if (actualString.equals(objString) && expectedCat == TypeCategory.TYPE_VARIABLE) {
return IncompatibleTypes.SEEMS_OK;
}
if (ignoreBaseType) {
if (expectedCat == TypeCategory.PARAMETERIZED && argCat == TypeCategory.PARAMETERIZED) {
GenericObjectType parmGeneric = (GenericObjectType) expectedType;
GenericObjectType argGeneric = (GenericObjectType) actualType;
return compareTypeParameters(parmGeneric, argGeneric);
}
return IncompatibleTypes.SEEMS_OK;
}
if (actualType.equals(Type.OBJECT) && expectedCat == TypeCategory.ARRAY_TYPE) {
return IncompatibleTypes.ARRAY_AND_OBJECT;
}
// -~- plain objects are easy
if (expectedCat == TypeCategory.PLAIN_OBJECT_TYPE && argCat == TypeCategory.PLAIN_OBJECT_TYPE) {
return IncompatibleTypes.getPriorityForAssumingCompatible(expectedType, actualType, false);
}
if (expectedCat == TypeCategory.PARAMETERIZED && argCat == TypeCategory.PLAIN_OBJECT_TYPE) {
return IncompatibleTypes.getPriorityForAssumingCompatible((GenericObjectType) expectedType, actualType);
}
if (expectedCat == TypeCategory.PLAIN_OBJECT_TYPE && argCat == TypeCategory.PARAMETERIZED) {
return IncompatibleTypes.getPriorityForAssumingCompatible((GenericObjectType) actualType, expectedType);
}
// -~- parmType is: "? extends Another Type" OR "? super Another Type"
if (expectedCat == TypeCategory.WILDCARD_EXTENDS || expectedCat == TypeCategory.WILDCARD_SUPER) {
return compareTypes(((GenericObjectType) expectedType).getExtension(), actualType, ignoreBaseType);
}
// -~- Not handling type variables
if (expectedCat == TypeCategory.TYPE_VARIABLE || argCat == TypeCategory.TYPE_VARIABLE) {
return IncompatibleTypes.SEEMS_OK;
}
// -~- Array Types: compare dimensions, then base type
if (expectedCat == TypeCategory.ARRAY_TYPE && argCat == TypeCategory.ARRAY_TYPE) {
ArrayType parmArray = (ArrayType) expectedType;
ArrayType argArray = (ArrayType) actualType;
if (parmArray.getDimensions() != argArray.getDimensions()) {
return IncompatibleTypes.ARRAY_AND_NON_ARRAY;
}
return compareTypes(parmArray.getBasicType(), argArray.getBasicType(), ignoreBaseType);
}
// If one is an Array Type and the other is not, then they
// are incompatible. (We already know neither is java.lang.Object)
if (expectedCat == TypeCategory.ARRAY_TYPE ^ argCat == TypeCategory.ARRAY_TYPE) {
return IncompatibleTypes.ARRAY_AND_NON_ARRAY;
}
// -~- Parameter Types: compare base type then parameters
if (expectedCat == TypeCategory.PARAMETERIZED && argCat == TypeCategory.PARAMETERIZED) {
GenericObjectType parmGeneric = (GenericObjectType) expectedType;
GenericObjectType argGeneric = (GenericObjectType) actualType;
// base types should be related
{
IncompatibleTypes result = compareTypes(parmGeneric.getObjectType(), argGeneric.getObjectType(), ignoreBaseType);
if (!result.equals(IncompatibleTypes.SEEMS_OK)) {
return result;
}
}
return compareTypeParameters(parmGeneric, argGeneric);