diff --git a/platform/lang-api/src/com/intellij/lang/annotation/AnnotationHolder.java b/platform/lang-api/src/com/intellij/lang/annotation/AnnotationHolder.java index 424851003529..f070885a4f0e 100644 --- a/platform/lang-api/src/com/intellij/lang/annotation/AnnotationHolder.java +++ b/platform/lang-api/src/com/intellij/lang/annotation/AnnotationHolder.java @@ -45,7 +45,7 @@ public interface AnnotationHolder { * @param message the error message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createErrorAnnotation(ASTNode node, @Nullable String message); + Annotation createErrorAnnotation(@NotNull ASTNode node, @Nullable String message); /** * Creates an error annotation with the specified message over the specified text range. @@ -54,7 +54,7 @@ public interface AnnotationHolder { * @param message the error message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createErrorAnnotation(TextRange range, @Nullable String message); + Annotation createErrorAnnotation(@NotNull TextRange range, @Nullable String message); /** * Creates a warning annotation with the specified message over the specified PSI element. @@ -63,7 +63,7 @@ public interface AnnotationHolder { * @param message the warning message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createWarningAnnotation(PsiElement elt, @Nullable String message); + Annotation createWarningAnnotation(@NotNull PsiElement elt, @Nullable String message); /** * Creates a warning annotation with the specified message over the specified AST node. @@ -72,7 +72,7 @@ public interface AnnotationHolder { * @param message the warning message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createWarningAnnotation(ASTNode node, @Nullable String message); + Annotation createWarningAnnotation(@NotNull ASTNode node, @Nullable String message); /** * Creates a warning annotation with the specified message over the specified text range. @@ -81,7 +81,7 @@ public interface AnnotationHolder { * @param message the warning message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createWarningAnnotation(TextRange range, @Nullable String message); + Annotation createWarningAnnotation(@NotNull TextRange range, @Nullable String message); /** * Creates an annotation with severity {@link HighlightSeverity#INFO} ('weak warning') with the specified @@ -91,7 +91,7 @@ public interface AnnotationHolder { * @param message the info message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createInformationAnnotation(PsiElement elt, @Nullable String message); + Annotation createInformationAnnotation(@NotNull PsiElement elt, @Nullable String message); /** * Creates an annotation with severity {@link HighlightSeverity#INFO} ('weak warning') with the specified @@ -101,7 +101,7 @@ public interface AnnotationHolder { * @param message the info message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createInformationAnnotation(ASTNode node, @Nullable String message); + Annotation createInformationAnnotation(@NotNull ASTNode node, @Nullable String message); /** * Creates an annotation with severity {@link HighlightSeverity#INFO} ('weak warning') with the specified @@ -111,7 +111,7 @@ public interface AnnotationHolder { * @param message the info message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createInformationAnnotation(TextRange range, String message); + Annotation createInformationAnnotation(@NotNull TextRange range, String message); /** @@ -122,7 +122,7 @@ public interface AnnotationHolder { * @param message the information message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createInfoAnnotation(PsiElement elt, @Nullable String message); + Annotation createInfoAnnotation(@NotNull PsiElement elt, @Nullable String message); /** * Creates an information annotation (colored highlighting only, with no gutter mark and not participating in @@ -132,7 +132,7 @@ public interface AnnotationHolder { * @param message the information message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createInfoAnnotation(ASTNode node, @Nullable String message); + Annotation createInfoAnnotation(@NotNull ASTNode node, @Nullable String message); /** * Creates an information annotation (colored highlighting only, with no gutter mark and not participating in @@ -142,6 +142,6 @@ public interface AnnotationHolder { * @param message the information message. * @return the annotation (which can be modified to set additional annotation parameters) */ - Annotation createInfoAnnotation(TextRange range, String message); + Annotation createInfoAnnotation(@NotNull TextRange range, String message); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java index b075eae216d5..ca9470e48af2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/AnnotationHolderImpl.java @@ -34,47 +34,47 @@ public class AnnotationHolderImpl extends SmartList implements Annot return createAnnotation(elt.getTextRange(), HighlightSeverity.ERROR, message); } - public Annotation createErrorAnnotation(ASTNode node, String message) { + public Annotation createErrorAnnotation(@NotNull ASTNode node, String message) { return createAnnotation(node.getTextRange(), HighlightSeverity.ERROR, message); } - public Annotation createErrorAnnotation(TextRange range, String message) { + public Annotation createErrorAnnotation(@NotNull TextRange range, String message) { return createAnnotation(range, HighlightSeverity.ERROR, message); } - public Annotation createWarningAnnotation(PsiElement elt, String message) { + public Annotation createWarningAnnotation(@NotNull PsiElement elt, String message) { return createAnnotation(elt.getTextRange(), HighlightSeverity.WARNING, message); } - public Annotation createWarningAnnotation(ASTNode node, String message) { + public Annotation createWarningAnnotation(@NotNull ASTNode node, String message) { return createAnnotation(node.getTextRange(), HighlightSeverity.WARNING, message); } - public Annotation createWarningAnnotation(TextRange range, String message) { + public Annotation createWarningAnnotation(@NotNull TextRange range, String message) { return createAnnotation(range, HighlightSeverity.WARNING, message); } - public Annotation createInformationAnnotation(PsiElement elt, String message) { + public Annotation createInformationAnnotation(@NotNull PsiElement elt, String message) { return createAnnotation(elt.getTextRange(), HighlightSeverity.INFO, message); } - public Annotation createInformationAnnotation(ASTNode node, String message) { + public Annotation createInformationAnnotation(@NotNull ASTNode node, String message) { return createAnnotation(node.getTextRange(), HighlightSeverity.INFO, message); } - public Annotation createInformationAnnotation(TextRange range, String message) { + public Annotation createInformationAnnotation(@NotNull TextRange range, String message) { return createAnnotation(range, HighlightSeverity.INFO, message); } - public Annotation createInfoAnnotation(PsiElement elt, String message) { + public Annotation createInfoAnnotation(@NotNull PsiElement elt, String message) { return createAnnotation(elt.getTextRange(), HighlightSeverity.INFORMATION, message); } - public Annotation createInfoAnnotation(ASTNode node, String message) { + public Annotation createInfoAnnotation(@NotNull ASTNode node, String message) { return createAnnotation(node.getTextRange(), HighlightSeverity.INFORMATION, message); } - public Annotation createInfoAnnotation(TextRange range, String message) { + public Annotation createInfoAnnotation(@NotNull TextRange range, String message) { return createAnnotation(range, HighlightSeverity.INFORMATION, message); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/AnnotatorBasedInspection.java b/platform/lang-impl/src/com/intellij/codeInspection/AnnotatorBasedInspection.java index 23b1d4d631a9..fd51dfb8adf2 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/AnnotatorBasedInspection.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/AnnotatorBasedInspection.java @@ -20,7 +20,6 @@ import com.intellij.analysis.AnalysisScope; import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl; import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.codeInspection.ex.DescriptorProviderInspection; import com.intellij.codeInspection.ex.JobDescriptor; import com.intellij.lang.ASTNode; import com.intellij.lang.LanguageAnnotators; @@ -106,17 +105,17 @@ public class AnnotatorBasedInspection extends GlobalInspectionTool { } @Override - public Annotation createWarningAnnotation(PsiElement elt, String message) { + public Annotation createWarningAnnotation(@NotNull PsiElement elt, String message) { return createProblem(elt, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, HighlightSeverity.WARNING, null); } @Override - public Annotation createInfoAnnotation(PsiElement elt, String message) { + public Annotation createInfoAnnotation(@NotNull PsiElement elt, String message) { return super.createInfoAnnotation(elt, message); } @Override - public Annotation createInformationAnnotation(PsiElement elt, String message) { + public Annotation createInformationAnnotation(@NotNull PsiElement elt, String message) { return createProblem(elt, message, ProblemHighlightType.INFORMATION, HighlightSeverity.INFORMATION, null); } @@ -131,22 +130,22 @@ public class AnnotatorBasedInspection extends GlobalInspectionTool { } @Override - public Annotation createErrorAnnotation(ASTNode node, String message) { + public Annotation createErrorAnnotation(@NotNull ASTNode node, String message) { return createErrorAnnotation(node.getPsi(), message); } @Override - public Annotation createWarningAnnotation(ASTNode node, String message) { + public Annotation createWarningAnnotation(@NotNull ASTNode node, String message) { return createWarningAnnotation(node.getPsi(), message); } @Override - public Annotation createInformationAnnotation(ASTNode node, String message) { + public Annotation createInformationAnnotation(@NotNull ASTNode node, String message) { return createInformationAnnotation(node.getPsi(), message); } @Override - public Annotation createInfoAnnotation(ASTNode node, String message) { + public Annotation createInfoAnnotation(@NotNull ASTNode node, String message) { return createInfoAnnotation(node.getPsi(), message); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 932d19ccec79..e9429f30b52e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -172,7 +172,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { } if (!resolveResult.isAccessible()) { String message = GroovyBundle.message("cannot.access", referenceExpression.getReferenceName()); - final Annotation annotation = myHolder.createWarningAnnotation(referenceExpression.getReferenceNameElement(), message); + final Annotation annotation = myHolder.createWarningAnnotation(getElementToHighlight(referenceExpression), message); if (resolved instanceof PsiMember) { registerAccessFix(annotation, referenceExpression, ((PsiMember)resolved)); } @@ -510,7 +510,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { else { final GroovyResolveResult[] results = newExpression.multiResolveConstructor(); final GrArgumentList argList = newExpression.getArgumentList(); - PsiElement toHighlight = argList != null ? argList : refElement.getReferenceNameElement(); + PsiElement toHighlight = argList != null ? argList : getElementToHighlight(refElement); if (results.length > 0) { String message = GroovyBundle.message("ambiguous.constructor.call"); @@ -1285,7 +1285,9 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { private static void highlightMemberResolved(AnnotationHolder holder, GrReferenceExpression refExpr, PsiMember member) { boolean isStatic = member.hasModifierProperty(GrModifier.STATIC); - Annotation annotation = holder.createInfoAnnotation(refExpr.getReferenceNameElement(), null); + final PsiElement refNameElement = refExpr.getReferenceNameElement(); + if (refNameElement == null) return; + Annotation annotation = holder.createInfoAnnotation(refNameElement, null); if (member instanceof PsiField || member instanceof GrAccessorMethod) { annotation.setTextAttributes(isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD); @@ -1411,12 +1413,11 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { private static void checkSingleResolvedElement(AnnotationHolder holder, GrReferenceElement refElement, GroovyResolveResult resolveResult, boolean highlightError) { final PsiElement resolved = resolveResult.getElement(); + final PsiElement toHighlight = getElementToHighlight(refElement); if (resolved == null) { String message = GroovyBundle.message("cannot.resolve", refElement.getReferenceName()); // Register quickfix - final PsiElement nameElement = refElement.getReferenceNameElement(); - final PsiElement toHighlight = nameElement != null ? nameElement : refElement; final Annotation annotation; if (highlightError) { @@ -1434,10 +1435,16 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { } else if (!resolveResult.isAccessible()) { String message = GroovyBundle.message("cannot.access", refElement.getReferenceName()); - holder.createWarningAnnotation(refElement.getReferenceNameElement(), message); + holder.createWarningAnnotation(toHighlight, message); } } + @NotNull + private static PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) { + final PsiElement refNameElement = refElement.getReferenceNameElement(); + return refNameElement != null ? refNameElement : refElement; + } + private static void checkDefaultMapConstructor(AnnotationHolder holder, GrArgumentList argList, PsiElement element) { if (argList != null) { final GrNamedArgument[] args = argList.getNamedArguments();