mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
eliminate captured wildcards in itli live template list component type (IDEA-159655)
This commit is contained in:
+2
-9
@@ -23,9 +23,9 @@ import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInsight.template.impl.JavaTemplateUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.GenericsUtil;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiWildcardType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -79,14 +79,7 @@ public class GuessElementTypeMacro extends Macro {
|
||||
if (expr == null) return null;
|
||||
PsiType[] types = GuessManager.getInstance(project).guessContainerElementType(expr, new TextRange(context.getTemplateStartOffset(), context.getTemplateEndOffset()));
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
PsiType type = types[i];
|
||||
if (type instanceof PsiWildcardType) {
|
||||
if (((PsiWildcardType)type).isExtends()) {
|
||||
types[i] = ((PsiWildcardType)type).getBound();
|
||||
} else {
|
||||
types[i] = PsiType.getJavaLangObject(expr.getManager(), expr.getResolveScope());
|
||||
}
|
||||
}
|
||||
types[i] = GenericsUtil.eliminateWildcards(types[i], false, true);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
@@ -1461,4 +1461,19 @@ class Foo {
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
public void "test iterate over list with wildcard component type"() {
|
||||
myFixture.configureByText 'a.java', '''class C {{
|
||||
java.util.List<? extends Integer> list;
|
||||
<caret>
|
||||
}}'''
|
||||
myFixture.type('itli\t')
|
||||
myFixture.checkResult '''class C {{
|
||||
java.util.List<? extends Integer> list;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Integer integer = list.get(i);
|
||||
|
||||
}
|
||||
}}'''
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user