mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
new inference: most specifics, varargs case
This commit is contained in:
@@ -968,12 +968,14 @@ public class InferenceSession {
|
||||
|
||||
final PsiParameter[] parameters1 = m1.getParameterList().getParameters();
|
||||
final PsiParameter[] parameters2 = m2.getParameterList().getParameters();
|
||||
LOG.assertTrue(parameters1.length == parameters2.length);
|
||||
if (!varargs) {
|
||||
LOG.assertTrue(parameters1.length == parameters2.length);
|
||||
}
|
||||
|
||||
final int paramsLength = !varargs ? parameters1.length : parameters1.length - 1;
|
||||
for (int i = 0; i < paramsLength; i++) {
|
||||
PsiType sType = siteSubstitutor2.substitute(parameters1[i].getType());
|
||||
PsiType tType = siteSubstitutor2.substitute(parameters2[i].getType());
|
||||
PsiType tType = siteSubstitutor2.substitute(getVarargParameterType(varargs, i, parameters2));
|
||||
if (session.isProperType(sType) && session.isProperType(tType)) {
|
||||
if (!TypeConversionUtil.isAssignable(tType, sType)) {
|
||||
return false;
|
||||
@@ -991,13 +993,22 @@ public class InferenceSession {
|
||||
|
||||
if (varargs) {
|
||||
PsiType sType = siteSubstitutor2.substitute(parameters1[paramsLength].getType());
|
||||
PsiType tType = siteSubstitutor2.substitute(parameters2[paramsLength].getType());
|
||||
PsiType tType = siteSubstitutor2.substitute(getVarargParameterType(true, paramsLength, parameters2));
|
||||
session.addConstraint(new StrictSubtypingConstraint(tType, sType));
|
||||
}
|
||||
|
||||
return session.repeatInferencePhases(true);
|
||||
}
|
||||
|
||||
public static PsiType getVarargParameterType(boolean varargs, int i, PsiParameter[] parameters2) {
|
||||
if (varargs && i >= parameters2.length - 1) {
|
||||
final PsiType lastParamType = parameters2[parameters2.length - 1].getType();
|
||||
LOG.assertTrue(lastParamType instanceof PsiEllipsisType);
|
||||
return ((PsiEllipsisType)lastParamType).getComponentType();
|
||||
}
|
||||
return parameters2[i].getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* 15.12.2.5 Choosing the Most Specific Method
|
||||
* "a functional interface type S is more specific than a functional interface type T for an expression exp" part
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.*;
|
||||
|
||||
class Specificss {
|
||||
{
|
||||
Set<String> JAR_EXTENSIONS = newTroveSet(new ArrayList<String>(), "jar", "zip", "swc", "ane");
|
||||
}
|
||||
|
||||
|
||||
public static <T> HashSet<T> newTroveSet(T... elements) {
|
||||
return newTroveSet(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
public static <T> HashSet<T> newTroveSet(List<T> strategy, T... elements) {
|
||||
return new HashSet<T>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,6 +156,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMostSpecificVarargsCase() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user