Package de.monticore.types3.util
Class SymTypeCompatibilityCalculator
- java.lang.Object
-
- de.monticore.types3.util.SymTypeCompatibilityCalculator
-
public class SymTypeCompatibilityCalculator extends java.lang.Objectchecks for compatibility between SymTypes delegate of SymTypeRelations
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringLOG_NAME
-
Constructor Summary
Constructors Constructor Description SymTypeCompatibilityCalculator()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.util.List<Bound>arrayConstrainSameType(SymTypeArray arrayA, SymTypeArray arrayB)protected java.util.List<Bound>arrayConstrainSubTypeOf(SymTypeArray subArray, SymTypeArray superArray)whether one array is the subType of anotherprotected java.util.List<Bound>boxedPrimitiveConstrainSubTypeOf(SymTypeOfObject subType, SymTypeOfObject superType)whether a boxed primitive is the subType of another This version is NOT conform to the java spec (20); Java does not allow, e.g., Integer i = 2; Float f = i; Note, that this is (nearly) never an issue about losing object identity: E.g., Integer x = 2; Integer y = 2; // x == y holds but, Integer x = 222; Integer y = 222; // x != y holds (tested in JDK 17) s.a.protected <T extends SymTypeExpression>
TboxGenericButNotArguments(T type)E.g.:List<List<int>> to java.util.List<List<int>>java.util.List<Bound>constrainCompatible(SymTypeExpression target, SymTypeExpression source)protected java.util.List<Bound>constrainCompatiblePreNormalized(SymTypeExpression target, SymTypeExpression source)protected java.util.List<Bound>constrainContainsPreNormalized(SymTypeExpression subSetType, SymTypeExpression superSetType)Is the set of types denoted by subSetType a subSet of the set of types denoted by superSetType? s.java.util.List<Bound>constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)protected java.util.List<Bound>constrainSameTypeUsingSubTypeOf(SymTypeExpression typeA, SymTypeExpression typeB)Reduces a constraint<a = b>to the constraints<a <: b>, <b <: a>.java.util.List<Bound>constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)protected java.util.List<Bound>constrainSubTypeOfSubIntersection(SymTypeOfIntersection subType, SymTypeExpression superType)protected java.util.List<Bound>constrainSubTypeOfSubUnion(SymTypeOfUnion subType, SymTypeExpression superType)protected java.util.List<Bound>constrainSubTypeOfSuperIntersection(SymTypeExpression subType, SymTypeOfIntersection superType)protected java.util.List<Bound>constrainSubTypeOfSuperUnion(SymTypeExpression subType, SymTypeOfUnion superType)protected java.util.List<Bound>functionConstrainSameType(SymTypeOfFunction funcA, SymTypeOfFunction funcB)protected java.util.List<Bound>functionConstrainSubTypeOf(SymTypeOfFunction subFunc, SymTypeOfFunction superFunc)protected java.util.List<SymTypeExpression>getSuperTypes(SymTypeExpression thisType)Deprecated, for removal: This API element is subject to removal in a future version.protected UnsatisfiableBoundgetUnsatisfiableBoundForCompatibilty(SymTypeExpression targetType, SymTypeExpression sourceType)protected UnsatisfiableBoundgetUnsatisfiableBoundForContainment(SymTypeExpression subSetType, SymTypeExpression superSetType)protected UnsatisfiableBoundgetUnsatisfiableBoundForSameType(SymTypeExpression typeA, SymTypeExpression typeB)protected UnsatisfiableBoundgetUnsatisfiableBoundForSubTyping(SymTypeExpression subType, SymTypeExpression superType)protected java.util.List<Bound>handleMultipleListOfBounds(java.util.List<java.util.List<Bound>> bounds, SymTypeExpression subType, SymTypeExpression superType)protected java.util.List<Bound>infVarConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)protected java.util.List<Bound>internal_constrainSameTypePreNormalized(SymTypeExpression typeA, SymTypeExpression typeB)java.util.List<Bound>internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType)booleaninternal_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)Deprecated, for removal: This API element is subject to removal in a future version.booleaninternal_isSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)Deprecated, for removal: This API element is subject to removal in a future version.protected java.util.List<Bound>intersectionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)booleanisCompatible(SymTypeExpression target, SymTypeExpression source)booleanisSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)protected java.util.List<Bound>nullConstrainCompatible(SymTypeExpression target, SymTypeOfNull source)protected java.util.List<Bound>numericWithSIUnitConstrainSameType(SymTypeOfNumericWithSIUnit numericWithSIUnitA, SymTypeOfNumericWithSIUnit numericWithSIUnitB)protected java.util.List<Bound>numericWithSIUnitConstrainSubTypeOf(SymTypeOfNumericWithSIUnit subType, SymTypeOfNumericWithSIUnit superType)protected java.util.List<Bound>objectConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)protected java.util.List<Bound>objectConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)whether one object is a subType of another this includes SymTypeOfObject, as well as SymTypeOfGenericsprotected java.util.List<Bound>primitiveConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)protected java.lang.StringprintBounds(java.util.List<Bound> bounds)protected java.util.List<Bound>regExConstrainCompatible(SymTypeExpression target, SymTypeExpression source)isCompatible if one of the arguments is a SymTypeOfRegexprotected java.util.List<Bound>regExConstrainSameType(SymTypeExpression regexA, SymTypeExpression regexB)protected java.util.List<Bound>regExConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)whether one type is the subType of another is if at least one of them is a SymTypeOfRegExprotected java.util.List<Bound>singleConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)this tests all symtypes that are not union or intersection types (and don't contain them)protected java.util.List<Bound>siUnitConstrainSameType(SymTypeOfSIUnit siUnitA, SymTypeOfSIUnit siUnitB)protected java.util.List<Bound>siUnitConstrainSubTypeOf(SymTypeOfSIUnit subType, SymTypeOfSIUnit superType)protected java.util.List<Bound>tupleConstrainSameType(SymTypeOfTuple tupleA, SymTypeOfTuple tupleB)protected java.util.List<Bound>tupleConstrainSubTypeOf(SymTypeOfTuple subTuple, SymTypeOfTuple superTuple)protected java.util.List<Bound>typeSetConstrainCompatible(SymTypeExpression target, SymTypeExpression source)s.a.protected java.util.List<Bound>typeSetConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)whether one expression is the subType of another, with at least one of the types being a variable or wildcard, thus representing a set of types, rather than a single type.protected java.util.List<Bound>unboxedPrimitiveConstrainSubTypeOf(SymTypePrimitive subType, SymTypePrimitive superType)whether unboxed primitives are in a subType relation s.protected java.util.List<Bound>unionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)protected java.util.List<Bound>wildcardConstrainSameType(SymTypeOfWildcard wcA, SymTypeOfWildcard wcB)
-
-
-
Field Detail
-
LOG_NAME
protected static final java.lang.String LOG_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
isCompatible
public boolean isCompatible(SymTypeExpression target, SymTypeExpression source)
-
isSubTypeOf
public boolean isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
-
internal_isSubTypeOf
@Deprecated(forRemoval=true) public boolean internal_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)
Deprecated, for removal: This API element is subject to removal in a future version.isSubTypeOf and canBeSubTypeOf, as they are very similar subTypeIsSoft if it is only a possibility, that it is a subtype
-
internal_isSubTypeOfPreNormalized
@Deprecated(forRemoval=true) public boolean internal_isSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)
Deprecated, for removal: This API element is subject to removal in a future version.
-
constrainCompatible
public java.util.List<Bound> constrainCompatible(SymTypeExpression target, SymTypeExpression source)
-
constrainCompatiblePreNormalized
protected java.util.List<Bound> constrainCompatiblePreNormalized(SymTypeExpression target, SymTypeExpression source)
-
typeSetConstrainCompatible
protected java.util.List<Bound> typeSetConstrainCompatible(SymTypeExpression target, SymTypeExpression source)
-
nullConstrainCompatible
protected java.util.List<Bound> nullConstrainCompatible(SymTypeExpression target, SymTypeOfNull source)
-
regExConstrainCompatible
protected java.util.List<Bound> regExConstrainCompatible(SymTypeExpression target, SymTypeExpression source)
isCompatible if one of the arguments is a SymTypeOfRegex- Returns:
- if false, it can still be compatible due to other typing rules
-
constrainSubTypeOf
public java.util.List<Bound> constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
-
internal_constrainSubTypeOfPreNormalized
public java.util.List<Bound> internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType)
-
constrainSubTypeOfSubUnion
protected java.util.List<Bound> constrainSubTypeOfSubUnion(SymTypeOfUnion subType, SymTypeExpression superType)
-
constrainSubTypeOfSuperUnion
protected java.util.List<Bound> constrainSubTypeOfSuperUnion(SymTypeExpression subType, SymTypeOfUnion superType)
- Parameters:
subType- is not a union
-
constrainSubTypeOfSuperIntersection
protected java.util.List<Bound> constrainSubTypeOfSuperIntersection(SymTypeExpression subType, SymTypeOfIntersection superType)
- Parameters:
subType- is not a union
-
constrainSubTypeOfSubIntersection
protected java.util.List<Bound> constrainSubTypeOfSubIntersection(SymTypeOfIntersection subType, SymTypeExpression superType)
- Parameters:
superType- is neither union nor intersection
-
handleMultipleListOfBounds
protected java.util.List<Bound> handleMultipleListOfBounds(java.util.List<java.util.List<Bound>> bounds, SymTypeExpression subType, SymTypeExpression superType)
Helper forconstrainSubTypeOfSuperUnion(SymTypeExpression, SymTypeOfUnion),constrainSubTypeOfSubIntersection(SymTypeOfIntersection, SymTypeExpression). In these cases, one does not calculate bounds that are connected by 'and', instead, List of 'and'-ed bounds are calculated, which in turn are connected by 'or'. Solving these sets of bounds may be heavily exponential, as such, we use a heuristic to reduce them to a single list of 'and'-ed bounds.- Parameters:
subType- used for loggingsuperType- used for logging- Returns:
- the result may not contain the most optimal set of bounds, but it will never(!) omit required bounds.
-
constrainSameType
public java.util.List<Bound> constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
internal_constrainSameTypePreNormalized
protected java.util.List<Bound> internal_constrainSameTypePreNormalized(SymTypeExpression typeA, SymTypeExpression typeB)
-
singleConstrainSubTypeOf
protected java.util.List<Bound> singleConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
this tests all symtypes that are not union or intersection types (and don't contain them)
-
typeSetConstrainSubTypeOf
protected java.util.List<Bound> typeSetConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
whether one expression is the subType of another, with at least one of the types being a variable or wildcard, thus representing a set of types, rather than a single type.
-
arrayConstrainSubTypeOf
protected java.util.List<Bound> arrayConstrainSubTypeOf(SymTypeArray subArray, SymTypeArray superArray)
whether one array is the subType of another
-
unboxedPrimitiveConstrainSubTypeOf
protected java.util.List<Bound> unboxedPrimitiveConstrainSubTypeOf(SymTypePrimitive subType, SymTypePrimitive superType)
whether unboxed primitives are in a subType relation s. Java spec 20 4.10.1
-
boxedPrimitiveConstrainSubTypeOf
protected java.util.List<Bound> boxedPrimitiveConstrainSubTypeOf(SymTypeOfObject subType, SymTypeOfObject superType)
whether a boxed primitive is the subType of another This version is NOT conform to the java spec (20); Java does not allow, e.g., Integer i = 2; Float f = i; Note, that this is (nearly) never an issue about losing object identity: E.g., Integer x = 2; Integer y = 2; // x == y holds but, Integer x = 222; Integer y = 222; // x != y holds (tested in JDK 17) s.a. Java spec 20 5.1.7 Thus, unlike Java we allow Integer i = 2; Float f = i;, is a subTypeRelation analoge to unboxed primitives This method needs to be overridden if a more Java-conform check is required
-
primitiveConstrainSubTypeOf
protected java.util.List<Bound> primitiveConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
-
tupleConstrainSubTypeOf
protected java.util.List<Bound> tupleConstrainSubTypeOf(SymTypeOfTuple subTuple, SymTypeOfTuple superTuple)
-
functionConstrainSubTypeOf
protected java.util.List<Bound> functionConstrainSubTypeOf(SymTypeOfFunction subFunc, SymTypeOfFunction superFunc)
-
objectConstrainSubTypeOf
protected java.util.List<Bound> objectConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
whether one object is a subType of another this includes SymTypeOfObject, as well as SymTypeOfGenerics
-
regExConstrainSubTypeOf
protected java.util.List<Bound> regExConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
whether one type is the subType of another is if at least one of them is a SymTypeOfRegEx
-
numericWithSIUnitConstrainSubTypeOf
protected java.util.List<Bound> numericWithSIUnitConstrainSubTypeOf(SymTypeOfNumericWithSIUnit subType, SymTypeOfNumericWithSIUnit superType)
-
siUnitConstrainSubTypeOf
protected java.util.List<Bound> siUnitConstrainSubTypeOf(SymTypeOfSIUnit subType, SymTypeOfSIUnit superType)
-
infVarConstrainSameType
protected java.util.List<Bound> infVarConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
intersectionConstrainSameType
protected java.util.List<Bound> intersectionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
unionConstrainSameType
protected java.util.List<Bound> unionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
arrayConstrainSameType
protected java.util.List<Bound> arrayConstrainSameType(SymTypeArray arrayA, SymTypeArray arrayB)
-
tupleConstrainSameType
protected java.util.List<Bound> tupleConstrainSameType(SymTypeOfTuple tupleA, SymTypeOfTuple tupleB)
-
functionConstrainSameType
protected java.util.List<Bound> functionConstrainSameType(SymTypeOfFunction funcA, SymTypeOfFunction funcB)
-
numericWithSIUnitConstrainSameType
protected java.util.List<Bound> numericWithSIUnitConstrainSameType(SymTypeOfNumericWithSIUnit numericWithSIUnitA, SymTypeOfNumericWithSIUnit numericWithSIUnitB)
-
siUnitConstrainSameType
protected java.util.List<Bound> siUnitConstrainSameType(SymTypeOfSIUnit siUnitA, SymTypeOfSIUnit siUnitB)
-
regExConstrainSameType
protected java.util.List<Bound> regExConstrainSameType(SymTypeExpression regexA, SymTypeExpression regexB)
-
objectConstrainSameType
protected java.util.List<Bound> objectConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
wildcardConstrainSameType
protected java.util.List<Bound> wildcardConstrainSameType(SymTypeOfWildcard wcA, SymTypeOfWildcard wcB)
-
constrainContainsPreNormalized
protected java.util.List<Bound> constrainContainsPreNormalized(SymTypeExpression subSetType, SymTypeExpression superSetType)
Is the set of types denoted by subSetType a subSet of the set of types denoted by superSetType? s. Java spec 20 4.5.1, 4.10.2 A type variable represents multiple Types, in other cases, this is an identity check. s. a.typeSetConstrainSubTypeOf(de.monticore.types.check.SymTypeExpression, de.monticore.types.check.SymTypeExpression)The arguments are expected to be normalized. Additionally, type variables within other symTypes are currently not supported, this helper function (currently) is only to check subtyping of generics. Tuples could be extended in this regard (currently not needed).Fundamentally, T1 "contains" T2 (
"T2 <= T1") if the set of types denoted by T1 is (provably) a superSet of the types denoted by T2. This translates to the reflexive and transitive closure of (from spec):-
? extends T <= ? extends S if T <: S -
? extends T <= ? -
? super T <= ? super S if S <: T -
? super T <= ? -
? super T <= ? extends Object -
T <= T -
T <= ? extends T -
T <= ? super T
-
-
constrainSameTypeUsingSubTypeOf
protected java.util.List<Bound> constrainSameTypeUsingSubTypeOf(SymTypeExpression typeA, SymTypeExpression typeB)
Reduces a constraint<a = b>to the constraints<a <: b>, <b <: a>. This is not necessarily ideal wrt. resulting messages, and should be replaced in the future if required. It will most likely result in incorrect values, iff any inference variables are present.
-
getUnsatisfiableBoundForCompatibilty
protected UnsatisfiableBound getUnsatisfiableBoundForCompatibilty(SymTypeExpression targetType, SymTypeExpression sourceType)
-
getUnsatisfiableBoundForSubTyping
protected UnsatisfiableBound getUnsatisfiableBoundForSubTyping(SymTypeExpression subType, SymTypeExpression superType)
-
getUnsatisfiableBoundForSameType
protected UnsatisfiableBound getUnsatisfiableBoundForSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
getUnsatisfiableBoundForContainment
protected UnsatisfiableBound getUnsatisfiableBoundForContainment(SymTypeExpression subSetType, SymTypeExpression superSetType)
-
getSuperTypes
@Deprecated(forRemoval=true) protected java.util.List<SymTypeExpression> getSuperTypes(SymTypeExpression thisType)
Deprecated, for removal: This API element is subject to removal in a future version.
-
boxGenericButNotArguments
protected <T extends SymTypeExpression> T boxGenericButNotArguments(T type)
E.g.:List<List<int>> to java.util.List<List<int>>
-
printBounds
protected java.lang.String printBounds(java.util.List<Bound> bounds)
-
-