extract method: do not suggest to replace duplicates if candidates intersects with extracted method

This commit is contained in:
anna
2012-12-17 21:45:38 +01:00
parent 77e8d52790
commit 746ed966f9
4 changed files with 28 additions and 2 deletions
@@ -164,7 +164,9 @@ public class DuplicatesFinder {
@Nullable
private Match isDuplicateFragment(PsiElement candidate, boolean ignoreParameterTypes) {
if (PsiTreeUtil.isAncestor(myPattern[0], candidate, false)) return null;
for (PsiElement pattern : myPattern) {
if (PsiTreeUtil.isAncestor(pattern, candidate, false)) return null;
}
PsiElement sibling = candidate;
ArrayList<PsiElement> candidates = new ArrayList<PsiElement>();
for (final PsiElement element : myPattern) {
@@ -0,0 +1,8 @@
class Test {
public static void main(String[] args) {
<selection>System.out.println("hello");
System.out.println("hello");</selection>
System.out.println("hello");
}
}
@@ -0,0 +1,12 @@
class Test {
public static void main(String[] args) {
newMethod();
System.out.println("hello");
}
private static void newMethod() {
System.out.println("hello");
System.out.println("hello");
}
}
@@ -561,7 +561,11 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
public void testFinalParams4LocalClasses() throws Exception {
doTest();
}
public void testTwoFromThreeEqStatements() throws Exception {
doDuplicatesTest();
}
private void doTestDisabledParam() throws PrepareFailedException {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.ELSE_ON_NEW_LINE = true;