mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method reference: replace raw substitutor from second search with inferred substitutor and don't forget super class substitution (IDEA-149488)
This commit is contained in:
+13
-5
@@ -1444,19 +1444,27 @@ public class InferenceSession {
|
||||
return receiverSubstitutor;
|
||||
}
|
||||
}
|
||||
mySiteSubstitutor = mySiteSubstitutor.putAll(receiverSubstitutor);
|
||||
mySiteSubstitutor = receiverSubstitutor;
|
||||
|
||||
if (methodContainingClass != null) {
|
||||
final PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(methodContainingClass, containingClass, receiverSubstitutor);
|
||||
LOG.assertTrue(superSubstitutor != null, "mContainingClass: " + methodContainingClass.getName() + "; containingClass: " + containingClass.getName());
|
||||
mySiteSubstitutor = mySiteSubstitutor.putAll(superSubstitutor);
|
||||
}
|
||||
|
||||
psiSubstitutor = receiverSubstitutor;
|
||||
}
|
||||
}
|
||||
else if (methodContainingClass != null) {
|
||||
psiSubstitutor = TypeConversionUtil.getClassSubstitutor(methodContainingClass, containingClass, psiSubstitutor);
|
||||
LOG.assertTrue(psiSubstitutor != null, "derived: " + containingClass + "; super: " + methodContainingClass);
|
||||
}
|
||||
|
||||
final PsiType qType = JavaPsiFacade.getElementFactory(method.getProject()).createType(containingClass, psiSubstitutor);
|
||||
|
||||
addConstraint(new TypeCompatibilityConstraint(substituteWithInferenceVariables(qType), pType));
|
||||
|
||||
if (methodContainingClass != null) {
|
||||
psiSubstitutor = TypeConversionUtil.getClassSubstitutor(methodContainingClass, containingClass, psiSubstitutor);
|
||||
LOG.assertTrue(psiSubstitutor != null, "derived: " + containingClass + "; super: " + methodContainingClass);
|
||||
}
|
||||
|
||||
for (int i = 0; i < signature.getParameterTypes().length - 1; i++) {
|
||||
final PsiType interfaceParamType = signature.getParameterTypes()[i + 1];
|
||||
addConstraint(new TypeCompatibilityConstraint(substituteWithInferenceVariables(getParameterType(parameters, i, psiSubstitutor, varargs)),
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
class BBB {
|
||||
|
||||
static <T> void f() {
|
||||
TerminalOp<T, LinkedHashSet<T>> <warning descr="Variable 'reduceOp' is never used">reduceOp</warning> = BBB.<T, LinkedHashSet<T>>makeRef(LinkedHashSet::new, LinkedHashSet::<warning descr="Unchecked call to 'add(E)' as a member of raw type 'HashSet'">add</warning>, LinkedHashSet::<warning descr="Unchecked call to 'addAll(Collection<? extends E>)' as a member of raw type 'AbstractCollection'">addAll</warning>);
|
||||
TerminalOp<T, LinkedHashSet<T>> <warning descr="Variable 'reduceOp' is never used">reduceOp</warning> = BBB.<T, LinkedHashSet<T>>makeRef(LinkedHashSet::new, LinkedHashSet::add, LinkedHashSet::addAll);
|
||||
}
|
||||
|
||||
public static <T, U> TerminalOp<T, U> makeRef(U <warning descr="Parameter 'seed' is never used">seed</warning>, BiFunction<U, ? super T, U> <warning descr="Parameter 'reducer' is never used">reducer</warning>, BinaryOperator<U> <warning descr="Parameter 'combiner' is never used">combiner</warning>) {
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
final class Test {
|
||||
|
||||
public static <TEnum extends Enum<TEnum>> void toEnumSet() {
|
||||
BiConsumer<EnumSet<TEnum>, TEnum> add = EnumSet::add;
|
||||
System.out.println(add);
|
||||
BiConsumer<EnumSet<TEnum>, TEnum> add1 = AbstractCollection::add;
|
||||
System.out.println(add1);
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -62,6 +62,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testUncheckedWarningWithRawSecondSearchAndMethodFromSuper() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testWildcardReturns() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user