mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
method refs: attempt to use parent to infer constructor type (IDEA-98846)
This commit is contained in:
@@ -221,7 +221,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
if (nullPassed && currentSubstitution == null) return RAW_INFERENCE;
|
||||
} else if (argumentType instanceof PsiMethodReferenceType) {
|
||||
final PsiMethodReferenceExpression referenceExpression = ((PsiMethodReferenceType)argumentType).getExpression();
|
||||
currentSubstitution = inferConstraintFromFunctionalInterfaceMethod(typeParameter, referenceExpression, partialSubstitutor.substitute(parameterType));
|
||||
currentSubstitution = inferConstraintFromFunctionalInterfaceMethod(typeParameter, referenceExpression, partialSubstitutor.substitute(parameterType), partialSubstitutor, policy);
|
||||
}
|
||||
else {
|
||||
currentSubstitution = getSubstitutionForTypeParameterConstraint(typeParameter, parameterType,
|
||||
@@ -608,7 +608,9 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
@Nullable
|
||||
private static Pair<PsiType, ConstraintType> inferConstraintFromFunctionalInterfaceMethod(final PsiTypeParameter typeParam,
|
||||
final PsiMethodReferenceExpression methodReferenceExpression,
|
||||
final PsiType functionalInterfaceType) {
|
||||
final PsiType functionalInterfaceType,
|
||||
final PsiSubstitutor partialSubstitutor,
|
||||
final ParameterTypeInferencePolicy policy) {
|
||||
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
|
||||
final PsiMethod functionalInterfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
|
||||
if (functionalInterfaceMethod != null) {
|
||||
@@ -669,7 +671,14 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
} else {
|
||||
argType = methReferenceResolveResult.getSubstitutor().substitute(subst.substitute(method.getReturnType()));
|
||||
}
|
||||
return getSubstitutionForTypeParameterConstraint(typeParam, functionalInterfaceReturnType, argType, true, PsiUtil.getLanguageLevel(functionalInterfaceMethod));
|
||||
final Pair<PsiType, ConstraintType> typeParameterConstraint =
|
||||
getSubstitutionForTypeParameterConstraint(typeParam, functionalInterfaceReturnType, argType, true, PsiUtil.getLanguageLevel(functionalInterfaceMethod));
|
||||
if (typeParameterConstraint != null && typeParameterConstraint.getSecond() != ConstraintType.EQUALS && method.isConstructor()) {
|
||||
final Pair<PsiType, ConstraintType> constraintFromParent =
|
||||
inferMethodTypeParameterFromParent(typeParam, partialSubstitutor, methodReferenceExpression.getParent().getParent(), policy);
|
||||
if (constraintFromParent != null && constraintFromParent.getSecond() == ConstraintType.EQUALS) return constraintFromParent;
|
||||
}
|
||||
return typeParameterConstraint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IDEA99970 {
|
||||
public static <T, C> Collector<T, C> toCollection(Supplier<C> collectionFactory) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> Collector<T, List<T>> toList() {
|
||||
return toCollection(ArrayList<T>::new);
|
||||
}
|
||||
|
||||
public static <T> Collector<T, List<T>> toList1() {
|
||||
return toCollection(ArrayList<T>::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface Supplier<T> {
|
||||
public T get();
|
||||
}
|
||||
|
||||
interface Collector<T, R> {}
|
||||
@@ -167,6 +167,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConstructorNonAbstractAbstractExpected() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user