mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ExtractMethod: support disjunction type variables
Fixes EA-143189 - Incorrect parameter 'java.io.IOException | java.lang.RuntimeException e' GitOrigin-RevId: 3bbdebaa6f7110e4d86eb36c34fea2f8e09ce351
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ba13cba904
commit
c9f0692714
@@ -4,6 +4,7 @@ package com.intellij.refactoring.util;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.PsiImmediateClassType;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -13,7 +14,7 @@ public class VariableData extends AbstractVariableData {
|
||||
|
||||
public VariableData(@NotNull PsiVariable var) {
|
||||
variable = var;
|
||||
type = var.getType();
|
||||
type = correctType(var.getType());
|
||||
}
|
||||
|
||||
public VariableData(@Nullable PsiVariable var, PsiType type) {
|
||||
@@ -22,13 +23,20 @@ public class VariableData extends AbstractVariableData {
|
||||
if (LambdaUtil.notInferredType(type)) {
|
||||
type = PsiType.getJavaLangObject(var.getManager(), GlobalSearchScope.allScope(var.getProject()));
|
||||
}
|
||||
this.type = SmartTypePointerManager.getInstance(var.getProject()).createSmartTypePointer(type).getType();
|
||||
this.type = correctType(SmartTypePointerManager.getInstance(var.getProject()).createSmartTypePointer(type).getType());
|
||||
}
|
||||
else {
|
||||
this.type = type;
|
||||
this.type = correctType(type);
|
||||
}
|
||||
}
|
||||
|
||||
private static PsiType correctType(PsiType varType) {
|
||||
if (varType instanceof PsiDisjunctionType) {
|
||||
return PsiTypesUtil.getLowestUpperBoundClassType((PsiDisjunctionType)varType);
|
||||
}
|
||||
return varType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VariableData substitute(@Nullable PsiVariable var) {
|
||||
if (var == null) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
public class DisjunctionType {
|
||||
static void test() {
|
||||
try {
|
||||
foo();
|
||||
}
|
||||
catch (NoSuchFieldException | NoSuchMethodException ex) {
|
||||
<selection>
|
||||
System.out.println(ex.getCause());
|
||||
</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
public class DisjunctionType {
|
||||
static void test() {
|
||||
try {
|
||||
foo();
|
||||
}
|
||||
catch (NoSuchFieldException | NoSuchMethodException ex) {
|
||||
|
||||
newMethod(ex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void newMethod(ReflectiveOperationException ex) {
|
||||
System.out.println(ex.getCause());
|
||||
}
|
||||
}
|
||||
@@ -1382,6 +1382,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
public void testFromStaticMethodInInterface() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDisjunctionType() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestDisabledParam() throws PrepareFailedException {
|
||||
final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
|
||||
Reference in New Issue
Block a user