new inference: checked exceptions inference, ensure throws bound are marked as such

This commit is contained in:
Anna Kozlova
2014-09-16 14:03:52 +04:00
parent 0261ad4164
commit 5e79028c99
5 changed files with 38 additions and 8 deletions

View File

@@ -121,6 +121,9 @@ public class InferenceSession {
method = currentProperties.getMethod();
}
}
if (method != null) {
initThrowsConstraints(method);
}
if (parameters.length > 0) {
for (int i = 0; i < args.length; i++) {
if (args[i] != null && isPertinentToApplicability(args[i], method)) {
@@ -131,6 +134,15 @@ public class InferenceSession {
}
}
public void initThrowsConstraints(PsiMethod method) {
for (PsiClassType thrownType : method.getThrowsList().getReferencedTypes()) {
final InferenceVariable variable = getInferenceVariable(substituteWithInferenceVariables(thrownType));
if (variable != null) {
variable.setThrownBound();
}
}
}
private static MethodCandidateInfo.CurrentCandidateProperties getCurrentProperties(PsiElement parent) {
if (parent instanceof PsiCallExpression) {
return MethodCandidateInfo.getCurrentMethod(((PsiCallExpression)parent).getArgumentList());
@@ -456,13 +468,6 @@ public class InferenceSession {
}
}
}
for (PsiClassType thrownType : method.getThrowsList().getReferencedTypes()) {
final InferenceVariable variable = getInferenceVariable(substituteWithInferenceVariables(thrownType));
if (variable != null) {
variable.setThrownBound();
}
}
}
public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType) {

View File

@@ -135,7 +135,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
for (PsiType type : method.getThrowsList().getReferencedTypes()) {
type = psiSubstitutor.substitute(type);
if (type instanceof PsiClassType && !ExceptionUtil.isUncheckedException((PsiClassType)type)) {
thrownTypes.add(type);
thrownTypes.add(substitutor.substitute(type));
}
}
}

View File

@@ -116,6 +116,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR
private PsiSubstitutor inferTypeArguments() {
if (interfaceMethod == null) return substitutor;
final InferenceSession session = new InferenceSession(method.getTypeParameters(), substitutor, reference.getManager(), reference);
session.initThrowsConstraints(method);
final PsiSubstitutor psiSubstitutor = session.collectApplicabilityConstraints(reference, this, functionalInterfaceType);
if (psiSubstitutor != null) {
return psiSubstitutor;

View File

@@ -0,0 +1,19 @@
import java.io.IOException;
class Test {
interface B<K, E extends Throwable> {
K l(K k) throws E;
}
<R> void bar(B<R, IOException> b) {}
<E extends Throwable, T> T baz(T l) throws E {
return null;
}
{
bar(l -> baz(l));
bar(this::baz);
}
}

View File

@@ -136,6 +136,11 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
@Bombed(month = Calendar.OCTOBER, day = 30)
public void testCheckedExceptionsConstraintsSubstitutions() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}