replace duplicates: process chained constructors (IDEA-138745)

This commit is contained in:
Anna Kozlova
2015-04-08 12:05:59 +02:00
parent 822934d37a
commit e1e48eb1e8
4 changed files with 35 additions and 1 deletions
@@ -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();
@@ -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);
}
}
@@ -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);
}