mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
disable add exception to catch/generalize catch inside functional interface inside try statement (IDEA-135171)
This commit is contained in:
+2
-2
@@ -171,8 +171,8 @@ public class AddExceptionToCatchFix extends BaseIntentionAction {
|
||||
if (element == null) return null;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
final PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiTryStatement.class, PsiMethod.class);
|
||||
if (parent == null || parent instanceof PsiMethod) return null;
|
||||
final PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiTryStatement.class, PsiMethod.class, PsiFunctionalExpression.class);
|
||||
if (parent == null || parent instanceof PsiMethod || parent instanceof PsiFunctionalExpression) return null;
|
||||
final PsiTryStatement statement = (PsiTryStatement) parent;
|
||||
|
||||
final PsiCodeBlock tryBlock = statement.getTryBlock();
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public class GeneralizeCatchFix implements IntentionAction {
|
||||
myTryStatement = (PsiTryStatement)element.getParent();
|
||||
break;
|
||||
}
|
||||
if (element instanceof PsiMethod || (element instanceof PsiClass && !(element instanceof PsiAnonymousClass))) break;
|
||||
if (element instanceof PsiMethod || element instanceof PsiFunctionalExpression || (element instanceof PsiClass && !(element instanceof PsiAnonymousClass))) break;
|
||||
element = element.getParent();
|
||||
}
|
||||
if (myTryStatement == null) return false;
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Add 'catch' clause(s)" "true"
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class C {
|
||||
static Object get() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
void method() {
|
||||
try {
|
||||
Supplier<Object> lambda1 = () -> {
|
||||
try {
|
||||
return C.get();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
} catch( Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Add 'catch' clause(s)" "false"
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class C {
|
||||
static Object get() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
void method() {
|
||||
try {
|
||||
Supplier<Object> lambda1 = () -> C.ge<caret>t();
|
||||
} catch( Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Add 'catch' clause(s)" "true"
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class C {
|
||||
static Object get() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
void method() {
|
||||
try {
|
||||
Supplier<Object> lambda1 = () -> {
|
||||
try {
|
||||
return C.ge<caret>t();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
} catch( Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Add 'catch' clause(s)" "false"
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class C {
|
||||
static Object get() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
void method() {
|
||||
try {
|
||||
Supplier<Object> lambda1 = C::g<caret>et;
|
||||
} catch( Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Generalize catch for 'java.lang.Exception' to 'java.lang.Exception'" "false"
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class C {
|
||||
static Object get() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
void method() {
|
||||
try {
|
||||
Supplier<Object> lambda1 = () -> C.ge<caret>t();
|
||||
} catch( Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Generalize catch for 'java.lang.Exception' to 'java.lang.Exception'" "false"
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class C {
|
||||
static Object get() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
void method() {
|
||||
try {
|
||||
Supplier<Object> lambda1 = C::g<caret>et;
|
||||
} catch( Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -1,5 +1,8 @@
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
|
||||
public class AddExceptionToCatchTest extends LightQuickFixParameterizedTestCase {
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
@@ -9,4 +12,9 @@ public class AddExceptionToCatchTest extends LightQuickFixParameterizedTestCase
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/addCatchBlock";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -1,5 +1,8 @@
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
|
||||
public class GeneralizeCatchTest extends LightQuickFixParameterizedTestCase {
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
@@ -9,4 +12,9 @@ public class GeneralizeCatchTest extends LightQuickFixParameterizedTestCase {
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/generalizeCatch";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user