extract method: new signature detector: add unused parameters to method calls as refs to initial vars

This commit is contained in:
Anna Kozlova
2014-12-05 17:35:36 +01:00
parent 092c1193f0
commit ea292f0319
4 changed files with 28 additions and 0 deletions
@@ -1219,6 +1219,8 @@ public class ExtractMethodProcessor implements MatchProvider {
}
methodCallExpression.getArgumentList().add(val);
}
} else {
methodCallExpression.getArgumentList().add(myElementFactory.createExpressionFromText(data.variable.getName(), methodCallExpression));
}
}
return match.replace(myExtractedMethod, methodCallExpression, myOutputVariable);
@@ -0,0 +1,9 @@
public class Test {
{
int x = 0;
<selection>System.out.println("foo".substring(x));</selection>
System.out.println("bar".substring(x));
}
}
@@ -0,0 +1,13 @@
public class Test {
{
int x = 0;
newMethod(x, "foo".substring(x));
newMethod(x, "bar".substring(x));
}
private void newMethod(int x, String substring) {
System.out.println(substring);
}
}
@@ -627,6 +627,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doDuplicatesTest();
}
public void testSuggestChangeSignatureInitialParameterUnused() 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");