mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: infer from thrown exceptions in lambda body
(cherry picked from commit 04056c01aa1eef1239ac88d48baec7ff109ef0df)
This commit is contained in:
+3
-1
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiMethodReferenceExpressionImpl;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.Function;
|
||||
@@ -96,7 +97,8 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
|
||||
|
||||
final List<PsiType> thrownTypes = new ArrayList<PsiType>();
|
||||
if (myExpression instanceof PsiLambdaExpression) {
|
||||
//todo
|
||||
PsiElement body = ((PsiLambdaExpression)myExpression).getBody();
|
||||
thrownTypes.addAll(ExceptionUtil.getUnhandledExceptions(body));
|
||||
} else {
|
||||
final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).resolve();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
class Test {
|
||||
interface I<E extends Throwable> {
|
||||
void foo() throws E;
|
||||
}
|
||||
static class Ex extends Exception {}
|
||||
|
||||
<E extends Throwable> void bar(I<E> s) throws E {
|
||||
s.foo();
|
||||
}
|
||||
|
||||
void baz(I<Ex> s) throws Ex {
|
||||
bar(() -> {
|
||||
try {
|
||||
s.foo();
|
||||
} catch (Throwable t) {
|
||||
throw t;
|
||||
}
|
||||
});
|
||||
bar(() -> s.foo());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -20,8 +20,8 @@ class Test {
|
||||
|
||||
|
||||
|
||||
foo1(()->{ <error descr="Unhandled exception: java.lang.ClassNotFoundException">throw new ClassNotFoundException();</error> });
|
||||
foo1(()->{ <error descr="Unhandled exception: java.lang.Exception">throw new Exception();</error> });
|
||||
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo1(()->{ throw new ClassNotFoundException(); });</error>
|
||||
<error descr="Unhandled exception: java.lang.Exception">foo1(()->{ throw new Exception(); });</error>
|
||||
|
||||
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo1(this::m2);</error>
|
||||
<error descr="Unhandled exception: java.lang.Exception">foo1(this::m3);</error>
|
||||
|
||||
+4
@@ -41,6 +41,10 @@ public class ExceptionVariablesInferenceTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLambdaBodyUncoutExceptionsForOuterCallInference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user