mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
NPE while highlighting enum constant in annotation attribute
This commit is contained in:
@@ -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;
|
||||
|
||||
+29
@@ -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 = <error descr="Expected 'A.CONST' to be an inline constant">A.CONST</error>)
|
||||
def bar
|
||||
''')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user