2020import io .quarkus .gizmo .MethodCreator ;
2121import io .quarkus .gizmo .MethodDescriptor ;
2222import io .quarkus .gizmo .ResultHandle ;
23- import io .quarkus .gizmo .TryBlock ;
2423
2524/**
2625 * Generates the bytecode for the MemberAccessor of a particular Member
@@ -126,13 +125,9 @@ private static MemberAccessor createInstance(String className, GizmoClassLoader
126125 // MemberAccessor methods
127126 // ************************************************************************
128127
129- private static MethodCreator getMethodCreator (ClassCreator classCreator , String methodName , Class <?>... parameters ) {
130- try {
131- return classCreator .getMethodCreator (
132- MethodDescriptor .ofMethod (MemberAccessor .class .getMethod (methodName , parameters )));
133- } catch (NoSuchMethodException e ) {
134- throw new IllegalStateException ("No such method: " + methodName , e );
135- }
128+ private static MethodCreator getMethodCreator (ClassCreator classCreator , Class <?> returnType , String methodName ,
129+ Class <?>... parameters ) {
130+ return classCreator .getMethodCreator (methodName , returnType , parameters );
136131 }
137132
138133 private static void createConstructor (ClassCreator classCreator , GizmoMemberInfo memberInfo ) {
@@ -146,43 +141,35 @@ private static void createConstructor(ClassCreator classCreator, GizmoMemberInfo
146141
147142 ResultHandle declaringClass = methodCreator .loadClass (memberInfo .getDescriptor ().getDeclaringClassName ());
148143 memberInfo .getDescriptor ().whenMetadataIsOnField (fd -> {
149- TryBlock tryBlock = methodCreator .tryBlock ();
150- ResultHandle name = tryBlock .load (fd .getName ());
151- ResultHandle field = tryBlock .invokeVirtualMethod (MethodDescriptor .ofMethod (Class .class , "getDeclaredField" ,
144+ ResultHandle name = methodCreator .load (fd .getName ());
145+ ResultHandle field = methodCreator .invokeVirtualMethod (MethodDescriptor .ofMethod (Class .class , "getDeclaredField" ,
152146 Field .class , String .class ),
153147 declaringClass , name );
154148 ResultHandle type =
155- tryBlock .invokeVirtualMethod (MethodDescriptor .ofMethod (Field .class , "getGenericType" , Type .class ),
149+ methodCreator .invokeVirtualMethod (MethodDescriptor .ofMethod (Field .class , "getGenericType" , Type .class ),
156150 field );
157- tryBlock .writeInstanceField (FieldDescriptor .of (classCreator .getClassName (), GENERIC_TYPE_FIELD , Type .class ),
151+ methodCreator .writeInstanceField (FieldDescriptor .of (classCreator .getClassName (), GENERIC_TYPE_FIELD , Type .class ),
158152 thisObj , type );
159- tryBlock .writeInstanceField (
153+ methodCreator .writeInstanceField (
160154 FieldDescriptor .of (classCreator .getClassName (), ANNOTATED_ELEMENT_FIELD , AnnotatedElement .class ),
161155 thisObj , field );
162-
163- tryBlock .addCatch (NoSuchFieldException .class ).throwException (IllegalStateException .class , "Unable to find field (" +
164- fd .getName () + ") in class (" + fd .getDeclaringClass () + ")." );
165156 });
166157
167158 memberInfo .getDescriptor ().whenMetadataIsOnMethod (md -> {
168- TryBlock tryBlock = methodCreator .tryBlock ();
169- ResultHandle name = tryBlock .load (md .getName ());
170- ResultHandle method = tryBlock .invokeVirtualMethod (MethodDescriptor .ofMethod (Class .class , "getDeclaredMethod" ,
159+ ResultHandle name = methodCreator .load (md .getName ());
160+ ResultHandle method = methodCreator .invokeVirtualMethod (MethodDescriptor .ofMethod (Class .class , "getDeclaredMethod" ,
171161 Method .class , String .class , Class [].class ),
172162 declaringClass , name ,
173- tryBlock .newArray (Class .class , 0 ));
163+ methodCreator .newArray (Class .class , 0 ));
174164 ResultHandle type =
175- tryBlock .invokeVirtualMethod (MethodDescriptor .ofMethod (Method .class , "getGenericReturnType" , Type .class ),
165+ methodCreator .invokeVirtualMethod (
166+ MethodDescriptor .ofMethod (Method .class , "getGenericReturnType" , Type .class ),
176167 method );
177- tryBlock .writeInstanceField (FieldDescriptor .of (classCreator .getClassName (), GENERIC_TYPE_FIELD , Type .class ),
168+ methodCreator .writeInstanceField (FieldDescriptor .of (classCreator .getClassName (), GENERIC_TYPE_FIELD , Type .class ),
178169 thisObj , type );
179- tryBlock .writeInstanceField (
170+ methodCreator .writeInstanceField (
180171 FieldDescriptor .of (classCreator .getClassName (), ANNOTATED_ELEMENT_FIELD , AnnotatedElement .class ),
181172 thisObj , method );
182-
183- tryBlock .addCatch (NoSuchMethodException .class ).throwException (IllegalStateException .class ,
184- "Unable to find method (" +
185- md .getName () + ") in class (" + md .getDeclaringClass () + ")." );
186173 });
187174
188175 // Return this (it a constructor)
@@ -199,7 +186,7 @@ private static void createConstructor(ClassCreator classCreator, GizmoMemberInfo
199186 * </pre>
200187 */
201188 private static void createGetDeclaringClass (ClassCreator classCreator , GizmoMemberInfo memberInfo ) {
202- MethodCreator methodCreator = getMethodCreator (classCreator , "getDeclaringClass" );
189+ MethodCreator methodCreator = getMethodCreator (classCreator , Class . class , "getDeclaringClass" );
203190 ResultHandle out = methodCreator .loadClass (memberInfo .getDescriptor ().getDeclaringClassName ());
204191 methodCreator .returnValue (out );
205192 }
@@ -255,7 +242,7 @@ private static void assertIsGoodMethod(MethodDescriptor method, Class<? extends
255242 * letter become lowercase
256243 */
257244 private static void createGetName (ClassCreator classCreator , GizmoMemberInfo memberInfo ) {
258- MethodCreator methodCreator = getMethodCreator (classCreator , "getName" );
245+ MethodCreator methodCreator = getMethodCreator (classCreator , String . class , "getName" );
259246
260247 // If it is a method, assert that it has the required
261248 // properties
@@ -278,7 +265,7 @@ private static void createGetName(ClassCreator classCreator, GizmoMemberInfo mem
278265 * </pre>
279266 */
280267 private static void createGetType (ClassCreator classCreator , GizmoMemberInfo memberInfo ) {
281- MethodCreator methodCreator = getMethodCreator (classCreator , "getType" );
268+ MethodCreator methodCreator = getMethodCreator (classCreator , Class . class , "getType" );
282269 ResultHandle out = methodCreator .loadClass (memberInfo .getDescriptor ().getTypeName ());
283270 methodCreator .returnValue (out );
284271 }
@@ -297,7 +284,7 @@ private static void createGetType(ClassCreator classCreator, GizmoMemberInfo mem
297284 * is stored in gizmoMemberAccessorNameToGenericType when this method is called.
298285 */
299286 private static void createGetGenericType (ClassCreator classCreator ) {
300- MethodCreator methodCreator = getMethodCreator (classCreator , "getGenericType" );
287+ MethodCreator methodCreator = getMethodCreator (classCreator , Type . class , "getGenericType" );
301288 ResultHandle thisObj = methodCreator .getThis ();
302289
303290 ResultHandle out =
@@ -331,7 +318,7 @@ private static void createGetGenericType(ClassCreator classCreator) {
331318 * member if it is private (which get passed to the MemberDescriptor).
332319 */
333320 private static void createExecuteGetter (ClassCreator classCreator , GizmoMemberInfo memberInfo ) {
334- MethodCreator methodCreator = getMethodCreator (classCreator , "executeGetter" , Object .class );
321+ MethodCreator methodCreator = getMethodCreator (classCreator , Object . class , "executeGetter" , Object .class );
335322 ResultHandle bean = methodCreator .getMethodParam (0 );
336323 methodCreator .returnValue (memberInfo .getDescriptor ().readMemberValue (methodCreator , bean ));
337324 }
@@ -364,7 +351,7 @@ private static void createExecuteGetter(ClassCreator classCreator, GizmoMemberIn
364351 * </pre>
365352 */
366353 private static void createExecuteSetter (ClassCreator classCreator , GizmoMemberInfo memberInfo ) {
367- MethodCreator methodCreator = getMethodCreator (classCreator , "executeSetter" , Object .class ,
354+ MethodCreator methodCreator = getMethodCreator (classCreator , void . class , "executeSetter" , Object .class ,
368355 Object .class );
369356
370357 ResultHandle bean = methodCreator .getMethodParam (0 );
@@ -377,17 +364,13 @@ private static void createExecuteSetter(ClassCreator classCreator, GizmoMemberIn
377364 }
378365 }
379366
380- private static MethodCreator getAnnotationMethodCreator (ClassCreator classCreator , String methodName ,
367+ private static MethodCreator getAnnotationMethodCreator (ClassCreator classCreator , Class <?> returnType , String methodName ,
381368 Class <?>... parameters ) {
382- return classCreator .getMethodCreator (getAnnotationMethod (methodName , parameters ));
369+ return classCreator .getMethodCreator (getAnnotationMethod (returnType , methodName , parameters ));
383370 }
384371
385- private static MethodDescriptor getAnnotationMethod (String methodName , Class <?>... parameters ) {
386- try {
387- return MethodDescriptor .ofMethod (AnnotatedElement .class .getMethod (methodName , parameters ));
388- } catch (NoSuchMethodException e ) {
389- throw new IllegalStateException ("No such method: " + methodName , e );
390- }
372+ private static MethodDescriptor getAnnotationMethod (Class <?> returnType , String methodName , Class <?>... parameters ) {
373+ return MethodDescriptor .ofMethod (AnnotatedElement .class , methodName , returnType , parameters );
391374 }
392375
393376 /**
@@ -402,27 +385,30 @@ private static MethodDescriptor getAnnotationMethod(String methodName, Class<?>.
402385 * </pre>
403386 */
404387 private static void createGetAnnotation (ClassCreator classCreator ) {
405- MethodCreator methodCreator = getAnnotationMethodCreator (classCreator , "getAnnotation" , Class .class );
388+ MethodCreator methodCreator = getAnnotationMethodCreator (classCreator , Annotation . class , "getAnnotation" , Class .class );
406389 ResultHandle thisObj = methodCreator .getThis ();
407390
408391 ResultHandle annotatedElement = methodCreator .readInstanceField (
409392 FieldDescriptor .of (classCreator .getClassName (), ANNOTATED_ELEMENT_FIELD , AnnotatedElement .class ),
410393 thisObj );
411394 ResultHandle query = methodCreator .getMethodParam (0 );
412- ResultHandle out = methodCreator .invokeInterfaceMethod (getAnnotationMethod ("getAnnotation" , Class .class ),
413- annotatedElement , query );
395+ ResultHandle out =
396+ methodCreator .invokeInterfaceMethod (getAnnotationMethod (Annotation .class , "getAnnotation" , Class .class ),
397+ annotatedElement , query );
414398 methodCreator .returnValue (out );
415399 }
416400
417401 private static void createDeclaredAnnotationsByType (ClassCreator classCreator ) {
418- MethodCreator methodCreator = getAnnotationMethodCreator (classCreator , "getDeclaredAnnotationsByType" , Class .class );
402+ MethodCreator methodCreator =
403+ getAnnotationMethodCreator (classCreator , Annotation [].class , "getDeclaredAnnotationsByType" , Class .class );
419404 ResultHandle thisObj = methodCreator .getThis ();
420405
421406 ResultHandle annotatedElement = methodCreator .readInstanceField (
422407 FieldDescriptor .of (classCreator .getClassName (), ANNOTATED_ELEMENT_FIELD , AnnotatedElement .class ),
423408 thisObj );
424409 ResultHandle query = methodCreator .getMethodParam (0 );
425- ResultHandle out = methodCreator .invokeInterfaceMethod (getAnnotationMethod ("getDeclaredAnnotationsByType" , Class .class ),
410+ ResultHandle out = methodCreator .invokeInterfaceMethod (
411+ getAnnotationMethod (Annotation [].class , "getDeclaredAnnotationsByType" , Class .class ),
426412 annotatedElement , query );
427413 methodCreator .returnValue (out );
428414 }
0 commit comments