mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
new inference: temp solution for inexact method refs
(cherry picked from commit e94cddb696cbcb3e3a8d8e4f62f8903b4bd71403)
This commit is contained in:
@@ -100,10 +100,22 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
|
||||
PsiElement body = ((PsiLambdaExpression)myExpression).getBody();
|
||||
thrownTypes.addAll(ExceptionUtil.getUnhandledExceptions(body));
|
||||
} else {
|
||||
final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).resolve();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
for (PsiClassType type : ((PsiMethod)resolve).getThrowsList().getReferencedTypes()) {
|
||||
if (!ExceptionUtil.isUncheckedException(type)) {
|
||||
if (((PsiMethodReferenceExpression)myExpression).isExact()) {
|
||||
final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).resolve();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
for (PsiClassType type : ((PsiMethod)resolve).getThrowsList().getReferencedTypes()) {
|
||||
if (!ExceptionUtil.isUncheckedException(type)) {
|
||||
thrownTypes.add(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiSubstitutor psiSubstitutor =
|
||||
PsiMethodReferenceUtil.getQualifierResolveResult((PsiMethodReferenceExpression)myExpression).getSubstitutor();
|
||||
for (PsiType type : interfaceMethod.getThrowsList().getReferencedTypes()) {
|
||||
type = psiSubstitutor.substitute(type);
|
||||
if (type instanceof PsiClassType && !ExceptionUtil.isUncheckedException((PsiClassType)type)) {
|
||||
thrownTypes.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
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(s::foo);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,11 @@ public class ExceptionVariablesInferenceTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLambdaBodyUncoutExceptionsForOuterCallInference() throws Exception {
|
||||
public void testLambdaBodyUncaughtExceptionsForOuterCallInference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMethodRefUncaughtExceptionsForOuterCallInference() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user