mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: disable folding if array is used for writing (IDEA-156818)
This commit is contained in:
+5
-2
@@ -208,7 +208,9 @@ public class ParametersFolder {
|
||||
if (expressions == null) {
|
||||
expressions = new ArrayList<PsiExpression>();
|
||||
while (expression != null) {
|
||||
if (isAccessedForWriting((PsiExpression)expression)) return null;
|
||||
if (isAccessedForWriting((PsiExpression)expression)) {
|
||||
return null;
|
||||
}
|
||||
for (PsiElement scopeElement : scopeElements) {
|
||||
if (PsiTreeUtil.isAncestor(expression, scopeElement, true)) {
|
||||
expression = null;
|
||||
@@ -300,7 +302,8 @@ public class ParametersFolder {
|
||||
PsiElement expression = element;
|
||||
while (expression != null) {
|
||||
if (PsiEquivalenceUtil.areElementsEquivalent(expression, expr)) {
|
||||
return (PsiExpression)expression;
|
||||
PsiExpression psiExpression = (PsiExpression)expression;
|
||||
return PsiUtil.isAccessedForWriting(psiExpression) ? null : psiExpression;
|
||||
}
|
||||
expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class);
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
void f(int size, int[] array) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int x = i;
|
||||
<selection>int tmp = array[i];
|
||||
array[i] = array[x];
|
||||
array[x] = tmp;</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
void f(int size, int[] array) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int x = i;
|
||||
newMethod(array, i, x);
|
||||
}
|
||||
}
|
||||
|
||||
private void newMethod(int[] array, int i, int x) {
|
||||
int tmp = array[i];
|
||||
array[i] = array[x];
|
||||
array[x] = tmp;
|
||||
}
|
||||
}
|
||||
@@ -350,6 +350,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testStopFoldingForArrayWriteAccessInConsequentUsages() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testStopFoldingPostfixInside() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user