diff options
Diffstat (limited to 'java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java')
-rw-r--r-- | java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java index c0cd96c20d47..c2c79a9d9d8a 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java @@ -113,13 +113,21 @@ public class AnnotationUtil { } } if (!skipExternal) { - final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(listOwner.getProject()); + final Project project = listOwner.getProject(); + final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project); for (String annotationName : annotationNames) { final PsiAnnotation annotation = annotationsManager.findExternalAnnotation(listOwner, annotationName); if (annotation != null) { return annotation; } } + final InferredAnnotationsManager inferredAnnotationsManager = InferredAnnotationsManager.getInstance(project); + for (String annotationName : annotationNames) { + final PsiAnnotation annotation = inferredAnnotationsManager.findInferredAnnotation(listOwner, annotationName); + if (annotation != null) { + return annotation; + } + } } return null; } @@ -269,8 +277,12 @@ public class AnnotationUtil { if (modifierList == null) return false; PsiAnnotation annotation = modifierList.findAnnotation(annotationFQN); if (annotation != null) return true; - if (!skipExternal && ExternalAnnotationsManager.getInstance(listOwner.getProject()).findExternalAnnotation(listOwner, annotationFQN) != null) { - return true; + if (!skipExternal) { + final Project project = listOwner.getProject(); + if (ExternalAnnotationsManager.getInstance(project).findExternalAnnotation(listOwner, annotationFQN) != null || + InferredAnnotationsManager.getInstance(project).findInferredAnnotation(listOwner, annotationFQN) != null) { + return true; + } } if (checkHierarchy) { if (listOwner instanceof PsiMethod) { @@ -365,17 +377,31 @@ public class AnnotationUtil { } @NotNull - public static PsiAnnotation[] getAllAnnotations(@NotNull PsiModifierListOwner owner, boolean inHierarchy, Set<PsiModifierListOwner> visited) { + public static PsiAnnotation[] getAllAnnotations(@NotNull PsiModifierListOwner owner, + boolean inHierarchy, + Set<PsiModifierListOwner> visited) { + return getAllAnnotations(owner, inHierarchy, visited, true); + } + + @NotNull + public static PsiAnnotation[] getAllAnnotations(@NotNull PsiModifierListOwner owner, + boolean inHierarchy, + Set<PsiModifierListOwner> visited, boolean withInferred) { final PsiModifierList list = owner.getModifierList(); PsiAnnotation[] annotations = PsiAnnotation.EMPTY_ARRAY; if (list != null) { annotations = list.getAnnotations(); } - final PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotations(owner); + final Project project = owner.getProject(); + final PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(owner); if (externalAnnotations != null) { annotations = ArrayUtil.mergeArrays(annotations, externalAnnotations, PsiAnnotation.ARRAY_FACTORY); } + if (withInferred) { + final PsiAnnotation[] inferredAnnotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner); + annotations = ArrayUtil.mergeArrays(annotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY); + } if (inHierarchy) { if (owner instanceof PsiClass) { @@ -435,6 +461,10 @@ public class AnnotationUtil { return PsiTreeUtil.getParentOfType(element, PsiNameValuePair.class, PsiArrayInitializerMemberValue.class) != null; } + public static boolean isInferredAnnotation(@NotNull PsiAnnotation annotation) { + return InferredAnnotationsManager.getInstance(annotation.getProject()).isInferredAnnotation(annotation); + } + @Nullable public static String getStringAttributeValue(@NotNull PsiAnnotation anno, @Nullable final String attributeName) { PsiAnnotationMemberValue attrValue = anno.findAttributeValue(attributeName); |