39
39
* {@link AnnotatedElement}.
40
40
*
41
41
* @author Phillip Webb
42
+ * @author Sam Brannen
42
43
* @since 5.2
43
44
* @see AnnotationsProcessor
44
45
*/
@@ -121,7 +122,7 @@ private static <C, R> R processClass(C context, Class<?> source,
121
122
case DIRECT :
122
123
return processElement (context , source , processor , classFilter );
123
124
case INHERITED_ANNOTATIONS :
124
- return processClassInheritedAnnotations (context , source , processor , classFilter );
125
+ return processClassInheritedAnnotations (context , source , searchStrategy , processor , classFilter );
125
126
case SUPERCLASS :
126
127
return processClassHierarchy (context , source , processor , classFilter , false , false );
127
128
case EXHAUSTIVE :
@@ -135,9 +136,9 @@ private static <C, R> R processClass(C context, Class<?> source,
135
136
136
137
@ Nullable
137
138
private static <C , R > R processClassInheritedAnnotations (C context , Class <?> source ,
138
- AnnotationsProcessor <C , R > processor , @ Nullable BiPredicate <C , Class <?>> classFilter ) {
139
+ SearchStrategy searchStrategy , AnnotationsProcessor <C , R > processor , @ Nullable BiPredicate <C , Class <?>> classFilter ) {
139
140
140
- if (isWithoutHierarchy (source )) {
141
+ if (isWithoutHierarchy (source , searchStrategy )) {
141
142
return processElement (context , source , processor , classFilter );
142
143
}
143
144
Annotation [] relevant = null ;
@@ -505,7 +506,7 @@ static boolean isKnownEmpty(AnnotatedElement source, SearchStrategy searchStrate
505
506
if (hasPlainJavaAnnotationsOnly (source )) {
506
507
return true ;
507
508
}
508
- if (searchStrategy == SearchStrategy .DIRECT || isWithoutHierarchy (source )) {
509
+ if (searchStrategy == SearchStrategy .DIRECT || isWithoutHierarchy (source , searchStrategy )) {
509
510
if (source instanceof Method && ((Method ) source ).isBridge ()) {
510
511
return false ;
511
512
}
@@ -530,19 +531,21 @@ static boolean hasPlainJavaAnnotationsOnly(Class<?> type) {
530
531
return (type .getName ().startsWith ("java." ) || type == Ordered .class );
531
532
}
532
533
533
- private static boolean isWithoutHierarchy (AnnotatedElement source ) {
534
+ private static boolean isWithoutHierarchy (AnnotatedElement source , SearchStrategy searchStrategy ) {
534
535
if (source == Object .class ) {
535
536
return true ;
536
537
}
537
538
if (source instanceof Class ) {
538
539
Class <?> sourceClass = (Class <?>) source ;
539
- return (sourceClass .getSuperclass () == Object .class &&
540
+ boolean noSuperTypes = (sourceClass .getSuperclass () == Object .class &&
540
541
sourceClass .getInterfaces ().length == 0 );
542
+ return (searchStrategy == SearchStrategy .TYPE_HIERARCHY_AND_ENCLOSING_CLASSES ? noSuperTypes &&
543
+ sourceClass .getEnclosingClass () == null : noSuperTypes );
541
544
}
542
545
if (source instanceof Method ) {
543
546
Method sourceMethod = (Method ) source ;
544
547
return (Modifier .isPrivate (sourceMethod .getModifiers ()) ||
545
- isWithoutHierarchy (sourceMethod .getDeclaringClass ()));
548
+ isWithoutHierarchy (sourceMethod .getDeclaringClass (), searchStrategy ));
546
549
}
547
550
return true ;
548
551
}
0 commit comments