mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Java: Don't fold the whole extracted expression - simplified the fix (IDEA-195927)
This commit is contained in:
@@ -30,7 +30,6 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.RefactoringChangeUtil;
|
||||
import com.intellij.refactoring.util.VariableData;
|
||||
import com.intellij.refactoring.util.duplicates.DuplicatesFinder;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -216,8 +215,6 @@ public class ParametersFolder {
|
||||
private List<PsiExpression> getMentionedExpressions(PsiVariable var, LocalSearchScope scope, final List<? extends PsiVariable> inputVariables) {
|
||||
if (myMentionedInExpressions.containsKey(var)) return myMentionedInExpressions.get(var);
|
||||
final PsiElement[] scopeElements = scope.getScope();
|
||||
final PsiExpression scopeExpression =
|
||||
PsiUtil.skipParenthesizedExprDown(scopeElements.length == 1 ? ObjectUtils.tryCast(scopeElements[0], PsiExpression.class) : null);
|
||||
|
||||
List<PsiExpression> expressions = null;
|
||||
for (PsiReference reference : ReferencesSearch.search(var, scope)) {
|
||||
@@ -228,7 +225,7 @@ public class ParametersFolder {
|
||||
if (isAccessedForWriting((PsiExpression)expression)) {
|
||||
return null;
|
||||
}
|
||||
if (expression == scopeExpression || isAncestor(expression, scopeElements)) {
|
||||
if (isAncestor(expression, scopeElements)) {
|
||||
break;
|
||||
}
|
||||
if (dependsOnLocals(expression, inputVariables)) {
|
||||
@@ -285,7 +282,7 @@ public class ParametersFolder {
|
||||
|
||||
private static boolean isAncestor(PsiElement expression, PsiElement[] scopeElements) {
|
||||
for (PsiElement scopeElement : scopeElements) {
|
||||
if (PsiTreeUtil.isAncestor(expression, scopeElement, true)) {
|
||||
if (PsiTreeUtil.isAncestor(expression, scopeElement, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
class C {
|
||||
int x;
|
||||
|
||||
int b(boolean[] b, C[] c, int n) {
|
||||
int i = n;
|
||||
while (i >= 0 && <selection>(b[i] || c[n].x == c[i].x)</selection>) {
|
||||
i--;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int a(boolean[] b, C[] c, int n) {
|
||||
int i = n;
|
||||
while (i < c.length && (b[i] || c[n].x == c[i].x)) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
class C {
|
||||
int x;
|
||||
|
||||
int b(boolean[] b, C[] c, int n) {
|
||||
int i = n;
|
||||
while (i >= 0 && newMethod(b[i], c[n].x == c[i].x)) {
|
||||
i--;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private boolean newMethod(boolean b2, boolean b1) {
|
||||
return b2 || b1;
|
||||
}
|
||||
|
||||
int a(boolean[] b, C[] c, int n) {
|
||||
int i = n;
|
||||
while (i < c.length && (newMethod(b[i], c[n].x == c[i].x))) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1295,6 +1295,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testDuplicateSubexpressionWithParentheses() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testBeforeCommentAfterSelectedFragment() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user