mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce: process parenthesis correctly
This commit is contained in:
@@ -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()]);
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user