find occurrences: distinguish <> with different inference (IDEA-66176)

This commit is contained in:
anna
2011-03-11 11:44:42 +01:00
parent ef19124922
commit 1b09d55adc
5 changed files with 44 additions and 2 deletions
@@ -28,6 +28,7 @@ import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PsiDiamondTypeElementImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.tree.IElementType;
@@ -225,7 +226,17 @@ public class CodeInsightUtil {
}
return 1;
}
}, false);
}, new Comparator<PsiElement>() {
@Override
public int compare(PsiElement o1, PsiElement o2) {
if (o1 instanceof PsiDiamondTypeElementImpl && o2 instanceof PsiDiamondTypeElementImpl) {
final PsiDiamondType.DiamondInferenceResult thisInferenceResult = new PsiDiamondType(o1.getManager(), (PsiTypeElement)o1).resolveInferredTypes();
final PsiDiamondType.DiamondInferenceResult otherInferenceResult = new PsiDiamondType(o2.getManager(), (PsiTypeElement)o2).resolveInferredTypes();
return thisInferenceResult.equals(otherInferenceResult) ? 0 : 1;
}
return 0;
}
}, false);
}
public static Editor positionCursor(final Project project, PsiFile targetFile, PsiElement element) {
@@ -0,0 +1,9 @@
import java.util.*;
class Test {
void foo(final ArrayList<String> anObject) {
List<String> ls = anObject;
List<String> lss = anObject;
List<Integer> li = new ArrayList<>();
}
}
@@ -0,0 +1,9 @@
import java.util.*;
class Test {
void foo() {
List<String> ls = <selection>new ArrayList<>()</selection>;
List<String> lss = new ArrayList<>();
List<Integer> li = new ArrayList<>();
}
}
@@ -264,6 +264,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false);
}
public void testDiamondOccurrences() throws Exception {
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false);
}
private void doTestThroughHandler() throws Exception {
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext() {