introduce: do not treat as same different foreach vars (IDEA-58421)

This commit is contained in:
anna
2010-10-05 18:48:10 +04:00
parent f04f503a63
commit a4c29ba8ce
4 changed files with 28 additions and 1 deletions
@@ -219,7 +219,7 @@ public class CodeInsightUtil {
public static boolean areExpressionsEquivalent(PsiExpression expr1, PsiExpression expr2) {
return PsiEquivalenceUtil.areElementsEquivalent(expr1, expr2, new Comparator<PsiElement>() {
public int compare(PsiElement o1, PsiElement o2) {
if (o1 instanceof PsiParameter && o2 instanceof PsiParameter) {
if (o1 instanceof PsiParameter && o2 instanceof PsiParameter && ((PsiParameter)o1).getDeclarationScope() instanceof PsiMethod) {
return ((PsiParameter)o1).getName().compareTo(((PsiParameter)o2).getName());
}
return 1;
@@ -0,0 +1,12 @@
class A {
{
List<Integer> l = new ArrayList<Integer>();
for (Integer i : l) {
final String tostr = i.toString();
System.out.println(tostr);
}
for (Integer i : l) {
System.out.println(i.toString());
}
}
}
@@ -0,0 +1,11 @@
class A {
{
List<Integer> l = new ArrayList<Integer>();
for (Integer i : l) {
System.out.println(<selection>i.toString()</selection>);
}
for (Integer i : l) {
System.out.println(i.toString());
}
}
}
@@ -218,6 +218,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("foo1", true, true, false, "Foo"));
}
public void testDifferentForeachParameters () throws Exception {
doTest(new MockIntroduceVariableHandler("tostr", true, true, false, "java.lang.String"));
}
public void testSiblingInnerClassType() throws Exception {
doTest(new MockIntroduceVariableHandler("vari", true, false, false, "A.B"){
@Override