extract method duplicates: distinguish method overloads (IDEA-97777)

This commit is contained in:
Anna Kozlova
2013-06-17 21:10:25 +04:00
parent 059e0c6691
commit a1096fae35
4 changed files with 56 additions and 0 deletions
@@ -394,6 +394,12 @@ public class DuplicatesFinder {
match.registerReturnValue(new ContinueReturnValue());
} else if (pattern instanceof PsiBreakStatement) {
match.registerReturnValue(new BreakReturnValue());
}else if (pattern instanceof PsiMethodCallExpression) {
final PsiMethod patternMethod = ((PsiMethodCallExpression)pattern).resolveMethod();
final PsiMethod candidateMethod = ((PsiMethodCallExpression)candidate).resolveMethod();
if (patternMethod != null && candidateMethod != null) {
if (!MethodSignatureUtil.areSignaturesEqual(patternMethod, candidateMethod)) return false;
}
} else if (pattern instanceof PsiReferenceExpression) {
final PsiReferenceExpression patternRefExpr = (PsiReferenceExpression)pattern;
final PsiReferenceExpression candidateRefExpr = (PsiReferenceExpression)candidate;
@@ -0,0 +1,21 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class Test {
public void myTest(List list, String s1, String s2) {
}
public void myTest(Collection list, String s1, String s2) {
}
public void usage() {
List list = new ArrayList();
String aa = "AA";
String bb = "bb";
myTest(list, aa, bb);
Collection col = new ArrayList();
<selection>myTest(col, aa, bb);</selection>
}
}
@@ -0,0 +1,25 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class Test {
public void myTest(List list, String s1, String s2) {
}
public void myTest(Collection list, String s1, String s2) {
}
public void usage() {
List list = new ArrayList();
String aa = "AA";
String bb = "bb";
myTest(list, aa, bb);
Collection col = new ArrayList();
newMethod(aa, bb, col);
}
private void newMethod(String aa, String bb, Collection col) {
myTest(col, aa, bb);
}
}
@@ -583,6 +583,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doDuplicatesTest();
}
public void testOverloadedMethods() throws Exception {
doDuplicatesTest();
}
public void testTargetAnonymous() throws Exception {
doTest();
}