From 175486973c15e2f4c2fcf043883e61c7361ba1b3 Mon Sep 17 00:00:00 2001 From: Ilya Klyuchnikov Date: Fri, 27 Jun 2014 22:26:20 +0400 Subject: [PATCH] findInferredAnnotations returns @NotNull array --- .../bytecodeAnalysis/ProjectBytecodeAnalysis.java | 12 ++++++------ .../ExternalAnnotationsLineMarkerProvider.java | 5 ++--- .../src/com/intellij/codeInsight/AnnotationUtil.java | 4 +--- .../codeInsight/InferredAnnotationsManager.java | 2 +- .../codeInsight/javadoc/JavaDocInfoGenerator.java | 4 +--- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/ProjectBytecodeAnalysis.java b/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/ProjectBytecodeAnalysis.java index 401277ff727f..086781adfbbd 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/ProjectBytecodeAnalysis.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/ProjectBytecodeAnalysis.java @@ -46,7 +46,7 @@ import java.util.Collection; * @author lambdamix */ public class ProjectBytecodeAnalysis extends AbstractProjectComponent { - + private static final PsiAnnotation[] NO_DATA = new PsiAnnotation[0]; private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.bytecodeAnalysis.ProjectBytecodeAnalysis"); private static final CharTableImpl charTable = new CharTableImpl(); private static final JavaParserUtil.ParserWrapper ANNOTATION = new JavaParserUtil.ParserWrapper() { @@ -149,13 +149,13 @@ public class ProjectBytecodeAnalysis extends AbstractProjectComponent { } } - @Nullable + @NotNull public PsiAnnotation[] findInferredAnnotations(@NotNull PsiModifierListOwner listOwner) { return collectInferredAnnotations(listOwner); } // TODO the best way to synchronize? - @Nullable + @NotNull private synchronized PsiAnnotation[] collectInferredAnnotations(PsiModifierListOwner listOwner) { if (myAnnotations == null) { loadAnnotations(); @@ -163,7 +163,7 @@ public class ProjectBytecodeAnalysis extends AbstractProjectComponent { try { int key = getKey(listOwner); if (key == -1) { - return null; + return NO_DATA; } boolean notNull = myAnnotations.notNulls.contains(key); String contractValue = myAnnotations.contracts.get(key); @@ -185,12 +185,12 @@ public class ProjectBytecodeAnalysis extends AbstractProjectComponent { }; } else { - return null; + return NO_DATA; } } catch (IOException e) { LOG.error(e); - return null; + return NO_DATA; } } diff --git a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java index 9ef1cb394c18..c59f52c4932c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExternalAnnotationsLineMarkerProvider.java @@ -58,8 +58,7 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider final InferredAnnotationsManager inferredAnnotationsManager = InferredAnnotationsManager.getInstance(modifierListOwner.getProject()); PsiAnnotation[] inferredAnnotations = inferredAnnotationsManager.findInferredAnnotations(modifierListOwner); - if (externalAnnotations != null && externalAnnotations.length > 0 || - inferredAnnotations != null && inferredAnnotations.length > 0) { + if (externalAnnotations != null && externalAnnotations.length > 0 || inferredAnnotations.length > 0) { owner = (PsiModifierListOwner)element; } else if (element instanceof PsiMethod) { final PsiParameter[] parameters = ((PsiMethod)element).getParameterList().getParameters(); @@ -70,7 +69,7 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider break; } inferredAnnotations = inferredAnnotationsManager.findInferredAnnotations(parameter); - if (inferredAnnotations != null && inferredAnnotations.length > 0) { + if (inferredAnnotations.length > 0) { owner = (PsiMethod)element; break; } 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 7ead36d50fa7..3b908a77d5e7 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/AnnotationUtil.java @@ -390,9 +390,7 @@ public class AnnotationUtil { annotations = ArrayUtil.mergeArrays(annotations, externalAnnotations, PsiAnnotation.ARRAY_FACTORY); } final PsiAnnotation[] inferredAnnotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner); - if (inferredAnnotations != null) { - annotations = ArrayUtil.mergeArrays(annotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY); - } + annotations = ArrayUtil.mergeArrays(annotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY); if (inHierarchy) { if (owner instanceof PsiClass) { diff --git a/java/java-psi-api/src/com/intellij/codeInsight/InferredAnnotationsManager.java b/java/java-psi-api/src/com/intellij/codeInsight/InferredAnnotationsManager.java index a7aebe95a9fa..a53caa219478 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/InferredAnnotationsManager.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/InferredAnnotationsManager.java @@ -33,6 +33,6 @@ public abstract class InferredAnnotationsManager { @Nullable public abstract PsiAnnotation findInferredAnnotation(@NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQN); - @Nullable + @NotNull public abstract PsiAnnotation[] findInferredAnnotations(@NotNull PsiModifierListOwner listOwner); } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index dedd7a99807d..dddb5a7fe976 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -705,9 +705,7 @@ public class JavaDocInfoGenerator { externalAnnotations = new PsiAnnotation[]{}; } PsiAnnotation[] inferredAnnotations = InferredAnnotationsManager.getInstance(owner.getProject()).findInferredAnnotations(owner); - if (inferredAnnotations != null) { - externalAnnotations = ArrayUtil.mergeArrays(externalAnnotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY); - } + externalAnnotations = ArrayUtil.mergeArrays(externalAnnotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY); generateAnnotations(buffer, owner, externalAnnotations, true, generateLink); }