new inference: infer exceptions for inner lambda body calls (IDEA-134225)

This commit is contained in:
Anna Kozlova
2014-12-17 20:13:46 +01:00
parent ef013da019
commit 7343c62b7e
3 changed files with 29 additions and 2 deletions
@@ -465,12 +465,15 @@ public class ExceptionUtil {
final PsiLambdaExpression expression = PsiTreeUtil.getParentOfType(methodCall, PsiLambdaExpression.class);
final PsiSubstitutor substitutor;
if (expression != null) {
substitutor = ourThrowsGuard.doPreventingRecursion(expression, false, new Computable<PsiSubstitutor>() {
final PsiElement parent = methodCall.getParent();
final boolean callInReturnStatement = parent == expression ||
parent instanceof PsiReturnStatement && PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class, true, PsiMethod.class) == expression;
substitutor = callInReturnStatement ? ourThrowsGuard.doPreventingRecursion(expression, false, new Computable<PsiSubstitutor>() {
@Override
public PsiSubstitutor compute() {
return result.getSubstitutor();
}
});
}) : result.getSubstitutor();
} else {
substitutor = result.getSubstitutor();
}
@@ -0,0 +1,20 @@
import java.io.IOException;
import java.util.Optional;
class Test {
interface Extractor<T> {
T extractData() throws IOException;
}
public static <T> T query(Extractor<T> rse) {
return null;
}
static {
final Optional<String> query = query(() -> {
final String type = Optional.<String>empty().orElseThrow(null);
return null;
});
}
}
@@ -140,6 +140,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testCheckedExceptionsConstraintsSubstitutionsDeepInBody() throws Exception {
doTest();
}
public void testIDEA130129() throws Exception {
doTest();
}