mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
method ref: accept non parameterized receivers (IDEA-101168)
This commit is contained in:
@@ -189,12 +189,17 @@ public class PsiMethodReferenceUtil {
|
||||
if (receiverClass != null && isReceiverType(receiverClass, containingClass)) {
|
||||
LOG.assertTrue(containingClass != null);
|
||||
return resolveResult.getSubstitutor().equals(psiSubstitutor) ||
|
||||
PsiUtil.isRawSubstitutor(containingClass, psiSubstitutor) ||
|
||||
PsiUtil.isRawSubstitutor(receiverClass, resolveResult.getSubstitutor());
|
||||
emptyOrRaw(containingClass, psiSubstitutor) ||
|
||||
emptyOrRaw(receiverClass, resolveResult.getSubstitutor());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean emptyOrRaw(PsiClass containingClass, PsiSubstitutor psiSubstitutor) {
|
||||
return PsiUtil.isRawSubstitutor(containingClass, psiSubstitutor) ||
|
||||
(!containingClass.hasTypeParameters() && psiSubstitutor.getSubstitutionMap().isEmpty());
|
||||
}
|
||||
|
||||
public static boolean isReceiverType(PsiType functionalInterfaceType, PsiClass containingClass, @Nullable PsiMethod referencedMethod) {
|
||||
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
|
||||
final MethodSignature function = LambdaUtil.getFunction(resolveResult.getElement());
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
class IDEA101168<E> {
|
||||
|
||||
public void foo(Stream<OfPrimitive<E>> stream, Collector<CharSequence, Double> collector) {
|
||||
stream.map(Object ::toString).collect(collector);
|
||||
}
|
||||
|
||||
interface OfPrimitive<A> {
|
||||
}
|
||||
|
||||
interface Collector<T, R> {
|
||||
interface OfInt<R> extends Collector<Integer, R> {
|
||||
}
|
||||
}
|
||||
|
||||
interface Stream<T> extends BaseStream<T> {
|
||||
<R> Stream<R> map(Function<? super T, ? extends R> mapper);
|
||||
IntStream map(ToIntFunction<? super T> mapper);
|
||||
<R> R collect(Collector<? super T, R> collector);
|
||||
}
|
||||
|
||||
interface Function<T, R> {
|
||||
public R apply(T t);
|
||||
}
|
||||
|
||||
interface ToIntFunction<T> {
|
||||
public int applyAsInt(T t);
|
||||
}
|
||||
|
||||
interface IntStream extends BaseStream<Integer> {
|
||||
<R> R collect(Collector.OfInt<R> collector);
|
||||
}
|
||||
interface BaseStream<T> {}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNonParameterizedReceiver() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user