mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace duplicates: process chained constructors (IDEA-138745)
This commit is contained in:
+2
-1
@@ -58,8 +58,9 @@ class MethodDuplicatesMatchProvider implements MatchProvider {
|
||||
final boolean needQualifier = match.getInstanceExpression() != null;
|
||||
final boolean needStaticQualifier = isExternal(match);
|
||||
final boolean nameConflicts = nameConflicts(match);
|
||||
final String methodName = myMethod.isConstructor() ? "this" : myMethod.getName();
|
||||
@NonNls final String text = needQualifier || needStaticQualifier || nameConflicts
|
||||
? "q." + myMethod.getName() + "()": myMethod.getName() + "()";
|
||||
? "q." + methodName + "()": methodName + "()";
|
||||
PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)factory.createExpressionFromText(text, null);
|
||||
methodCallExpression = (PsiMethodCallExpression)CodeStyleManager.getInstance(myMethod.getManager()).reformat(methodCallExpression);
|
||||
final PsiParameter[] parameters = myMethod.getParameterList().getParameters();
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
public A(String a) {
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public B(String a) {
|
||||
this(a, null);
|
||||
}
|
||||
public B(String a, final String anObject) {
|
||||
super(a);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
public A(String a) {
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public B(String a) {
|
||||
super(a);
|
||||
}
|
||||
public B(String a) {
|
||||
super(a);
|
||||
String <caret>b = "b";
|
||||
}
|
||||
}
|
||||
@@ -341,6 +341,12 @@ public class IntroduceParameterTest extends LightRefactoringTestCase {
|
||||
checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testCodeDuplicatesFromConstructor() {
|
||||
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
|
||||
perform(true, 0, "anObject", false, true, true, false, 0, true);
|
||||
checkResultByFile("/refactoring/introduceParameter/after" + getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testTypeAnnotation() {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, false, false, false, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user