|
1 | 1 | /* |
2 | | - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2017 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -488,15 +488,13 @@ public static <A extends Annotation> A findAnnotation(AnnotatedElement annotated |
488 | 488 | private static <A extends Annotation> A findAnnotation( |
489 | 489 | AnnotatedElement annotatedElement, Class<A> annotationType, Set<Annotation> visited) { |
490 | 490 | try { |
491 | | - Annotation[] anns = annotatedElement.getDeclaredAnnotations(); |
492 | | - for (Annotation ann : anns) { |
493 | | - if (ann.annotationType() == annotationType) { |
494 | | - return (A) ann; |
495 | | - } |
| 491 | + A annotation = annotatedElement.getDeclaredAnnotation(annotationType); |
| 492 | + if (annotation != null) { |
| 493 | + return annotation; |
496 | 494 | } |
497 | | - for (Annotation ann : anns) { |
| 495 | + for (Annotation ann : annotatedElement.getDeclaredAnnotations()) { |
498 | 496 | if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) { |
499 | | - A annotation = findAnnotation((AnnotatedElement) ann.annotationType(), annotationType, visited); |
| 497 | + annotation = findAnnotation((AnnotatedElement) ann.annotationType(), annotationType, visited); |
500 | 498 | if (annotation != null) { |
501 | 499 | return annotation; |
502 | 500 | } |
@@ -677,15 +675,13 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> |
677 | 675 | @SuppressWarnings("unchecked") |
678 | 676 | private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, Set<Annotation> visited) { |
679 | 677 | try { |
680 | | - Annotation[] anns = clazz.getDeclaredAnnotations(); |
681 | | - for (Annotation ann : anns) { |
682 | | - if (ann.annotationType() == annotationType) { |
683 | | - return (A) ann; |
684 | | - } |
| 678 | + A annotation = clazz.getDeclaredAnnotation(annotationType); |
| 679 | + if (annotation != null) { |
| 680 | + return annotation; |
685 | 681 | } |
686 | | - for (Annotation ann : anns) { |
| 682 | + for (Annotation ann : clazz.getDeclaredAnnotations()) { |
687 | 683 | if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) { |
688 | | - A annotation = findAnnotation(ann.annotationType(), annotationType, visited); |
| 684 | + annotation = findAnnotation(ann.annotationType(), annotationType, visited); |
689 | 685 | if (annotation != null) { |
690 | 686 | return annotation; |
691 | 687 | } |
@@ -803,16 +799,12 @@ public static boolean isAnnotationDeclaredLocally(Class<? extends Annotation> an |
803 | 799 | Assert.notNull(annotationType, "Annotation type must not be null"); |
804 | 800 | Assert.notNull(clazz, "Class must not be null"); |
805 | 801 | try { |
806 | | - for (Annotation ann : clazz.getDeclaredAnnotations()) { |
807 | | - if (ann.annotationType() == annotationType) { |
808 | | - return true; |
809 | | - } |
810 | | - } |
| 802 | + return (clazz.getDeclaredAnnotation(annotationType) != null); |
811 | 803 | } |
812 | 804 | catch (Throwable ex) { |
813 | 805 | handleIntrospectionFailure(clazz, ex); |
| 806 | + return false; |
814 | 807 | } |
815 | | - return false; |
816 | 808 | } |
817 | 809 |
|
818 | 810 | /** |
|
0 commit comments