mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
final field initialization: class initializers (IDEA-130312)
This commit is contained in:
+4
-3
@@ -321,15 +321,16 @@ public class HighlightControlFlowUtil {
|
||||
return null;
|
||||
}
|
||||
final PsiField anotherField = PsiTreeUtil.getTopmostParentOfType(expression, PsiField.class);
|
||||
int offset = startOffset;
|
||||
if (anotherField != null && anotherField.getContainingClass() == aClass && !field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
startOffset = 0;
|
||||
offset = 0;
|
||||
}
|
||||
block = null;
|
||||
// initializers will be checked later
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
for (PsiMethod constructor : constructors) {
|
||||
// variable must be initialized before its usage
|
||||
if (startOffset < constructor.getTextRange().getStartOffset()) continue;
|
||||
if (offset < constructor.getTextRange().getStartOffset()) continue;
|
||||
PsiCodeBlock body = constructor.getBody();
|
||||
if (body != null && variableDefinitelyAssignedIn(variable, body)) {
|
||||
return null;
|
||||
@@ -339,7 +340,7 @@ public class HighlightControlFlowUtil {
|
||||
for (int j = 0; redirectedConstructors != null && j < redirectedConstructors.size(); j++) {
|
||||
PsiMethod redirectedConstructor = redirectedConstructors.get(j);
|
||||
// variable must be initialized before its usage
|
||||
if (startOffset < redirectedConstructor.getTextRange().getStartOffset()) continue;
|
||||
if (offset < redirectedConstructor.getTextRange().getStartOffset()) continue;
|
||||
PsiCodeBlock redirBody = redirectedConstructor.getBody();
|
||||
if (redirBody != null
|
||||
&& variableDefinitelyAssignedIn(variable, redirBody)) {
|
||||
|
||||
+17
@@ -259,4 +259,21 @@ class StaticInitializerUsedInAnotherStaticField {
|
||||
}
|
||||
|
||||
private static final int ourEnumerationCacheConstant = ENUMERATION_CACHE_SIZE;
|
||||
}
|
||||
|
||||
class InitializedInClassInitializerUsedInTheFollowingFieldInitializer {
|
||||
private final int i;
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
private int j = i;
|
||||
|
||||
private final int k;
|
||||
|
||||
private int l = <error descr="Variable 'k' might not have been initialized">k</error>;
|
||||
|
||||
{
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user