mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: check duplicates/used vars also in unreachable code
(cherry picked from commit 42249fe8f0cead1a0023aa9edfb23fc52a95c268)
This commit is contained in:
@@ -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());
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+22
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user