mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Type inference for string injection parameter
This commit is contained in:
@@ -13,6 +13,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpres
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.arithmetic.GrRangeExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrRangeType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
@@ -85,6 +86,10 @@ public class ClosureParameterEnhancer extends AbstractClosureParameterEnhancer {
|
||||
@Nullable
|
||||
protected PsiType getClosureParameterType(GrClosableBlock closure, int index) {
|
||||
PsiElement parent = closure.getParent();
|
||||
if (parent instanceof GrStringInjection && index == 0) {
|
||||
return TypesUtil.createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING_BUILDER, closure);
|
||||
}
|
||||
|
||||
if (parent instanceof GrArgumentList) parent = parent.getParent();
|
||||
if (!(parent instanceof GrMethodCall)) {
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -243,6 +243,6 @@ public class TypeInferenceTest extends GroovyResolveTestCase {
|
||||
}
|
||||
|
||||
public void testSingleParameterInStringInjection() {
|
||||
assertTypeEquals("java.util.StringBuilder", "a.groovy");
|
||||
assertTypeEquals("java.lang.StringBuilder", "a.groovy");
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
[2, 3, 4].collect {"${builder -> bui<ref>lder.append(it)}"}
|
||||
Reference in New Issue
Block a user