mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Add exception to method signature fix made aware of try-with-resources
This commit is contained in:
@@ -314,6 +314,9 @@ public class ExceptionUtil {
|
||||
PsiClassType exception = getUnhandledException(throwStatement, null);
|
||||
if (exception != null) return Collections.singletonList(exception);
|
||||
}
|
||||
else if (element instanceof PsiResourceVariable) {
|
||||
return getUnhandledCloserExceptions((PsiResourceVariable)element, null);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+2
@@ -30,6 +30,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -175,6 +176,7 @@ public class AddExceptionToThrowsFix extends BaseIntentionAction {
|
||||
return QuickFixBundle.message("add.exception.to.throws.family");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiElement findElement(PsiElement element, PsiMethod topElement) {
|
||||
if (element == null) return null;
|
||||
List<PsiClassType> unhandledExceptions = ExceptionUtil.getUnhandledExceptions(element);
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Add Exception(s) to Method Signature" "true"
|
||||
class C {
|
||||
static class E1 extends Exception { }
|
||||
|
||||
static class MyResource implements AutoCloseable {
|
||||
public void close() throws E1 { }
|
||||
}
|
||||
|
||||
void m() throws E1 {
|
||||
try (MyResource r = new MyResource()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Add Exception(s) to Method Signature" "true"
|
||||
class C {
|
||||
static class E1 extends Exception { }
|
||||
static class E2 extends Exception { }
|
||||
|
||||
static class MyResource implements AutoCloseable {
|
||||
public void doSomething() throws E1 { }
|
||||
public void close() throws E2 { }
|
||||
}
|
||||
|
||||
void m() throws E1, E2 {
|
||||
try (MyResource r = new MyResource()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Add Exception(s) to Method Signature" "true"
|
||||
class C {
|
||||
static class E1 extends Exception { }
|
||||
|
||||
static class MyResource implements AutoCloseable {
|
||||
public void close() throws E1 { }
|
||||
}
|
||||
|
||||
void m() {
|
||||
try (<caret>MyResource r = new MyResource()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Add Exception(s) to Method Signature" "true"
|
||||
class C {
|
||||
static class E1 extends Exception { }
|
||||
static class E2 extends Exception { }
|
||||
|
||||
static class MyResource implements AutoCloseable {
|
||||
public void doSomething() throws E1 { }
|
||||
public void close() throws E2 { }
|
||||
}
|
||||
|
||||
void m() throws E1 {
|
||||
try (<caret>MyResource r = new MyResource()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
public class AddExceptionToThrowsTest extends LightQuickFixTestCase {
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/addToThrows";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user