IDEA-74663 String injections don't override it parameter

This commit is contained in:
Maxim Medvedev
2011-10-04 22:06:42 +04:00
parent d9d271a605
commit 86e64cf1bf
3 changed files with 18 additions and 3 deletions
@@ -35,6 +35,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
@@ -85,7 +86,7 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
PsiElement current = place;
boolean it_already_processed = false;
while (current != this && current != null) {
if (current instanceof GrClosableBlock && !((GrClosableBlock)current).hasParametersSection()) {
if (current instanceof GrClosableBlock && !((GrClosableBlock)current).hasParametersSection() && !(current.getParent() instanceof GrStringInjection)) {
it_already_processed = true;
break;
}
@@ -184,6 +185,10 @@ public class GrClosableBlockImpl extends GrBlockImpl implements GrClosableBlock
}
public GrParameter[] getSyntheticItParameter() {
if (getParent() instanceof GrStringInjection) {
return GrParameter.EMPTY_ARRAY;
}
GrParameter[] res = mySyntheticItParameter;
if (res == null) {
res = new GrParameter[]{new ClosureSyntheticParameter(this)};
@@ -809,4 +809,10 @@ def test() {
assertNotNull(ref.resolve())
}
void testStringInjectionDontOverrideItParameter() {
def ref = configureByText("""
[2, 3, 4].collect {"\${it.toBigDeci<caret>mal()}"}
""")
assertNotNull(ref.resolve())
}
}
@@ -229,11 +229,11 @@ public class TypeInferenceTest extends GroovyResolveTestCase {
public void testIncMethod() {
assertTypeEquals(JAVA_LANG_INTEGER, "A.groovy");
}
public void testDGMFind() {
assertTypeEquals("java.io.File", "a.groovy");
}
public void testMultiTypeParameter() {
assertTypeEquals("X | Y", "a.groovy");
}
@@ -241,4 +241,8 @@ public class TypeInferenceTest extends GroovyResolveTestCase {
public void testTypeArgsInAccessor() {
assertTypeEquals("Foo<java.lang.String>", "a.groovy");
}
public void testSingleParameterInStringInjection() {
assertTypeEquals("java.util.StringBuilder", "a.groovy");
}
}