java 9: effectively final check fixed (IDEA-171152)

This commit is contained in:
Anna.Kozlova
2017-04-07 19:00:58 +02:00
parent 506175911b
commit 1d95e4ee02
2 changed files with 3 additions and 8 deletions
@@ -1798,13 +1798,7 @@ public class HighlightUtil extends HighlightUtilBase {
PsiModifierList modifierList = variable.getModifierList();
if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.FINAL)) return null;
PsiElement scope = null;
if (variable instanceof PsiParameter) scope = ((PsiParameter)variable).getDeclarationScope();
else if (variable instanceof PsiResourceVariable) scope = variable.getParent().getParent();
else if (variable instanceof PsiLocalVariable) scope = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class);
if (scope != null) {
if (HighlightControlFlowUtil.isEffectivelyFinal(variable, scope, null)) return null;
}
if (!(variable instanceof PsiField) && HighlightControlFlowUtil.isEffectivelyFinal(variable, resource, (PsiJavaCodeReferenceElement)expression)) return null;
}
String text = JavaErrorMessages.message("resource.variable.must.be.final");
@@ -13,7 +13,8 @@ class TryWithResources {
final AutoCloseable r1 = null;
AutoCloseable r2 = null;
AutoCloseable r3 = null;
try (r1; r2; <error descr="Variable used as a try-with-resources resource should be final or effectively final">r3</error>) { }
AutoCloseable r4; r4 = null;
try (r1; r2; r4; <error descr="Variable used as a try-with-resources resource should be final or effectively final">r3</error>) { }
r3 = null;
}