mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-116508 ("Local variable or parameter can be final" inspection use generates uncompilable code not extracting a really finalizable variable)
This commit is contained in:
+10
@@ -231,6 +231,16 @@ public class LocalCanBeFinal extends BaseJavaBatchLocalInspectionTool {
|
||||
if (shouldBeIgnored(variable)) {
|
||||
iterator.remove();
|
||||
}
|
||||
final PsiElement parent = variable.getParent();
|
||||
if (!(parent instanceof PsiDeclarationStatement)) {
|
||||
continue;
|
||||
}
|
||||
final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)parent;
|
||||
final PsiElement[] elements = declarationStatement.getDeclaredElements();
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
if (elements.length > 1 && grandParent instanceof PsiForStatement) {
|
||||
iterator.remove(); // do not report when more than 1 variable declared in for loop
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiVariable writtenVariable : writtenVariables) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class For {
|
||||
void f(List<String> list) {
|
||||
for (Iterator<String> it = list.iterator(); it.hasNext();) { // 'it' can be final but not reported
|
||||
for (Iterator<String> it = list.iterator(); it.hasNext();) {
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {}
|
||||
for (int i = 0, length = 10; i < length; i++) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user