mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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) {
|
||||
|
||||
+26
@@ -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();
|
||||
}
|
||||
}
|
||||
+29
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user