|
36 | 36 | import javax.lang.model.element.ExecutableElement;
|
37 | 37 | import javax.lang.model.element.TypeElement;
|
38 | 38 | import javax.lang.model.element.VariableElement;
|
| 39 | +import javax.lang.model.type.DeclaredType; |
39 | 40 | import javax.lang.model.type.TypeKind;
|
40 | 41 | import javax.lang.model.type.TypeMirror;
|
41 | 42 | import javax.lang.model.util.Elements;
|
@@ -184,15 +185,48 @@ ItemDeprecation resolveItemDeprecation(Element element) {
|
184 | 185 | }
|
185 | 186 |
|
186 | 187 | boolean hasConstructorBindingAnnotation(ExecutableElement element) {
|
187 |
| - return hasAnnotation(element, this.constructorBindingAnnotation); |
| 188 | + return hasAnnotation(element, this.constructorBindingAnnotation, true); |
188 | 189 | }
|
189 | 190 |
|
190 | 191 | boolean hasAutowiredAnnotation(ExecutableElement element) {
|
191 | 192 | return hasAnnotation(element, this.autowiredAnnotation);
|
192 | 193 | }
|
193 | 194 |
|
194 | 195 | boolean hasAnnotation(Element element, String type) {
|
195 |
| - return getAnnotation(element, type) != null; |
| 196 | + return hasAnnotation(element, type, false); |
| 197 | + } |
| 198 | + |
| 199 | + boolean hasAnnotation(Element element, String type, boolean considerMetaAnnotations) { |
| 200 | + if (element != null) { |
| 201 | + for (AnnotationMirror annotation : element.getAnnotationMirrors()) { |
| 202 | + if (type.equals(annotation.getAnnotationType().toString())) { |
| 203 | + return true; |
| 204 | + } |
| 205 | + } |
| 206 | + if (considerMetaAnnotations) { |
| 207 | + Set<Element> seen = new HashSet<>(); |
| 208 | + for (AnnotationMirror annotation : element.getAnnotationMirrors()) { |
| 209 | + if (hasMetaAnnotation(annotation.getAnnotationType().asElement(), type, seen)) { |
| 210 | + return true; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + } |
| 215 | + } |
| 216 | + return false; |
| 217 | + } |
| 218 | + |
| 219 | + private boolean hasMetaAnnotation(Element annotationElement, String type, Set<Element> seen) { |
| 220 | + if (seen.add(annotationElement)) { |
| 221 | + for (AnnotationMirror annotation : annotationElement.getAnnotationMirrors()) { |
| 222 | + DeclaredType annotationType = annotation.getAnnotationType(); |
| 223 | + if (type.equals(annotationType.toString()) |
| 224 | + || hasMetaAnnotation(annotationType.asElement(), type, seen)) { |
| 225 | + return true; |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | + return false; |
196 | 230 | }
|
197 | 231 |
|
198 | 232 | AnnotationMirror getAnnotation(Element element, String type) {
|
|
0 commit comments