mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Don't fold method parameters when replacing duplicate fragments (IDEA-179519, IDEA-180673)
This commit is contained in:
+5
@@ -151,6 +151,11 @@ public class JavaDuplicatesExtractMethodProcessor extends ExtractMethodProcessor
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFoldingApplicable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiElement updateCallQualifier(PsiMethodCallExpression callExpression) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(myProject);
|
||||
|
||||
+1
-6
@@ -209,12 +209,7 @@ public class ParametrizedDuplicates {
|
||||
Map<PsiLocalVariable, ClusterOfUsages> parameterDeclarations = createParameterDeclarations(originalProcessor, expressionsMapping);
|
||||
putMatchParameters(parameterDeclarations);
|
||||
|
||||
JavaDuplicatesExtractMethodProcessor parametrizedProcessor = new JavaDuplicatesExtractMethodProcessor(myElements, REFACTORING_NAME) {
|
||||
@Override
|
||||
protected boolean isFoldingApplicable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
JavaDuplicatesExtractMethodProcessor parametrizedProcessor = new JavaDuplicatesExtractMethodProcessor(myElements, REFACTORING_NAME);
|
||||
if (!parametrizedProcessor.prepare(false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
class RenamedParameter {
|
||||
private boolean c;
|
||||
|
||||
public void foo() {
|
||||
String a = "s";
|
||||
String b = "t";
|
||||
<selection>if (c) {
|
||||
String t = b;
|
||||
x(t);
|
||||
} else if (!b.equals(a)) {
|
||||
x(b);
|
||||
}</selection>
|
||||
}
|
||||
|
||||
public void bar() {
|
||||
String a = "t";
|
||||
String b = "s";
|
||||
if (c) {
|
||||
String t = b;
|
||||
x(t);
|
||||
} else if (!b.equals(a)) {
|
||||
x(b);
|
||||
}
|
||||
}
|
||||
|
||||
void x(String s) {}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
class RenamedParameter {
|
||||
private boolean c;
|
||||
|
||||
public void foo() {
|
||||
String a = "s";
|
||||
String b = "t";
|
||||
newMethod(a, b);
|
||||
}
|
||||
|
||||
private void newMethod(String a, String b) {
|
||||
if (c) {
|
||||
String t = b;
|
||||
x(t);
|
||||
} else if (!b.equals(a)) {
|
||||
x(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void bar() {
|
||||
String a = "t";
|
||||
String b = "s";
|
||||
newMethod(a, b);
|
||||
}
|
||||
|
||||
void x(String s) {}
|
||||
}
|
||||
@@ -852,6 +852,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testConditionalWithTwoParameters() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testSuggestChangeSignatureWithChangedParameterName() throws Exception {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
boolean success = performExtractMethod(true, true, getEditor(), getFile(), getProject(), false, null, false, "p");
|
||||
|
||||
Reference in New Issue
Block a user