extract method: check duplicates/used vars also in unreachable code

(cherry picked from commit 42249fe8f0cead1a0023aa9edfb23fc52a95c268)
This commit is contained in:
Anna Kozlova
2015-03-11 20:33:25 +01:00
parent 12156212e9
commit 5435a357c6
5 changed files with 44 additions and 2 deletions
@@ -282,7 +282,7 @@ public final class Match {
try {
final Project project = getMatchStart().getProject();
final ControlFlow controlFlow = ControlFlowFactory.getInstance(project)
.getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment));
.getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment), false, false);
final int endOffset = controlFlow.getEndOffset(getMatchEnd());
final int startOffset = controlFlow.getStartOffset(getMatchStart());
final List<PsiVariable> usedVariables = ControlFlowUtil.getUsedVariables(controlFlow, endOffset, controlFlow.getSize());
@@ -150,7 +150,7 @@ public class ExtractLightMethodObjectHandler {
final ControlFlow controlFlow;
try {
controlFlow = ControlFlowFactory.getInstance(project).getControlFlow(container, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance());
controlFlow = ControlFlowFactory.getInstance(project).getControlFlow(container, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(), false, false);
}
catch (AnalysisCanceledException e) {
return null;
@@ -0,0 +1,16 @@
class A {
private static final boolean ourOverrideFinalFields = false;
public static String createShared(char[] chars) {
if (ourOverrideFinalFields) {
String s = new String();
return s;
}
String s = <selection>new String()</selection>;
return new String(chars);
}
}
@@ -0,0 +1,22 @@
import org.jetbrains.annotations.NotNull;
class A {
private static final boolean ourOverrideFinalFields = false;
public static String createShared(char[] chars) {
if (ourOverrideFinalFields) {
String s = newMethod();
return s;
}
String s = newMethod();
return new String(chars);
}
@NotNull
private static String newMethod() {
return new String();
}
}
@@ -233,6 +233,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doDuplicatesTest();
}
public void testDuplicateInUnreachableCode() throws Exception {
doDuplicatesTest();
}
public void testExpressionDuplicates() throws Exception {
doDuplicatesTest();
}