introduce variable: suppose that params are equivalent if they have the same name and types were already checked (IDEA-41074)

This commit is contained in:
anna
2010-05-26 13:28:39 +04:00
parent 5c6d20dc4e
commit c1db7b9edc
4 changed files with 67 additions and 1 deletions
@@ -193,7 +193,14 @@ public class CodeInsightUtil {
}
public static boolean areExpressionsEquivalent(PsiExpression expr1, PsiExpression expr2) {
return PsiEquivalenceUtil.areElementsEquivalent(expr1, expr2);
return PsiEquivalenceUtil.areElementsEquivalent(expr1, expr2, new Comparator<PsiElement>() {
public int compare(PsiElement o1, PsiElement o2) {
if (o1 instanceof PsiParameter && o2 instanceof PsiParameter) {
return ((PsiParameter)o1).getName().compareTo(((PsiParameter)o2).getName());
}
return 1;
}
}, false);
}
public static Editor positionCursor(final Project project, PsiFile targetFile, PsiElement element) {
@@ -0,0 +1,26 @@
public class Foo {
public static void bazz(int i) {
final Foo foo1 = new Foo(new IBar() {
public void doSomething() {
System.out.println("hello");
}
});
final Foo foo = i != 0 ? foo1 : foo1;
foo.bla();
}
private final IBar bar;
public Foo(IBar bar) {
this.bar = bar;
}
public void bla() {
bar.doSomething();
}
public interface IBar {
void doSomething();
}
}
@@ -0,0 +1,29 @@
public class Foo {
public static void bazz(int i) {
final Foo foo = i != 0 ? <selection>new Foo(new IBar() {
public void doSomething() {
System.out.println("hello");
}
})</selection> : new Foo(new IBar() {
public void doSomething() {
System.out.println("hello");
}
});
foo.bla();
}
private final IBar bar;
public Foo(IBar bar) {
this.bar = bar;
}
public void bla() {
bar.doSomething();
}
public interface IBar {
void doSomething();
}
}
@@ -197,6 +197,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("ab", true, true, false, "boolean"));
}
public void testDuplicatesAnonymousClassCreationWithSimilarParameters () throws Exception {
doTest(new MockIntroduceVariableHandler("foo1", true, true, false, "Foo"));
}
public void testNonExpressionPriorityFailure() throws Exception {
doTest(new MockIntroduceVariableHandler("sum", true, true, false, "int"){
@Override