From fb7c097c9087f98554bc9ca1452b2371d29fd231 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 10 Mar 2014 20:52:38 +0100 Subject: [PATCH] IDEA-121834 (generic exception substituted) --- .../intellij/codeInsight/ExceptionUtil.java | 16 +++++----- .../advHighlighting7/TryWithResources.java | 29 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java index d9ec369b4199..ada64c0d7452 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/ExceptionUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -487,15 +487,17 @@ public class ExceptionUtil { } @NotNull - public static List getCloserExceptions(@NotNull final PsiResourceVariable resource) { - final PsiMethod method = PsiUtil.getResourceCloserMethod(resource); - return method != null ? getExceptionsByMethod(method, PsiSubstitutor.EMPTY) : Collections.emptyList(); + public static List getCloserExceptions(@NotNull PsiResourceVariable resource) { + PsiMethod method = PsiUtil.getResourceCloserMethod(resource); + PsiSubstitutor substitutor = PsiUtil.resolveGenericsClassInType(resource.getType()).getSubstitutor(); + return method != null ? getExceptionsByMethod(method, substitutor) : Collections.emptyList(); } @NotNull - public static List getUnhandledCloserExceptions(@NotNull final PsiResourceVariable resource, @Nullable final PsiElement topElement) { - final PsiMethod method = PsiUtil.getResourceCloserMethod(resource); - return method != null ? getUnhandledExceptions(method, resource, topElement, PsiSubstitutor.EMPTY) : Collections.emptyList(); + public static List getUnhandledCloserExceptions(@NotNull PsiResourceVariable resource, @Nullable PsiElement topElement) { + PsiMethod method = PsiUtil.getResourceCloserMethod(resource); + PsiSubstitutor substitutor = PsiUtil.resolveGenericsClassInType(resource.getType()).getSubstitutor(); + return method != null ? getUnhandledExceptions(method, resource, topElement, substitutor) : Collections.emptyList(); } @NotNull diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java index b21f42ccaf4c..289dc6167f68 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/TryWithResources.java @@ -1,18 +1,3 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ class C { static class E extends Exception { } static class E1 extends E { } @@ -25,7 +10,15 @@ class C { @Override public void close() throws E3 { } } - static interface I extends AutoCloseable { } + interface I extends AutoCloseable { } + + interface Gen extends AutoCloseable { + @Override void close() throws E; + + class Impl implements Gen { + @Override public void close() throws E2 { } + } + } void m1() { try (MyResource r = new MyResource()) { r.doSomething(); } @@ -90,4 +83,8 @@ class C { MyResource r; try (MyResource r1 = r) { } } + + void m5() { + try (Gen gen = new Gen.Impl()) { } + } } \ No newline at end of file