mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
method references of vararg methods
This commit is contained in:
@@ -45,12 +45,14 @@ import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -356,13 +358,22 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
PsiSubstitutor substitutor,
|
||||
LanguageLevel languageLevel) {
|
||||
if (signature == null) return PsiSubstitutor.EMPTY;
|
||||
final PsiType[] types = method.getSignature(PsiUtil.isRawSubstitutor(method, substitutor) ? PsiSubstitutor.EMPTY : substitutor).getParameterTypes();
|
||||
final PsiType[] rightTypes = signature.getParameterTypes();
|
||||
PsiType[] types = method.getSignature(PsiUtil.isRawSubstitutor(method, substitutor) ? PsiSubstitutor.EMPTY : substitutor).getParameterTypes();
|
||||
PsiType[] rightTypes = signature.getParameterTypes();
|
||||
if (!method.isVarArgs() || types.length == 0) {
|
||||
if (types.length < rightTypes.length) {
|
||||
return getSubstitutor(rightTypes[0]);
|
||||
} else if (types.length > rightTypes.length) {
|
||||
return getSubstitutor(types[0]);
|
||||
}
|
||||
} else {
|
||||
if (rightTypes.length != types.length || rightTypes[rightTypes.length - 1].getArrayDimensions() != types[types.length-1].getArrayDimensions()) {
|
||||
types[types.length - 1] = ((PsiArrayType)types[types.length - 1]).getComponentType();
|
||||
int min = Math.min(types.length, rightTypes.length);
|
||||
types = Arrays.copyOf(types, min);
|
||||
rightTypes = Arrays.copyOf(rightTypes, min);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < rightTypes.length; i++) {
|
||||
rightTypes[i] = GenericsUtil.eliminateWildcards(rightTypes[i]);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void a(List<String> range1, List<String> range2) {
|
||||
zip(range1, range2, Test::<String>asList);
|
||||
I1<String> i = Test :: asList;
|
||||
}
|
||||
|
||||
public static <A, B, C> List<C> zip(List<? extends A> a,
|
||||
List<? extends B> b,
|
||||
BiFunction<? super A, ? super B, ? extends C> zipper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface BiFunction<T, U, R> {
|
||||
R apply(T t, U u);
|
||||
}
|
||||
|
||||
public static <T> List<T> asList(T... a) {
|
||||
return null;
|
||||
}
|
||||
|
||||
interface I1<T> {
|
||||
List<T> a(T... t);
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testGetClassSpecifics() { doTest(); }
|
||||
public void testAbstractMethod() { doTest(); }
|
||||
public void testMethodRefAcceptance() { doTest(); }
|
||||
public void testVarargsMethodRef() { doTest(); }
|
||||
|
||||
public void testTypeParameterWithExtendsList() throws Exception {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user