introduce: process parenthesis correctly

This commit is contained in:
unknown
2010-07-05 14:55:33 +04:00
committed by anna
parent f87d17b2a3
commit b9ca9a904c
4 changed files with 22 additions and 1 deletions
@@ -171,7 +171,14 @@ public class CodeInsightUtil {
public static PsiExpression[] findExpressionOccurrences(PsiElement scope, PsiExpression expr) {
List<PsiExpression> array = new ArrayList<PsiExpression>();
addExpressionOccurrences(RefactoringUtil.unparenthesizeExpression(expr), array, scope);
if (!array.contains(expr)) array.add(expr);
boolean found = false;
for (PsiExpression psiExpression : array) {
if (areExpressionsEquivalent(RefactoringUtil.unparenthesizeExpression(psiExpression), RefactoringUtil.unparenthesizeExpression(expr))) {
found = true;
break;
}
}
if (!found) array.add(expr);
return array.toArray(new PsiExpression[array.size()]);
}
@@ -0,0 +1,5 @@
public class Introduce {
void foo(String str) {
final String s = (String) str;
}
}
@@ -0,0 +1,5 @@
public class Introduce {
void foo(String str) {
<selection>((String)str)</selection>
}
}
@@ -74,6 +74,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("empty", true, true, true, "boolean"));
}
public void testParenthizedOccurence1() throws Exception {
doTest(new MockIntroduceVariableHandler("s", true, true, true, "java.lang.String"));
}
public void testConflictingField() throws Exception {
doTest(new MockIntroduceVariableHandler("name", true, false, true, "java.lang.String"));
}