mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
inline method: check unique names for this variable in initial class scope (IDEA-127411)
This commit is contained in:
@@ -791,7 +791,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
String[] names = myJavaCodeStyle.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, thisType)
|
||||
.names;
|
||||
String thisVarName = names[0];
|
||||
thisVarName = myJavaCodeStyle.suggestUniqueVariableName(thisVarName, block.getFirstChild(), true);
|
||||
thisVarName = myJavaCodeStyle.suggestUniqueVariableName(thisVarName, myMethod.getFirstChild(), true);
|
||||
PsiExpression initializer = myFactory.createExpressionFromText("null", null);
|
||||
PsiDeclarationStatement declaration = myFactory.createVariableDeclarationStatement(thisVarName, thisType, initializer);
|
||||
declaration = (PsiDeclarationStatement)block.addAfter(declaration, null);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
private final String test = "";
|
||||
|
||||
{
|
||||
foo();
|
||||
}
|
||||
|
||||
void fo<caret>o() {
|
||||
if (test.isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
private final String test = "";
|
||||
|
||||
{
|
||||
if (test.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -268,6 +268,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testThisNameConflict() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestInlineThisOnly() {
|
||||
@NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java";
|
||||
configureByFile(fileName);
|
||||
|
||||
Reference in New Issue
Block a user