mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
ExpectedTypesProvider: do not suggest null[] type if iteration parameter type is null
Fixes IDEA-207987 Create local variable suggested but fails with exception
This commit is contained in:
@@ -487,6 +487,8 @@ public class ExpectedTypesProvider {
|
||||
if (myExpr.equals(statement.getIteratedValue())) {
|
||||
PsiType type = statement.getIterationParameter().getType();
|
||||
|
||||
if (PsiType.NULL.equals(type)) return;
|
||||
|
||||
PsiType arrayType = type.createArrayType();
|
||||
myResult.add(createInfoImpl(arrayType, arrayType));
|
||||
|
||||
@@ -494,7 +496,7 @@ public class ExpectedTypesProvider {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(manager.getProject());
|
||||
PsiClass iterableClass =
|
||||
JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Iterable", statement.getResolveScope());
|
||||
if (iterableClass != null && iterableClass.getTypeParameters().length == 1 && !PsiType.NULL.equals(type)) {
|
||||
if (iterableClass != null && iterableClass.getTypeParameters().length == 1) {
|
||||
Map<PsiTypeParameter, PsiType> map = new HashMap<>();
|
||||
map.put(iterableClass.getTypeParameters()[0], PsiWildcardType.createExtends(manager, type));
|
||||
PsiType iterableType = factory.createType(iterableClass, factory.createSubstitutor(map));
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.util.*;
|
||||
|
||||
class Foo {
|
||||
List<String> bar() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (var integer : in<caret>put) {
|
||||
list.add(integer == null ? null : integer.toString());
|
||||
}
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
@@ -580,6 +580,17 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("l", false, false, false, "D<java.lang.Integer>", false));
|
||||
}
|
||||
|
||||
public void testForIterationParameterVar() {
|
||||
try {
|
||||
doTest(new MockIntroduceVariableHandler("input", false, false, false, "Object", false));
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("Error message:Cannot perform refactoring.\nUnknown expression type.", e.getMessage());
|
||||
return;
|
||||
}
|
||||
fail("Should not be able to perform refactoring");
|
||||
}
|
||||
|
||||
public void testOneLineLambdaVoidCompatible() {
|
||||
doTest(new MockIntroduceVariableHandler("c", false, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user