mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java intention: Quick fix for error "foreach not applicable to type java.util.Iterator" - handle comments and take care of empty block when copying the loop body (IDEA-124751)
This commit is contained in:
+7
-5
@@ -42,14 +42,14 @@ public class ReplaceIteratorForEachLoopWithIteratorForLoopFix implements Intenti
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Replace 'for each' loop with iterator 'for' loop";
|
||||
return getFamilyName();
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return getText();
|
||||
return "Replace 'for each' loop with iterator 'for' loop";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,9 +112,11 @@ public class ReplaceIteratorForEachLoopWithIteratorForLoopFix implements Intenti
|
||||
newForLoop = (PsiForStatement)styleManager.reformat(newForLoop);
|
||||
|
||||
if (forEachBody instanceof PsiBlockStatement) {
|
||||
final PsiStatement[] statements = ((PsiBlockStatement)forEachBody).getCodeBlock().getStatements();
|
||||
for (int i = statements.length - 1; i >= 0; i--) {
|
||||
newBodyBlock.addAfter(statements[i], newFirstStatement);
|
||||
final PsiCodeBlock bodyCodeBlock = ((PsiBlockStatement)forEachBody).getCodeBlock();
|
||||
final PsiElement firstBodyElement = bodyCodeBlock.getFirstBodyElement();
|
||||
final PsiElement lastBodyElement = bodyCodeBlock.getLastBodyElement();
|
||||
if (firstBodyElement != null && lastBodyElement != null) {
|
||||
newBodyBlock.addRangeAfter(firstBodyElement, lastBodyElement, newFirstStatement);
|
||||
}
|
||||
}
|
||||
else if (forEachBody != null && !(forEachBody instanceof PsiEmptyStatement)) {
|
||||
|
||||
Reference in New Issue
Block a user