IDEA-92963 Groovy: Good code is red (Invalid value to assign to)

This commit is contained in:
Max Medvedev
2012-10-16 18:01:09 +04:00
parent 3ec3f15f92
commit c13e9f5e3c
2 changed files with 19 additions and 2 deletions
@@ -69,6 +69,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClaus
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrPropertySelection;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
@@ -653,8 +654,12 @@ public class PsiUtil {
public static boolean mightBeLValue(@Nullable GrExpression expr) {
if (expr instanceof GrParenthesizedExpression) return mightBeLValue(((GrParenthesizedExpression)expr).getOperand());
if (expr instanceof GrTupleExpression) return true;
if (expr instanceof GrReferenceExpression || expr instanceof GrIndexProperty) return true;
if (expr instanceof GrTupleExpression ||
expr instanceof GrReferenceExpression ||
expr instanceof GrIndexProperty ||
expr instanceof GrPropertySelection) {
return true;
}
if ((expr instanceof GrThisReferenceExpression || expr instanceof GrSuperReferenceExpression) &&
GroovyConfigUtils.getInstance().isVersionAtLeast(expr, GroovyConfigUtils.GROOVY1_8)) {
@@ -884,6 +884,18 @@ class X {
}
}
}
''')
}
void testPropertySelectionMayBeLValue() {
testHighlighting('''\
def methodMissing(String methodName, args) {
def closure = {
callSomeOtherMethodInstead()
}
this.metaClass."$methodName" = closure
<error descr="Invalid value to assign to">closure()</error> = 2
}
''')
}
}