mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
exceptions collection: don't visit anonymous class body (IDEA-198967)
simple visit of expression list doesn't work as walking visitor starts to go down when it starts an element and element has no children
This commit is contained in:
@@ -65,14 +65,13 @@ public class ExceptionUtil {
|
||||
@NotNull
|
||||
public static List<PsiClassType> getThrownExceptions(@NotNull PsiElement element) {
|
||||
List<PsiClassType> result = new ArrayList<>();
|
||||
element.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
class Visitor extends JavaRecursiveElementWalkingVisitor {
|
||||
@Override
|
||||
public void visitAnonymousClass(PsiAnonymousClass aClass) {
|
||||
final PsiExpressionList argumentList = aClass.getArgumentList();
|
||||
if (argumentList != null){
|
||||
super.visitExpressionList(argumentList);
|
||||
if (argumentList != null && !argumentList.isEmpty()) {
|
||||
argumentList.accept(new Visitor());
|
||||
}
|
||||
super.visitAnonymousClass(aClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,7 +127,8 @@ public class ExceptionUtil {
|
||||
addExceptions(result, getTryExceptions(statement));
|
||||
// do not call super: try exception goes into try body recursively
|
||||
}
|
||||
});
|
||||
}
|
||||
element.accept(new Visitor());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
class MyTest {
|
||||
public static void main() {
|
||||
try {
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
};
|
||||
|
||||
new Foo("") {
|
||||
@Override
|
||||
public Object call() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class Foo implements Callable {
|
||||
protected Foo(Object o) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -13,6 +13,10 @@ class UnhandledExceptionsHighlightingTest : LightDaemonAnalyzerTestCase() {
|
||||
doTest(false)
|
||||
}
|
||||
|
||||
fun testIgnoreExceptionThrownInAnonymous() {
|
||||
doTest(false)
|
||||
}
|
||||
|
||||
private fun doTest(warnings: Boolean) {
|
||||
LanguageLevelProjectExtension.getInstance(getJavaFacade().project).languageLevel = LanguageLevel.JDK_1_8
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), testRootDisposable)
|
||||
|
||||
Reference in New Issue
Block a user