mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method object: created object name should be unique (suggestion)
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+18
@@ -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;
|
||||
}
|
||||
}
|
||||
+42
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -80,4 +80,8 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightCodeInsi
|
||||
public void testOutputVariable() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUniqueObjectName() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user