mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: propagate outer method to constraints, initial (IDEA-117803)
This commit is contained in:
+8
-3
@@ -87,11 +87,16 @@ public class InferenceSession {
|
||||
initBounds(typeParams);
|
||||
}
|
||||
|
||||
public void initExpressionConstraints(PsiParameter[] parameters, PsiExpression[] args, PsiElement parent) {
|
||||
final Pair<PsiMethod, PsiCallExpression> pair = getPair(parent);
|
||||
public void initExpressionConstraints(PsiParameter[] parameters, PsiExpression[] args, PsiElement parent, PsiMethod method) {
|
||||
if (method == null) {
|
||||
final Pair<PsiMethod, PsiCallExpression> pair = getPair(parent);
|
||||
if (pair != null) {
|
||||
method = pair.first;
|
||||
}
|
||||
}
|
||||
if (parameters.length > 0) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i] != null && (pair == null || isPertinentToApplicability(args[i], pair.first))) {
|
||||
if (args[i] != null && isPertinentToApplicability(args[i], method)) {
|
||||
PsiType parameterType = getParameterType(parameters, args, i, mySiteSubstitutor);
|
||||
myConstraints.add(new ExpressionCompatibilityConstraint(args[i], parameterType));
|
||||
}
|
||||
|
||||
+2
-4
@@ -18,8 +18,6 @@ package com.intellij.psi.impl.source.resolve.graphInference;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -41,7 +39,7 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper {
|
||||
@Nullable PsiElement parent,
|
||||
@NotNull ParameterTypeInferencePolicy policy) {
|
||||
final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager);
|
||||
inferenceSession.initExpressionConstraints(parameters, arguments, parent);
|
||||
inferenceSession.initExpressionConstraints(parameters, arguments, parent, null);
|
||||
return inferenceSession.infer(parameters, arguments, parent, policy).substitute(typeParameter);
|
||||
}
|
||||
|
||||
@@ -56,7 +54,7 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper {
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
if (typeParameters.length == 0) return partialSubstitutor;
|
||||
final InferenceSession inferenceSession = new InferenceSession(typeParameters, partialSubstitutor, myManager);
|
||||
inferenceSession.initExpressionConstraints(parameters, arguments, parent);
|
||||
inferenceSession.initExpressionConstraints(parameters, arguments, parent, null);
|
||||
return inferenceSession.infer(parameters, arguments, parent, policy);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
InferenceSession callSession = new InferenceSession(typeParams, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(), myExpression.getManager());
|
||||
final PsiExpression[] args = argumentList.getExpressions();
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
callSession.initExpressionConstraints(parameters, args, myExpression);
|
||||
callSession.initExpressionConstraints(parameters, args, myExpression, method);
|
||||
substitutor = callSession.infer(parameters, args, myExpression, LiftParameterTypeInferencePolicy.INSTANCE);
|
||||
}
|
||||
} else {
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
public class Tmp
|
||||
{
|
||||
interface BiFunction<T, U, R> {
|
||||
R apply(T t, U u);
|
||||
}
|
||||
|
||||
interface Sequence<T>
|
||||
{
|
||||
<R> Sequence<R> scan(R init, BiFunction<R, T, R> func);
|
||||
}
|
||||
|
||||
static <T> void foo(Sequence<T> sequence){}
|
||||
|
||||
void test(Sequence<String> strings) {
|
||||
foo(strings.scan(1, (i, s) -> 1));
|
||||
}
|
||||
}
|
||||
+10
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -90,6 +91,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOuterMethodPropagation() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
@@ -98,4 +103,9 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
doTestNewInference(BASE_PATH + "/" + getTestName(false) + ".java", warnings, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user