IDEA-87589 Groovy: unresolved references in static methods

This commit is contained in:
Maxim.Medvedev
2012-06-20 20:38:21 +04:00
parent ecc636158e
commit 0e0cc17834
2 changed files with 30 additions and 14 deletions
@@ -366,9 +366,9 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
Annotation annotation;
boolean compileStatic = isCompileStatic(referenceExpression);
boolean compileStatic = isCompileStatic(referenceExpression) || isInStaticMethod(referenceExpression);
if (compileStatic) {
annotation = myHolder.createInfoAnnotation(elt, GroovyBundle.message("cannot.resolve", referenceExpression.getReferenceName()));
annotation = myHolder.createErrorAnnotation(elt, GroovyBundle.message("cannot.resolve", referenceExpression.getReferenceName()));
annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
else {
@@ -394,6 +394,11 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
}
}
private static boolean isInStaticMethod(GrReferenceExpression referenceExpression) {
PsiMember context = PsiTreeUtil.getParentOfType(referenceExpression, PsiMember.class, true, GrClosableBlock.class);
return context instanceof PsiMethod && context.hasModifierProperty(PsiModifier.STATIC);
}
private static boolean isCompileStatic(PsiElement e) {
PsiMember containingMember = PsiTreeUtil.getParentOfType(e, PsiMember.class);
return containingMember != null && GroovyPsiManager.getInstance(containingMember.getProject()).isCompileStatic(containingMember);
@@ -407,11 +412,10 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
Annotation annotation = myHolder.createInfoAnnotation(toHighlight, null);
boolean reassigned = isReassigned(variable);
if (variable instanceof GrParameter) {
annotation
.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER);
} else {
annotation
.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE);
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER);
}
else {
annotation.setTextAttributes(reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE);
}
}
@@ -671,7 +675,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
GrOpenBlock block = method.getBlock();
if (block != null && TypeInferenceHelper.isTooComplexTooAnalyze(block)) {
myHolder.createWeakWarningAnnotation(method.getNameIdentifierGroovy(), GroovyBundle.message("method.0.is.too.complex.too.analyze",
method.getName()));
method.getName()));
}
}
@@ -901,7 +905,7 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
@Override
public void visitWildcardTypeArgument(GrWildcardTypeArgument wildcardTypeArgument) {
super.visitWildcardTypeArgument(wildcardTypeArgument);
checkTypeArgForPrimitive(wildcardTypeArgument.getBoundTypeElement(), GroovyBundle.message("primitive.bound.types.are.not.allowed"));
}
@@ -594,7 +594,7 @@ class A {
def foo() {
new Runnable() {
<error descr="Inner classes cannot have static declarations">static</error> void run() {
print this.@abc
print abc
}
}.run()
}
@@ -1021,19 +1021,19 @@ public @interface CompileStatic {
myFixture.configureByText('_.groovy', '''\
<info descr="null">import</info> <info descr="null">groovy.transform.CompileStatic</info>
<info descr="null">class</info> <info descr="null">A</info> {
<info descr="null">class</info> A {
<info descr="null">def</info> <info descr="null">foo</info>() {
<info descr="null">print</info> <info descr="null">abc</info>
}
<info descr="null">@CompileStatic</info>
<info descr="null">def</info> <info descr="null">bar</info>() {
<info descr="null">print</info> <info descr="Cannot resolve symbol 'abc'">abc</info>
<info descr="null">def</info> bar() {
<info descr="null">print</info> <error descr="Cannot resolve symbol 'abc'">abc</error>
}
}
''')
myFixture.testHighlighting(true, true, true)
myFixture.testHighlighting(true, true, false)
}
@@ -1091,4 +1091,16 @@ def a(xxx) {
}
''', UnusedDefInspection)
}
void testUnresolvedVarInStaticMethod() {
testHighlighting('''\
static def foo() {
print <error descr="Cannot resolve symbol 'abc'">abc</error>
def cl = {
print cde
}
}
''')
}
}