mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] check name before trying to resolve LHS of assignment
This commit is contained in:
+2
-1
@@ -130,9 +130,9 @@ public class GrAssignmentExpressionImpl extends GrOperatorExpressionImpl impleme
|
||||
@NotNull GroovyFileImpl file,
|
||||
@NotNull GrExpression lValue) {
|
||||
if (!(lValue instanceof GrReferenceExpression)) return true;
|
||||
|
||||
final GrReferenceExpression lReference = (GrReferenceExpression)lValue;
|
||||
if (lReference.isQualified()) return true;
|
||||
if (lReference != place && lReference.resolve() != null && !(lReference.resolve() instanceof GrBindingVariable)) return true;
|
||||
|
||||
final String name = lReference.getReferenceName();
|
||||
if (name == null) return true;
|
||||
@@ -140,6 +140,7 @@ public class GrAssignmentExpressionImpl extends GrOperatorExpressionImpl impleme
|
||||
String hintName = ResolveUtil.getNameHint(processor);
|
||||
if (hintName != null && !name.equals(hintName)) return true;
|
||||
|
||||
if (lReference != place && lReference.resolve() != null && !(lReference.resolve() instanceof GrBindingVariable)) return true;
|
||||
final ConcurrentMap<String, GrBindingVariable> bindings = file.getBindings();
|
||||
GrBindingVariable variable = bindings.get(name);
|
||||
if (variable == null) {
|
||||
|
||||
+14
@@ -33,8 +33,10 @@ import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection
|
||||
import org.jetbrains.plugins.groovy.dsl.GroovyDslFileIndex
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable
|
||||
import org.jetbrains.plugins.groovy.util.Slow
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
|
||||
@@ -548,4 +550,16 @@ def a = new Node()
|
||||
assert reference.resolve() != null
|
||||
}
|
||||
}
|
||||
|
||||
void "test do not resolve LHS and RHS of assignment when name doesn't match"() {
|
||||
def text = new StringBuilder("a0 = 1\n")
|
||||
def n = 1000
|
||||
for (i in 1..n) {
|
||||
text.append "a$i = a${i - 1}\n"
|
||||
}
|
||||
text.append "a$n"
|
||||
def file = (GroovyFile)fixture.configureByText('_.groovy', text.toString())
|
||||
def last = (GrReferenceExpression)file.statements.last()
|
||||
assert last.resolve() instanceof GrBindingVariable
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user