From b05d470c586a586d19a27de6828568d1a0c99da5 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Thu, 2 May 2013 19:21:22 +0400 Subject: [PATCH] NPE while highlighting enum constant in annotation attribute --- .../groovy/annotator/GroovyAnnotator.java | 13 +++++++-- .../GroovyHighlightingTest.groovy | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) 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 4f71412c9309..f3369636be49 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -1374,14 +1374,21 @@ public class GroovyAnnotator extends GroovyElementVisitor { if (value instanceof GrReferenceExpression) { PsiElement resolved = ((GrReferenceExpression)value).resolve(); if (resolved instanceof PsiClass) return false; + if (resolved instanceof PsiEnumConstant) return false; if (resolved instanceof GrAccessorMethod) resolved = ((GrAccessorMethod)resolved).getProperty(); if (resolved instanceof PsiField) { GrExpression initializer; try { - initializer = resolved instanceof GrField - ? ((GrField)resolved).getInitializerGroovy() - : (GrExpression)ExpressionConverter.getExpression(((PsiField)resolved).getInitializer(), GroovyFileType.GROOVY_LANGUAGE, value.getProject()); + if (resolved instanceof GrField) { + initializer = ((GrField)resolved).getInitializerGroovy(); + } + else { + final PsiExpression _initializer = ((PsiField)resolved).getInitializer(); + initializer = _initializer != null + ? (GrExpression)ExpressionConverter.getExpression(_initializer, GroovyFileType.GROOVY_LANGUAGE, value.getProject()) + : null; + } } catch (IncorrectOperationException e) { initializer = null; diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy index 70a3b260972d..8a387301f2b4 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy @@ -1333,4 +1333,33 @@ class B extends A { ''') } + void testEnumConstantAsAnnotationAttribute() { + testHighlighting('''\ +enum A {CONST} + +@interface I { + A foo() +} + +@I(foo = A.CONST) //no error +def bar +''') + } + + void testUnassignedFieldAsAnnotationAttribute() { + testHighlighting('''\ +interface A { + String CONST +} + +@interface I { + String foo() +} + +@I(foo = A.CONST) +def bar +''') + } + + } \ No newline at end of file