@@ -162,7 +162,7 @@ public boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotatio
162162 @ SuppressWarnings ("unchecked" )
163163 @ Override
164164 public Class <? extends Annotation >[] getAnnotationTypes (AnnotatedElement element ) {
165- return Arrays .stream (getAnnotationData (element , false )).map (AnnotationValue ::getType ).filter (t -> t != null ).toArray (Class []::new );
165+ return Arrays .stream (getAnnotationData (element , false )).map (AnnotationValue ::getType ).filter (Objects :: nonNull ).toArray (Class []::new );
166166 }
167167
168168 public AnnotationValue [] getDeclaredAnnotationData (AnnotatedElement element ) {
@@ -175,8 +175,7 @@ private AnnotationValue[] getAnnotationData(AnnotatedElement element, boolean de
175175 cur = ((WrappedElement ) cur ).getWrapped ();
176176 }
177177 AnnotationValue [] result = NO_ANNOTATIONS ;
178- while (cur instanceof AnnotationWrapper ) {
179- AnnotationWrapper wrapper = (AnnotationWrapper ) cur ;
178+ while (cur instanceof AnnotationWrapper wrapper ) {
180179 result = concat (result , wrapper .getInjectedAnnotations ());
181180 cur = wrapper .getAnnotationRoot ();
182181 }
@@ -201,11 +200,10 @@ private static AnnotationValue[] concat(AnnotationValue[] a1, AnnotationValue[]
201200 }
202201
203202 private AnnotationValue [] getAnnotationDataFromRoot (AnnotatedElement rootElement ) {
204- if (!(rootElement instanceof Class <?>)) {
203+ if (!(rootElement instanceof Class <?> clazz )) {
205204 return getDeclaredAnnotationDataFromRoot (rootElement );
206205 }
207206
208- Class <?> clazz = (Class <?>) rootElement ;
209207 AnnotationValue [] existing = annotationCache .get (clazz );
210208 if (existing != null ) {
211209 return existing ;
@@ -355,10 +353,10 @@ private static byte[] getRawAnnotations(AnnotatedElement rootElement) {
355353 } else if (recordComponentClass != null && recordComponentClass .isInstance (rootElement )) {
356354 return (byte []) recordComponentAnnotations .get (rootElement );
357355 } else {
358- throw new AnnotationExtractionError ("Unexpected annotated element type: " + rootElement .getClass ());
356+ throw new AnnotationExtractionError (rootElement , "Unexpected annotated element type: " + rootElement .getClass ());
359357 }
360358 } catch (InvocationTargetException | IllegalAccessException e ) {
361- throw new AnnotationExtractionError (e );
359+ throw new AnnotationExtractionError (rootElement , e );
362360 }
363361 }
364362
@@ -369,10 +367,10 @@ private static byte[] getRawParameterAnnotations(Executable rootElement) {
369367 } else if (rootElement instanceof Constructor <?>) {
370368 return (byte []) constructorParameterAnnotations .get (rootElement );
371369 } else {
372- throw new AnnotationExtractionError ("Unexpected annotated element type: " + rootElement .getClass ());
370+ throw new AnnotationExtractionError (rootElement , "Unexpected annotated element type: " + rootElement .getClass ());
373371 }
374372 } catch (IllegalAccessException e ) {
375- throw new AnnotationExtractionError (e );
373+ throw new AnnotationExtractionError (rootElement , e );
376374 }
377375 }
378376
@@ -387,18 +385,18 @@ private static byte[] getRawTypeAnnotations(AnnotatedElement rootElement) {
387385 } else if (recordComponentClass != null && recordComponentClass .isInstance (rootElement )) {
388386 return (byte []) recordComponentTypeAnnotations .get (rootElement );
389387 } else {
390- throw new AnnotationExtractionError ("Unexpected annotated element type: " + rootElement .getClass ());
388+ throw new AnnotationExtractionError (rootElement , "Unexpected annotated element type: " + rootElement .getClass ());
391389 }
392390 } catch (InvocationTargetException | IllegalAccessException e ) {
393- throw new AnnotationExtractionError (e );
391+ throw new AnnotationExtractionError (rootElement , e );
394392 }
395393 }
396394
397395 private static byte [] getRawAnnotationDefault (Method method ) {
398396 try {
399397 return (byte []) methodAnnotationDefault .get (method );
400398 } catch (IllegalAccessException e ) {
401- throw new AnnotationExtractionError (e );
399+ throw new AnnotationExtractionError (method , e );
402400 }
403401 }
404402
@@ -407,7 +405,7 @@ private static ConstantPool getConstantPool(AnnotatedElement rootElement) {
407405 try {
408406 return (ConstantPool ) classGetConstantPool .invoke (container );
409407 } catch (InvocationTargetException | IllegalAccessException e ) {
410- throw new AnnotationExtractionError (e );
408+ throw new AnnotationExtractionError (rootElement , e );
411409 }
412410 }
413411
@@ -422,10 +420,10 @@ private static Class<?> getContainer(AnnotatedElement rootElement) {
422420 try {
423421 return (Class <?>) recordComponentGetDeclaringRecord .invoke (rootElement );
424422 } catch (IllegalAccessException | InvocationTargetException e ) {
425- throw new AnnotationExtractionError (e );
423+ throw new AnnotationExtractionError (rootElement , e );
426424 }
427425 } else {
428- throw new AnnotationExtractionError ("Unexpected annotated element type: " + rootElement .getClass ());
426+ throw new AnnotationExtractionError (rootElement , "Unexpected annotated element type: " + rootElement .getClass ());
429427 }
430428 }
431429
@@ -443,14 +441,14 @@ private static AnnotatedElement unwrap(AnnotatedElement element) {
443441 private static AnnotatedElement findRoot (AnnotatedElement element ) {
444442 assert !(element instanceof WrappedElement || element instanceof AnnotationWrapper );
445443 try {
446- if (element instanceof ResolvedJavaType ) {
447- return OriginalClassProvider .getJavaClass (( ResolvedJavaType ) element );
448- } else if (element instanceof ResolvedJavaMethod ) {
449- return OriginalMethodProvider .getJavaMethod (( ResolvedJavaMethod ) element );
450- } else if (element instanceof ResolvedJavaField ) {
451- return OriginalFieldProvider .getJavaField (( ResolvedJavaField ) element );
452- } else if (element instanceof Package ) {
453- return (Class <?>) packageGetPackageInfo .invoke (element );
444+ if (element instanceof ResolvedJavaType type ) {
445+ return OriginalClassProvider .getJavaClass (type );
446+ } else if (element instanceof ResolvedJavaMethod method ) {
447+ return OriginalMethodProvider .getJavaMethod (method );
448+ } else if (element instanceof ResolvedJavaField field ) {
449+ return OriginalFieldProvider .getJavaField (field );
450+ } else if (element instanceof Package packageObject ) {
451+ return (Class <?>) packageGetPackageInfo .invoke (packageObject );
454452 } else {
455453 return element ;
456454 }
@@ -459,9 +457,9 @@ private static AnnotatedElement findRoot(AnnotatedElement element) {
459457 if (targetException instanceof LinkageError ) {
460458 throw (LinkageError ) targetException ;
461459 }
462- throw new AnnotationExtractionError (e );
460+ throw new AnnotationExtractionError (element , e );
463461 } catch (IllegalAccessException e ) {
464- throw new AnnotationExtractionError (e );
462+ throw new AnnotationExtractionError (element , e );
465463 }
466464 }
467465}
0 commit comments