extract method object: created object name should be unique (suggestion)

This commit is contained in:
anna
2010-11-15 16:54:59 +03:00
parent ce2ffdf3c8
commit 0c79b901e1
4 changed files with 65 additions and 1 deletions
@@ -682,7 +682,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
@Override
protected void declareNecessaryVariablesAfterCall(final PsiVariable outputVariable) throws IncorrectOperationException {
if (myMultipleExitPoints) {
final String object = StringUtil.decapitalize(myInnerClassName);
final String object = JavaCodeStyleManager.getInstance(myProject).suggestUniqueVariableName(StringUtil.decapitalize(myInnerClassName), outputVariable, true);
final PsiStatement methodCallStatement = PsiTreeUtil.getParentOfType(getMethodCall(), PsiStatement.class);
LOG.assertTrue(methodCallStatement != null);
final PsiStatement declarationStatement = myElementFactory
@@ -0,0 +1,18 @@
class A {
int foo() {
int x = 45;
int y = 46;
int inner = 47;
<selection>x = y + 1;
y = 77;</selection>
x = y + x + 45;
boolean z = true;
if (z) {
return y;
} else {
x = y;
}
y = 45;
return x;
}
}
@@ -0,0 +1,42 @@
class A {
int foo() {
int x = 45;
int y = 46;
int inner = 47;
Inner inner1 = new Inner(y).invoke();
y = inner1.getY();
x = inner1.getX();
x = y + x + 45;
boolean z = true;
if (z) {
return y;
} else {
x = y;
}
y = 45;
return x;
}
private class Inner {
private int y;
private int x;
public Inner(int y) {
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public Inner invoke() {
x = y + 1;
y = 77;
return this;
}
}
}
@@ -80,4 +80,8 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightCodeInsi
public void testOutputVariable() throws Exception {
doTest();
}
public void testUniqueObjectName() throws Exception {
doTest();
}
}