exception inference: don't check non-applicable methods (IDEA-178762)

This commit is contained in:
Anna Kozlova
2017-09-12 21:05:35 +03:00
parent 93b1084c31
commit b0ccbdebcf
3 changed files with 23 additions and 2 deletions
@@ -487,13 +487,15 @@ public class ExceptionUtil {
processor.getResults(), info -> {
PsiElement element1 = info.getElement();
if (info instanceof MethodCandidateInfo &&
element1 != method && //don't check self
MethodSignatureUtil.areSignaturesEqual(method, (PsiMethod)element1) &&
!MethodSignatureUtil.isSuperMethod((PsiMethod)element1, method)) {
!MethodSignatureUtil.isSuperMethod((PsiMethod)element1, method) &&
!(((MethodCandidateInfo)info).isToInferApplicability() && !((MethodCandidateInfo)info).isApplicable())) {
return Pair.create((PsiMethod)element1, ((MethodCandidateInfo)info).getSubstitutor(false));
}
return null;
});
if (candidates.size() > 1) {
if (!candidates.isEmpty()) {
GlobalSearchScope scope = methodCall.getResolveScope();
final List<PsiClassType> ex = collectSubstituted(substitutor, thrownExceptions, scope);
for (Pair<PsiMethod, PsiSubstitutor> pair : candidates) {
@@ -0,0 +1,18 @@
import java.io.IOException;
@FunctionalInterface
interface ThrowableRunnable<E extends Exception> {
void get() throws E;
static <E extends Exception> void m(ThrowableRunnable<E> supplier, Object... params) throws E {}
default void getContent() {
try {
m(() -> { throw new IOException(); });
} catch (IOException e) { }
}
}
@@ -162,6 +162,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testLambdaWithFormalTypeParameters() { doTest(); }
public void testIDEA174924() { doTest(); }
public void testVoidValueCompatibilityWithBreakInSwitch() { doTest(); }
public void testExceptionInferenceForVarargMethods() { doTest(); }
private void doTest() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());