mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
method ref: don't check method reference qualifier against functional interface (IDEA-141343)
This commit is contained in:
@@ -336,7 +336,8 @@ public class ExceptionUtil {
|
||||
final JavaResolveResult resolveResult = methodReferenceExpression.advancedResolve(false);
|
||||
final PsiElement resolve = resolveResult.getElement();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
return getUnhandledExceptions((PsiMethod)resolve, methodReferenceExpression, topElement, resolveResult.getSubstitutor());
|
||||
final PsiElement referenceNameElement = methodReferenceExpression.getReferenceNameElement();
|
||||
return getUnhandledExceptions((PsiMethod)resolve, referenceNameElement, topElement, resolveResult.getSubstitutor());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -667,12 +668,9 @@ public class ExceptionUtil {
|
||||
// like in void f() throws XXX { new AA(methodThrowingXXX()) { ... }; }
|
||||
return parent instanceof PsiAnonymousClass && isHandled(parent, exceptionType, topElement);
|
||||
}
|
||||
else if (parent instanceof PsiLambdaExpression) {
|
||||
final PsiType interfaceType = ((PsiLambdaExpression)parent).getFunctionalInterfaceType();
|
||||
return isDeclaredBySAMMethod(exceptionType, interfaceType);
|
||||
}
|
||||
else if (element instanceof PsiMethodReferenceExpression) {
|
||||
final PsiType interfaceType = ((PsiMethodReferenceExpression)element).getFunctionalInterfaceType();
|
||||
else if (parent instanceof PsiLambdaExpression ||
|
||||
parent instanceof PsiMethodReferenceExpression && element == ((PsiMethodReferenceExpression)parent).getReferenceNameElement()) {
|
||||
final PsiType interfaceType = ((PsiFunctionalExpression)parent).getFunctionalInterfaceType();
|
||||
return isDeclaredBySAMMethod(exceptionType, interfaceType);
|
||||
}
|
||||
else if (parent instanceof PsiClassInitializer) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class E1 extends Exception {}
|
||||
class E2 extends Exception {}
|
||||
class Test {
|
||||
interface I {
|
||||
void m() throws E1;
|
||||
}
|
||||
|
||||
void a(I i) {}
|
||||
Test b() throws E2 {return this;}
|
||||
void c() throws E1 {}
|
||||
void e() throws E1, E2 {}
|
||||
|
||||
void d() throws E2 {
|
||||
a(b()::c);
|
||||
a(<error descr="Unhandled exception: E2">this::e</error>);
|
||||
}
|
||||
}
|
||||
@@ -410,6 +410,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUnhandledExceptionsInQualifier() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user