diff --git a/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java b/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java index 85eea92a8563..fec778f6e4e7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java +++ b/java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java @@ -198,9 +198,14 @@ public class PsiImplUtil { @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, final PsiElement lastParent) { + final ElementClassHint hint = processor.getHint(ElementClassHint.KEY); + if (hint != null && !hint.shouldProcess(ElementClassHint.DeclaractionKind.VARIABLE)) return true; + final List resources = resourceList.getResourceVariables(); - for (PsiResourceVariable resource : resources) { - if (!resource.equals(lastParent) && !processor.execute(resource, state)) return false; + @SuppressWarnings({"SuspiciousMethodCalls"}) + final int lastIdx = lastParent instanceof PsiResourceVariable ? resources.indexOf(lastParent) : resources.size(); + for (int i = 0; i < lastIdx; i++) { + if (!processor.execute(resources.get(i), state)) return false; } return true; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java index 63a5b7b9e619..02753b317b10 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java @@ -46,11 +46,11 @@ class C { } r = null; - try (MyResource r = new MyResource(); MyResource r = new MyResource()) { } + try (MyResource r = new MyResource(); MyResource r = new MyResource()) { } try (MyResource r1 = new MyResource(); MyResource r2 = r1) { } - /* todo: try (MyResource r1 = < error descr="Cannot resolve symbol 'r'">r2; MyResource r2 = r1) { }*/ + try (MyResource r1 = r2; MyResource r2 = r1) { } MyResource r = null; try (MyResource r = new MyResource()) { } @@ -64,4 +64,9 @@ class C { } }.run(); } + + void m4() throws Exception { + MyResource r; + try (MyResource r1 = r) { } + } } \ No newline at end of file