mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java: propagate (completion) inference policy to nested sessions (IDEA-208607)
GitOrigin-RevId: 63b587a222e027c92ac3eebb1a5aeb79b669b17e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0c4037c12c
commit
3fa91b09d5
+7
-2
@@ -56,7 +56,7 @@ public class InferenceSession {
|
||||
private PsiSubstitutor myRestoreNameSubstitution = PsiSubstitutor.EMPTY;
|
||||
private MethodCandidateInfo myCurrentMethod;
|
||||
|
||||
public InferenceSession(InitialInferenceState initialState) {
|
||||
public InferenceSession(InitialInferenceState initialState, ParameterTypeInferencePolicy policy) {
|
||||
myContext = initialState.getContext();
|
||||
myManager = myContext.getManager();
|
||||
|
||||
@@ -69,7 +69,7 @@ public class InferenceSession {
|
||||
}
|
||||
myInferenceSessionContainer = initialState.getInferenceSessionContainer();
|
||||
myErased = initialState.isErased();
|
||||
myPolicy = DefaultParameterTypeInferencePolicy.INSTANCE;
|
||||
myPolicy = policy;
|
||||
}
|
||||
|
||||
public InferenceSession(PsiTypeParameter[] typeParams,
|
||||
@@ -126,6 +126,11 @@ public class InferenceSession {
|
||||
myCurrentMethod = currentMethod;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ParameterTypeInferencePolicy getInferencePolicy() {
|
||||
return myPolicy;
|
||||
}
|
||||
|
||||
public static PsiType createTypeParameterTypeWithUpperBound(@NotNull PsiType upperBound, @NotNull PsiElement place) {
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(place.getProject());
|
||||
|
||||
|
||||
+2
-2
@@ -128,7 +128,7 @@ public class InferenceSessionContainer {
|
||||
final CompoundInitialState compoundInitialState = createState(parentSession);
|
||||
InitialInferenceState initialInferenceState = compoundInitialState.getInitialState(parent);
|
||||
if (initialInferenceState != null) {
|
||||
final InferenceSession childSession = new InferenceSession(initialInferenceState);
|
||||
InferenceSession childSession = new InferenceSession(initialInferenceState, parentSession.getInferencePolicy());
|
||||
return childSession.collectAdditionalAndInfer(parameters, arguments, currentMethod, compoundInitialState.getInitialSubstitutor());
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class InferenceSessionContainer {
|
||||
|
||||
//one of the grand parents were found in the top inference session
|
||||
//start from it as it is the top level call
|
||||
final InferenceSession sessionInsideLambda = new InferenceSession(initialInferenceState);
|
||||
InferenceSession sessionInsideLambda = new InferenceSession(initialInferenceState, parentSession.getInferencePolicy());
|
||||
sessionInsideLambda.collectAdditionalAndInfer(methodParameters, argumentList.getExpressions(), ((MethodCandidateInfo)result), compoundInitialState.getInitialSubstitutor());
|
||||
return inferNested(parameters, arguments, parent, currentMethod, sessionInsideLambda);
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper {
|
||||
);
|
||||
}
|
||||
else {
|
||||
final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager, null);
|
||||
InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager, null, policy);
|
||||
inferenceSession.initExpressionConstraints(parameters, arguments, null, false);
|
||||
substitutor = inferenceSession.infer();
|
||||
}
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
|
||||
if (typeParams != null) {
|
||||
PsiSubstitutor siteSubstitutor = InferenceSession.chooseSiteSubstitutor(currentMethod, resolveResult, method);
|
||||
final InferenceSession callSession = new InferenceSession(typeParams, siteSubstitutor, expression.getManager(), expression);
|
||||
InferenceSession callSession = new InferenceSession(typeParams, siteSubstitutor, expression.getManager(), expression, session.getInferencePolicy());
|
||||
callSession.propagateVariables(session);
|
||||
if (method != null) {
|
||||
final PsiExpression[] args = argumentList.getExpressions();
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import java.util.stream.*;
|
||||
|
||||
class X {
|
||||
|
||||
{
|
||||
Stream<String> stringStream = Stream.of("1", "2", "2");
|
||||
stringStream.collect(Collectors.groupingBy(s -> s, Collectors.counting())<caret>);
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import java.util.stream.*;
|
||||
|
||||
class X {
|
||||
|
||||
{
|
||||
Stream<String> stringStream = Stream.of("1", "2", "2");
|
||||
stringStream.collect(Collectors.groupingBy(s -> s, Collectors.count<caret>));
|
||||
}
|
||||
|
||||
}
|
||||
+2
@@ -293,5 +293,7 @@ public void testConvertToObjectStream() {
|
||||
myFixture.assertPreferredCompletionItems(0, "String.class");
|
||||
}
|
||||
|
||||
public void testNestedCollectorsCounting() { doTest(false); }
|
||||
|
||||
public void testFilterInaccessibleConstructors() { doAntiTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user