WrapWithAdapterMethodCallFix: correctly handle disjunction type

Fixes EA-116570 Cannot create expression for type class com.intellij.psi.PsiDisjunctionType
This commit is contained in:
Tagir Valeev
2018-02-18 07:54:47 +07:00
parent 59c39f06fa
commit 413aca292b
3 changed files with 31 additions and 0 deletions
@@ -66,6 +66,9 @@ public class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentionActio
}
PsiType variableType = GenericsUtil.getVariableTypeByExpressionType(inType);
if (LambdaUtil.notInferredType(variableType)) return false;
if (variableType instanceof PsiDisjunctionType) {
variableType = ((PsiDisjunctionType)variableType).getLeastUpperBound();
}
String typeText = variableType.getCanonicalText();
// Empty text can be generated by PsiImmediateClassType if unresolved anonymous class is created like new X() {}
@@ -0,0 +1,14 @@
// "Wrap using 'Collections.singletonList()'" "true"
import java.util.*;
class Test {
List<Throwable> test() {
try {
System.out.println();
}
catch (Exception | Error ex) {
return Collections.singletonList(ex);
}
return null;
}
}
@@ -0,0 +1,14 @@
// "Wrap using 'Collections.singletonList()'" "true"
import java.util.*;
class Test {
List<Throwable> test() {
try {
System.out.println();
}
catch (Exception | Error ex) {
return e<caret>x;
}
return null;
}
}