FinalUtils#canBeFinal: field assignments are checked within top-level class

Fixes IDEA-187493 False "Field may be final" inspection
This commit is contained in:
Tagir Valeev
2018-03-12 10:18:10 +07:00
parent 552f6fd49e
commit 7ecb32ce2b
2 changed files with 13 additions and 1 deletions
@@ -41,7 +41,7 @@ public class FinalUtils {
return false;
}
PsiElement scope = variable instanceof PsiField
? ((PsiField)variable).getContainingClass()
? PsiUtil.getTopLevelClass(variable)
: PsiUtil.getVariableCodeBlock(variable, null);
if (scope == null) return false;
Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<>();
@@ -1071,4 +1071,16 @@ class T74 {
x = 2;
}
int y = x = 3;
}
// IDEA-187493
class T75 {
void foo() {
new Inner().innerField = 1;
}
private static class Inner {
private int innerField;
private Inner() {innerField = 0;}
}
}