mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] process inferred type parameters in add to throws/catch sections (IDEA-259729)
GitOrigin-RevId: aea7cd3f30f891d752116fb619d6215d3dc3431b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bc51c73b75
commit
2ead949be8
+9
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.generation.surroundWith;
|
||||
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
@@ -62,7 +48,7 @@ public class JavaWithTryCatchSurrounder extends JavaStatementsSurrounder {
|
||||
|
||||
@NonNls StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("try{\n}");
|
||||
for (PsiClassType exception : exceptions) {
|
||||
for (PsiClassType ignored : exceptions) {
|
||||
buffer.append("catch(Exception e){\n}");
|
||||
}
|
||||
if (myGenerateFinally) {
|
||||
@@ -82,6 +68,13 @@ public class JavaWithTryCatchSurrounder extends JavaStatementsSurrounder {
|
||||
|
||||
for (int i = 0; i < exceptions.size(); i++) {
|
||||
PsiClassType exception = exceptions.get(i);
|
||||
PsiClass target = exception.resolve();
|
||||
if (target instanceof PsiTypeParameter) {
|
||||
PsiClassType[] extendsListTypes = target.getExtendsListTypes();
|
||||
if (extendsListTypes.length > 0) {
|
||||
exception = extendsListTypes[0];
|
||||
}
|
||||
}
|
||||
String name = new VariableNameGenerator(tryBlock, VariableKind.PARAMETER).byName("e", "ex", "exc").byType(exception).generate(false);
|
||||
PsiCatchSection catchSection;
|
||||
try {
|
||||
|
||||
@@ -165,7 +165,7 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
}
|
||||
|
||||
public static void addException(@NotNull PsiMethod method, @NotNull PsiClass exceptionClass) throws IncorrectOperationException {
|
||||
addException(method, exceptionClass, exceptionClass.getQualifiedName());
|
||||
addException(method, exceptionClass, exceptionClass instanceof PsiTypeParameter ? exceptionClass.getName() : exceptionClass.getQualifiedName());
|
||||
}
|
||||
|
||||
private static void addException(@NotNull PsiMethod method,
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Surround with try/catch" "true"
|
||||
class Test {
|
||||
|
||||
interface I<E extends Exception> {
|
||||
void call() throws E;
|
||||
}
|
||||
|
||||
public static <E extends Exception> void method(I<E> i) {
|
||||
try {
|
||||
i.call();
|
||||
} catch (Exception e) {
|
||||
<selection><caret>throw new RuntimeException(e);</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Surround with try/catch" "true"
|
||||
class Test {
|
||||
|
||||
interface I<E extends Exception> {
|
||||
void call() throws E;
|
||||
}
|
||||
|
||||
public static <E extends Exception> void method(I<E> i) {
|
||||
i.ca<caret>ll();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Add exception to method signature" "true"
|
||||
class Test {
|
||||
|
||||
interface I<E extends Exception> {
|
||||
void call() throws E;
|
||||
}
|
||||
|
||||
public static <E extends Exception> void method(I<E> i) throws E {
|
||||
i.call();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Add exception to method signature" "true"
|
||||
class Test {
|
||||
|
||||
interface I<E extends Exception> {
|
||||
void call() throws E;
|
||||
}
|
||||
|
||||
public static <E extends Exception> void method(I<E> i) {
|
||||
i.ca<caret>ll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user