mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
new inference: temp solution to exclude inference results from nested call of the same method on the outer level
This commit is contained in:
@@ -335,9 +335,13 @@ public class InferenceSession {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initBounds(PsiTypeParameter... typeParameters) {
|
||||
public boolean initBounds(PsiTypeParameter... typeParameters) {
|
||||
boolean sameMethodCall = false;
|
||||
for (PsiTypeParameter parameter : typeParameters) {
|
||||
if (myInferenceVariables.containsKey(parameter)) continue;
|
||||
if (myInferenceVariables.containsKey(parameter)) {
|
||||
sameMethodCall = true;
|
||||
continue;
|
||||
}
|
||||
InferenceVariable variable = new InferenceVariable(parameter);
|
||||
boolean added = false;
|
||||
final PsiClassType[] extendsListTypes = parameter.getExtendsListTypes();
|
||||
@@ -354,6 +358,7 @@ public class InferenceSession {
|
||||
}
|
||||
myInferenceVariables.put(parameter, variable);
|
||||
}
|
||||
return sameMethodCall;
|
||||
}
|
||||
|
||||
public void addCapturedVariable(PsiTypeParameter param) {
|
||||
|
||||
@@ -111,7 +111,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
|
||||
final PsiSubstitutor psiSubstitutor = qualifierResolveResult.getSubstitutor();
|
||||
final PsiMethod method;
|
||||
if (((PsiMethodReferenceExpression)myExpression).isExact()) {
|
||||
final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).resolve();
|
||||
final PsiElement resolve = ((PsiMethodReferenceExpression)myExpression).getPotentiallyApplicableMember();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
method = (PsiMethod)resolve;
|
||||
} else {
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -100,7 +101,8 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
|
||||
if (typeParams != null) {
|
||||
|
||||
session.initBounds(typeParams);
|
||||
final HashSet<PsiTypeParameter> oldBounds = new HashSet<>(session.getTypeParams());
|
||||
final boolean sameMethodCall = session.initBounds(typeParams);
|
||||
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
|
||||
final HashSet<InferenceVariable> variables = new HashSet<InferenceVariable>();
|
||||
session.collectDependencies(returnType, variables);
|
||||
@@ -129,7 +131,16 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
}
|
||||
callSession.registerConstraints(returnType, myT);
|
||||
if (callSession.repeatInferencePhases(true)) {
|
||||
session.liftBounds(callSession.getInferenceVariables());
|
||||
final Collection<InferenceVariable> inferenceVariables = callSession.getInferenceVariables();
|
||||
if (sameMethodCall) {
|
||||
for (Iterator<InferenceVariable> iterator = inferenceVariables.iterator(); iterator.hasNext(); ) {
|
||||
InferenceVariable variable = iterator.next();
|
||||
if (oldBounds.contains(variable.getParameter())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
session.liftBounds(inferenceVariables);
|
||||
}
|
||||
final PsiType capturedReturnType = myExpression instanceof PsiMethodCallExpression
|
||||
? PsiMethodCallExpressionImpl.captureReturnType((PsiMethodCallExpression)myExpression, method, returnType, substitutor)
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
import java.util.List;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
abstract class Main2 {
|
||||
void address(Foo sa) {
|
||||
String ds = foobar(foobar(sa, Foo::getBar), Bar ::getName);
|
||||
Function<Foo, Bar> f = null;
|
||||
String ds1 = foobar(foobar(sa, f), null);
|
||||
}
|
||||
|
||||
abstract <T, V> V foobar(T t, Function<T, V> mapper);
|
||||
|
||||
class Foo {
|
||||
Bar getBar() {
|
||||
return new Bar();
|
||||
}
|
||||
}
|
||||
|
||||
class Bar {
|
||||
String getName(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Main0 {
|
||||
<T> List<T> foo(T t){
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user