mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
do not suggest child type if instanceof inside selected block; if child type suggested then insert cast in method call
This commit is contained in:
@@ -96,11 +96,9 @@ public class InputVariables {
|
||||
if (parent instanceof PsiTypeCastExpression) {
|
||||
final PsiType currentType = casts.get(block);
|
||||
final PsiType castType = ((PsiTypeCastExpression)parent).getType();
|
||||
casts.put(block, getBroaderType(currentType, castType));
|
||||
} else if (!(parent instanceof PsiInstanceOfExpression)){
|
||||
if (!casts.containsKey(block)) {
|
||||
casts.put(block, null);
|
||||
}
|
||||
casts.put(block, casts.containsKey(block) && currentType == null ? null : getBroaderType(currentType, castType));
|
||||
} else {
|
||||
casts.put(block, null);
|
||||
}
|
||||
}
|
||||
if (!casts.containsValue(null)) {
|
||||
@@ -263,6 +261,9 @@ public class InputVariables {
|
||||
if (myFoldingAvailable) {
|
||||
buffer.append(myFolding.getGeneratedCallArgument(data));
|
||||
} else {
|
||||
if (!TypeConversionUtil.isAssignable(data.type, data.variable.getType())) {
|
||||
buffer.append("(").append(data.variable.getType().getCanonicalText()).append(")");
|
||||
}
|
||||
buffer.append(data.variable.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
public class Test {
|
||||
void foo(Object o) {
|
||||
if (o instanceof A) {
|
||||
<selection>((A)o).bar();</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
void bar(){}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class Test {
|
||||
void foo(Object o) {
|
||||
if (o instanceof A) {
|
||||
newMethod((Object) o);
|
||||
}
|
||||
}
|
||||
|
||||
private void newMethod(A o) {
|
||||
((A)o).bar();
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
void bar(){}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
void foo(Object o) {
|
||||
<selection>
|
||||
if (o instanceof A1) {
|
||||
((A1)o).doSmth();
|
||||
}
|
||||
</selection>
|
||||
}
|
||||
}
|
||||
|
||||
class A1 {}
|
||||
@@ -463,6 +463,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCast4ParamGeneration() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doPrepareErrorTest(final String expectedMessage) throws Exception {
|
||||
String expectedError = null;
|
||||
try {
|
||||
|
||||
@@ -19,6 +19,7 @@ public class ReplaceMethodDuplicatesTestSuite {
|
||||
testSuite.addTestSuite(ExtractMethodObjectTest.class);
|
||||
testSuite.addTestSuite(FindMethodDuplicatesMiscTest.class);
|
||||
testSuite.addTestSuite(FindMethodDuplicatesTest.class);
|
||||
testSuite.addTestSuite(SuggestedParamTypesTest.class);
|
||||
return testSuite;
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,10 @@ public class SuggestedParamTypesTest extends LightCodeInsightTestCase {
|
||||
doTest("Object");
|
||||
}
|
||||
|
||||
public void testNoCastWhenWrapped() throws Exception {
|
||||
doTest("Object");
|
||||
}
|
||||
|
||||
private void doTest(String... types) throws Exception {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user