support for disjunction types in create from usage intentions (IDEA-129453)

This commit is contained in:
Anna Kozlova
2014-09-04 15:07:12 +04:00
parent 46fafc29fc
commit f35847c962
4 changed files with 34 additions and 0 deletions
@@ -403,6 +403,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
if (varargParam != null && pi >= parameters.length) return false;
PsiType exprType = RefactoringUtil.getTypeByExpression(expression);
if (exprType == null) return false;
exprType = GenericsUtil.getVariableTypeByExpressionType(exprType);
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject());
String name = suggestUniqueParameterName(codeStyleManager, expression, exprType, existingNames);
final ParameterInfoImpl newParameterInfo = new ParameterInfoImpl(-1, name, exprType, expression.getText().replace('\n', ' '));
@@ -351,6 +351,9 @@ public class GenericsUtil {
@Nullable
public static PsiType getVariableTypeByExpressionType(@Nullable PsiType type, final boolean openCaptured) {
if (type == null) return null;
if (type instanceof PsiDisjunctionType) {
type = ((PsiDisjunctionType)type).getLeastUpperBound();
}
if (type instanceof PsiCapturedWildcardType) {
type = ((PsiCapturedWildcardType)type).getWildcard();
}
@@ -0,0 +1,15 @@
// "Add 'Exception' as 1st parameter to method 'f'" "true"
import java.io.FileInputStream;
import java.io.IOException;
class Test {
public void createFileInputStream() {
try {
new FileInputStream("test");
} catch (IOException |NullPointerException e) {
f(e);
}
}
public void f(Exception e) { }
}
@@ -0,0 +1,15 @@
// "Add 'Exception' as 1st parameter to method 'f'" "true"
import java.io.FileInputStream;
import java.io.IOException;
class Test {
public void createFileInputStream() {
try {
new FileInputStream("test");
} catch (IOException |NullPointerException e) {
f(<caret>e);
}
}
public void f() { }
}