mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Preserve comment right after the loop
GitOrigin-RevId: e096580618c805f0e1f5c8e1a878b5e3321174c7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b2c6daba06
commit
1f6ad2d2bb
@@ -206,7 +206,6 @@ public class UnrollLoopAction extends PsiElementBaseIntentionAction {
|
||||
CommentTracker ct = new CommentTracker();
|
||||
PsiElement anchor = loop;
|
||||
for (PsiExpression expression : expressions) {
|
||||
ct.markUnchanged(loop.getBody());
|
||||
PsiLoopStatement copy = (PsiLoopStatement)factory.createStatementFromText(loop.getText(), element);
|
||||
PsiVariable variable = Objects.requireNonNull(getVariable(copy));
|
||||
for (PsiReference reference : ReferencesSearch.search(variable, new LocalSearchScope(copy))) {
|
||||
@@ -220,10 +219,17 @@ public class UnrollLoopAction extends PsiElementBaseIntentionAction {
|
||||
assert body != null;
|
||||
PsiElement[] children;
|
||||
if (body instanceof PsiBlockStatement) {
|
||||
PsiCodeBlock block = ((PsiBlockStatement)Objects.requireNonNull(loop.getBody())).getCodeBlock();
|
||||
PsiElement firstBodyElement = block.getFirstBodyElement();
|
||||
PsiElement lastBodyElement = block.getLastBodyElement();
|
||||
if (firstBodyElement != null && lastBodyElement != null) {
|
||||
ct.markRangeUnchanged(firstBodyElement, lastBodyElement);
|
||||
}
|
||||
children = ((PsiBlockStatement)body).getCodeBlock().getChildren();
|
||||
// Skip {braces}
|
||||
children = Arrays.copyOfRange(children, 1, children.length-1);
|
||||
} else {
|
||||
ct.markUnchanged(loop.getBody());
|
||||
children = new PsiElement[]{body};
|
||||
}
|
||||
for(PsiElement child : children) {
|
||||
|
||||
@@ -12,7 +12,7 @@ class Test {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//Comment
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
|
||||
@@ -4,7 +4,7 @@ class Test {
|
||||
fo<caret>r(Object x : new Object[] {"one", 1, 1.0, 1.0f}) {
|
||||
if(Math.random() > 0.5) break;
|
||||
System.out.println(x);
|
||||
}
|
||||
}//Comment
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
|
||||
Reference in New Issue
Block a user