Highlight uninitialized resource variable

This commit is contained in:
Roman Shevchenko
2011-02-25 20:59:19 +01:00
parent a469762b6d
commit 70370a5456
2 changed files with 7 additions and 1 deletions
@@ -66,6 +66,8 @@ class C {
}
void m4() throws Exception {
try (MyResource r = <error descr="Variable 'r' might not have been initialized">r</error>) { }
MyResource r;
try (MyResource r1 = <error descr="Variable 'r' might not have been initialized">r</error>) { }
}
@@ -232,7 +232,7 @@ public final class PsiUtil extends PsiUtilBase {
}
/**
* @return codeblock topmost codeblock where variable makes sense
* @return topmost code block where variable makes sense
*/
@Nullable
public static PsiElement getVariableCodeBlock(PsiVariable variable, PsiElement context) {
@@ -249,6 +249,10 @@ public final class PsiUtil extends PsiUtilBase {
codeBlock = ((PsiMethod)declarationScope).getBody();
}
}
else if (variable instanceof PsiResourceVariable) {
final PsiElement resourceList = variable.getParent();
return resourceList != null ? resourceList.getParent() : null; // use try statement as topmost
}
else if (variable instanceof PsiLocalVariable && variable.getParent() instanceof PsiForStatement) {
return variable.getParent();
}