mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-92335 (DFA in resource variable initializer)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -754,8 +754,13 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
|
||||
@Override public void visitTryStatement(PsiTryStatement statement) {
|
||||
startElement(statement);
|
||||
PsiCodeBlock finallyBlock = statement.getFinallyBlock();
|
||||
|
||||
PsiResourceList resourceList = statement.getResourceList();
|
||||
if (resourceList != null) {
|
||||
resourceList.accept(this);
|
||||
}
|
||||
|
||||
PsiCodeBlock finallyBlock = statement.getFinallyBlock();
|
||||
if (finallyBlock != null) {
|
||||
myCatchStack.push(new CatchDescriptor(finallyBlock));
|
||||
}
|
||||
@@ -817,6 +822,21 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (catchBlock != null) catchBlock.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitResourceList(PsiResourceList resourceList) {
|
||||
startElement(resourceList);
|
||||
|
||||
List<PsiResourceVariable> variables = resourceList.getResourceVariables();
|
||||
for (PsiResourceVariable variable : variables) {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null) {
|
||||
initializeVariable(variable, initializer);
|
||||
}
|
||||
}
|
||||
|
||||
finishElement(resourceList);
|
||||
}
|
||||
|
||||
@Override public void visitWhileStatement(PsiWhileStatement statement) {
|
||||
startElement(statement);
|
||||
|
||||
|
||||
+17
-2
@@ -1,5 +1,3 @@
|
||||
import java.lang.Exception;
|
||||
|
||||
class C {
|
||||
static class MyResource implements AutoCloseable {
|
||||
@Override public void close() { }
|
||||
@@ -25,4 +23,21 @@ class C {
|
||||
System.out.println(r);
|
||||
}
|
||||
}
|
||||
|
||||
interface MyResourceProvider {
|
||||
MyResource getResource();
|
||||
}
|
||||
|
||||
void m3() throws Exception {
|
||||
MyResourceProvider provider = null;
|
||||
try (MyResource r = <warning descr="Method invocation 'provider.getResource()' may produce 'java.lang.NullPointerException'">provider.getResource()</warning>) {
|
||||
System.out.println(r);
|
||||
}
|
||||
}
|
||||
|
||||
void m4() {
|
||||
try (MyResource r = null) {
|
||||
System.out.println(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.compiler.JavacQuirksInspection;
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.codeInspection.defUse.DefUseInspection;
|
||||
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
|
||||
@@ -146,7 +147,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testNumericLiterals() throws Exception { doTest(false, false); }
|
||||
public void testMultiCatch() throws Exception { doTest(false, false); }
|
||||
public void testTryWithResources() throws Exception { doTest(false, false); }
|
||||
public void testTryWithResourcesWarn() throws Exception { doTest(true, false, new DefUseInspection()); }
|
||||
public void testTryWithResourcesWarn() throws Exception { doTest(true, false, new DefUseInspection(), new DataFlowInspection()); }
|
||||
public void testSafeVarargsApplicability() throws Exception { doTest(true, false); }
|
||||
public void testUncheckedGenericsArrayCreation() throws Exception { doTest(true, false); }
|
||||
public void testPreciseRethrow() throws Exception { doTest(false, false); }
|
||||
|
||||
Reference in New Issue
Block a user