mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
forbid references on final fields from another ones (IDEA-100237)
This commit is contained in:
@@ -276,10 +276,10 @@ public class HighlightControlFlowUtil {
|
||||
&& HighlightUtil.findEnclosingFieldInitializer(expression) == null) {
|
||||
return null;
|
||||
}
|
||||
// access to final fields from inner classes always allowed
|
||||
if (inInnerClass(expression, ((PsiField)variable).getContainingClass(),containingFile)) return null;
|
||||
if (topBlock == null) return null;
|
||||
final PsiElement parent = topBlock.getParent();
|
||||
// access to final fields from inner classes always allowed
|
||||
if ((parent instanceof PsiMethod || parent instanceof PsiClassInitializer) && inInnerClass(expression, ((PsiField)variable).getContainingClass(),containingFile)) return null;
|
||||
final PsiCodeBlock block;
|
||||
final PsiClass aClass;
|
||||
if (parent instanceof PsiMethod) {
|
||||
@@ -317,7 +317,7 @@ public class HighlightControlFlowUtil {
|
||||
if (aClass == null || isFieldInitializedInOtherFieldInitializer(aClass, field, field.hasModifierProperty(PsiModifier.STATIC))) {
|
||||
return null;
|
||||
}
|
||||
final PsiField anotherField = PsiTreeUtil.getParentOfType(expression, PsiField.class);
|
||||
final PsiField anotherField = PsiTreeUtil.getTopmostParentOfType(expression, PsiField.class);
|
||||
if (anotherField != null && anotherField.getContainingClass() == aClass) {
|
||||
startOffset = 0;
|
||||
}
|
||||
|
||||
@@ -227,4 +227,16 @@ class Y {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class IDEA100237 {
|
||||
static class Foo {
|
||||
final int bar;
|
||||
|
||||
Foo() {
|
||||
bar = 1;
|
||||
}
|
||||
|
||||
final Object baz = new Object() {
|
||||
final int qux = <error descr="Variable 'bar' might not have been initialized">bar</error>.hashCode() + 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user