mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
new inference: checked exceptions inference, ensure throws bound are marked as such
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user