[extract method] fix: don't declare variable twice

GitOrigin-RevId: a7b8bcccb1e4bf4fb5ea35975f12767dae882813
This commit is contained in:
Alexandr Suhinin
2021-12-13 16:56:24 +00:00
committed by intellij-monorepo-bot
parent 973ce0cb93
commit 7bce69f60f
4 changed files with 28 additions and 1 deletions
@@ -74,7 +74,8 @@ fun findExtractOptions(elements: List<PsiElement>): ExtractOptions {
.map { it.copy(type = normalizeType(it.type)) }
val parameterNames = inputParameters.map { it.name }.toSet()
val exposedVariables = analyzer.findExposedLocalDeclarations()
val outputVariable = (dataOutput as? VariableOutput)?.variable
val exposedVariables = analyzer.findExposedLocalDeclarations().filter { exposedVariable -> exposedVariable != outputVariable }
extractOptions = extractOptions.copy(
dataOutput = normalizeDataOutput(dataOutput, flowOutput, elements, exposedVariables.mapNotNull { it.name }),
@@ -0,0 +1,7 @@
public class Test {
void test(boolean condition) {
<selection>String s = "42";</selection>
if (condition) s = "new";
System.out.println(s);
}
}
@@ -0,0 +1,15 @@
import org.jetbrains.annotations.NotNull;
public class Test {
void test(boolean condition) {
String s = getString();
if (condition) s = "new";
System.out.println(s);
}
@NotNull
private String getString() {
String s = "42";
return s;
}
}
@@ -202,6 +202,10 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() {
doTest()
}
fun testChangedVariableDeclaredOnce(){
doTest()
}
fun testRefactoringListener(){
templateTest {
configureByFile("$BASE_PATH/${getTestName(false)}.java")