// Loop through each element in S verifying that T has a matching parameter name and that the
// corresponding type is more specific then the type in S.
Iterator<Entry<String, Type>> iteratorS = namedTypesS.entrySet().iterator();
while (iteratorS.hasNext()) {
Entry<String, Type> entryS = iteratorS.next();
Type typeT = namedTypesT.get(entryS.getKey());
if (typeT == null) {
return false;
}
if (!((TypeImpl) typeT).isMoreSpecificThan(entryS.getValue(), withDynamic, visitedTypePairs)) {
return false;
}
}
} else if (s.getNamedParameterTypes().size() > 0) {
return false;
} else {
// positional parameter case
int tArgLength = tTypes.length + tOpTypes.length;
int sArgLength = sTypes.length + sOpTypes.length;
// Check that the total number of parameters in t is greater than or equal to the number of
// parameters in s and that the number of required parameters in s is greater than or equal to
// the number of required parameters in t.
if (tArgLength < sArgLength || sTypes.length < tTypes.length) {
return false;
}
if (tOpTypes.length == 0 && sOpTypes.length == 0) {
// No positional arguments, don't copy contents to new array
for (int i = 0; i < sTypes.length; i++) {
if (!((TypeImpl) tTypes[i]).isMoreSpecificThan(sTypes[i], withDynamic, visitedTypePairs)) {
return false;
}
}
} else {
// Else, we do have positional parameters, copy required and positional parameter types into
// arrays to do the compare (for loop below).
Type[] tAllTypes = new Type[sArgLength];
for (int i = 0; i < tTypes.length; i++) {
tAllTypes[i] = tTypes[i];
}
for (int i = tTypes.length, j = 0; i < sArgLength; i++, j++) {
tAllTypes[i] = tOpTypes[j];
}
Type[] sAllTypes = new Type[sArgLength];
for (int i = 0; i < sTypes.length; i++) {
sAllTypes[i] = sTypes[i];
}
for (int i = sTypes.length, j = 0; i < sArgLength; i++, j++) {
sAllTypes[i] = sOpTypes[j];
}
for (int i = 0; i < sAllTypes.length; i++) {
if (!((TypeImpl) tAllTypes[i]).isMoreSpecificThan(
sAllTypes[i],
withDynamic,
visitedTypePairs)) {
return false;
}
}
}
}
Type tRetType = t.getReturnType();
Type sRetType = s.getReturnType();
return sRetType.isVoid()
|| ((TypeImpl) tRetType).isMoreSpecificThan(sRetType, withDynamic, visitedTypePairs);
}