Class CollectionLiteralsTypeComputer
- java.lang.Object
-
- org.eclipse.xtext.xbase.typesystem.computation.AbstractTypeComputer
-
- org.eclipse.xtext.xbase.typesystem.computation.CollectionLiteralsTypeComputer
-
public class CollectionLiteralsTypeComputer extends AbstractTypeComputer
Utility that helps to compute the type for collection literals.- Since:
- 2.8
-
-
Constructor Summary
Constructors Constructor Description CollectionLiteralsTypeComputer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomputeArrayLiteralType(XListLiteral literal, LightweightTypeReference expectedArrayType, ITypeExpectation expectation, ITypeComputationState state)protected java.util.List<LightweightTypeReference>computeCollectionTypeCandidates(XCollectionLiteral literal, org.eclipse.xtext.common.types.JvmGenericType collectionType, LightweightTypeReference elementTypeExpectation, ITypeComputationState state)Creates a list of collection type references from the element types of a collection literal.protected voidcomputeType(XListLiteral literal, org.eclipse.xtext.common.types.JvmGenericType listType, ITypeExpectation expectation, ITypeComputationState state)voidcomputeType(XListLiteral literal, ITypeComputationState state)Entry point from theXbaseTypeComputer.protected voidcomputeType(XSetLiteral literal, org.eclipse.xtext.common.types.JvmGenericType setType, org.eclipse.xtext.common.types.JvmGenericType mapType, ITypeExpectation expectation, ITypeComputationState state)voidcomputeType(XSetLiteral literal, ITypeComputationState state)Entry point from theXbaseTypeComputer.protected ITypeComputationResultcomputeTypes(XExpression element, LightweightTypeReference expectation, ITypeComputationState state)protected LightweightTypeReferencecreateCollectionTypeReference(org.eclipse.xtext.common.types.JvmGenericType collectionType, LightweightTypeReference elementType, LightweightTypeReference expectedType, ITypeReferenceOwner owner)Creates a collection type reference that comes as close as possible / necessary to its expected type.protected LightweightTypeReferencecreateMapTypeReference(org.eclipse.xtext.common.types.JvmGenericType mapType, LightweightTypeReference pairType, LightweightTypeReference expectation, ITypeReferenceOwner owner)Creates a map type reference that comes as close as possible / necessary to its expected type.protected LightweightTypeReferencecreateNormalizedPairType(LightweightTypeReference pairType, LightweightTypeReference mapType, ITypeReferenceOwner owner)The map type may be constructed from different pairs, e.g.protected LightweightTypeReferencedoNormalizeElementType(LightweightTypeReference actual, LightweightTypeReference expected)If the expected type is not a wildcard, it may supersede the actual element type.protected LightweightTypeReferencegetCommonSuperType(java.util.List<LightweightTypeReference> types, ITypeComputationState state)Specializes the super implementation such that is allows an empty list of types.protected LightweightTypeReferencegetElementOrComponentType(LightweightTypeReference iterableOrArray, ITypeComputationState state)protected LightweightTypeReferencegetElementOrComponentType(LightweightTypeReference iterableOrArray, ITypeReferenceOwner owner)protected LightweightTypeReferencegetMapExpectation(LightweightTypeReference expectation)If the expected type is a subtype ofMap, the resolved super type is returned.protected voidhandleCollectionTypeNotAvailable(XCollectionLiteral literal, ITypeComputationState state, java.lang.Class<?> clazz)Process all children and assign an unknown type to the literal.protected booleanisExpectedType(LightweightTypeReference expectation, java.lang.Class<?> clazz)protected booleanisIterableExpectation(LightweightTypeReference expectation)protected booleanisMapExpectation(LightweightTypeReference expectation)protected booleanisMapLiteral(LightweightTypeReference expectation, LightweightTypeReference elementType)protected booleanisSubtypeButNotSynonym(LightweightTypeReference expectation, java.lang.Class<?> clazz)Same asLightweightTypeReference.isSubtypeOf(Class)but does not accept synonym types as subtypes.protected booleanmatchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation)Implements fall-back strategy.protected LightweightTypeReferencenormalizeElementType(LightweightTypeReference collectionElementType, LightweightTypeReference expectedCollectionType, ITypeReferenceOwner owner)The expected collection type may drive the type of the elements in the collection if the type is used as an invariant type.protected LightweightTypeReferencenormalizeFunctionTypeReference(LightweightTypeReference type)A function type reference may be known to have the type argumentNumberbut still use a more specific return typeInteger.protected voidrefineElementTypeExpectation(XCollectionLiteral literal, LightweightTypeReference expectation, ITypeComputationState state)protected voidsetUnboundCollectionType(XCollectionLiteral literal, org.eclipse.xtext.common.types.JvmGenericType collectionType, ITypeExpectation expectation, LightweightTypeReference elementTypeExpectation, ITypeComputationState state)-
Methods inherited from class org.eclipse.xtext.xbase.typesystem.computation.AbstractTypeComputer
deferredBindTypeArgument, findDeclaredType, findDeclaredType, findDeclaredType, findDeclaredType, getCommonSuperType, getPrimitiveVoid, getRawTypeForName, getRawTypeForName, getRawTypeForName, getTypeForName, getTypeForName
-
-
-
-
Method Detail
-
computeType
public void computeType(XSetLiteral literal, ITypeComputationState state)
Entry point from theXbaseTypeComputer.
-
computeType
public void computeType(XListLiteral literal, ITypeComputationState state)
Entry point from theXbaseTypeComputer.
-
getCommonSuperType
protected LightweightTypeReference getCommonSuperType(java.util.List<LightweightTypeReference> types, ITypeComputationState state)
Specializes the super implementation such that is allows an empty list of types. Returnsnullfor those. Computes the common super type for the given list of types. The list may not be empty.- Overrides:
getCommonSuperTypein classAbstractTypeComputer
-
computeType
protected void computeType(XSetLiteral literal, org.eclipse.xtext.common.types.JvmGenericType setType, org.eclipse.xtext.common.types.JvmGenericType mapType, ITypeExpectation expectation, ITypeComputationState state)
-
setUnboundCollectionType
protected void setUnboundCollectionType(XCollectionLiteral literal, org.eclipse.xtext.common.types.JvmGenericType collectionType, ITypeExpectation expectation, LightweightTypeReference elementTypeExpectation, ITypeComputationState state)
-
refineElementTypeExpectation
protected void refineElementTypeExpectation(XCollectionLiteral literal, LightweightTypeReference expectation, ITypeComputationState state)
-
isMapLiteral
protected boolean isMapLiteral(LightweightTypeReference expectation, LightweightTypeReference elementType)
-
isMapExpectation
protected boolean isMapExpectation(LightweightTypeReference expectation)
-
computeType
protected void computeType(XListLiteral literal, org.eclipse.xtext.common.types.JvmGenericType listType, ITypeExpectation expectation, ITypeComputationState state)
-
computeArrayLiteralType
protected void computeArrayLiteralType(XListLiteral literal, LightweightTypeReference expectedArrayType, ITypeExpectation expectation, ITypeComputationState state)
-
computeTypes
protected ITypeComputationResult computeTypes(XExpression element, LightweightTypeReference expectation, ITypeComputationState state)
-
handleCollectionTypeNotAvailable
protected void handleCollectionTypeNotAvailable(XCollectionLiteral literal, ITypeComputationState state, java.lang.Class<?> clazz)
Process all children and assign an unknown type to the literal.
-
createNormalizedPairType
protected LightweightTypeReference createNormalizedPairType(LightweightTypeReference pairType, LightweightTypeReference mapType, ITypeReferenceOwner owner)
The map type may be constructed from different pairs, e.g. the pair's type arguments don't need to be as strict as the map suggests. The pair's expectation is adjusted accordingly.
-
createCollectionTypeReference
protected LightweightTypeReference createCollectionTypeReference(org.eclipse.xtext.common.types.JvmGenericType collectionType, LightweightTypeReference elementType, LightweightTypeReference expectedType, ITypeReferenceOwner owner)
Creates a collection type reference that comes as close as possible / necessary to its expected type.
-
createMapTypeReference
protected LightweightTypeReference createMapTypeReference(org.eclipse.xtext.common.types.JvmGenericType mapType, LightweightTypeReference pairType, LightweightTypeReference expectation, ITypeReferenceOwner owner)
Creates a map type reference that comes as close as possible / necessary to its expected type.
-
matchesExpectation
protected boolean matchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation)
Implements fall-back strategy. If the expected type of a collection literal does not match the actual type, but the expected element types would match the actual element type, the collection literal will be successfully typed according to the expectation.
-
getMapExpectation
protected LightweightTypeReference getMapExpectation(LightweightTypeReference expectation)
If the expected type is a subtype ofMap, the resolved super type is returned. This allows to query for the type arguments that are available on the expectation.
-
normalizeElementType
protected LightweightTypeReference normalizeElementType(LightweightTypeReference collectionElementType, LightweightTypeReference expectedCollectionType, ITypeReferenceOwner owner)
The expected collection type may drive the type of the elements in the collection if the type is used as an invariant type. In other word, an expectation of the formCollection<CharSequence>may yield a typeList<CharSequence>for the literal['a']even though it would beList<? extends String>if no expectation was given.
-
isIterableExpectation
protected boolean isIterableExpectation(LightweightTypeReference expectation)
-
isExpectedType
protected boolean isExpectedType(LightweightTypeReference expectation, java.lang.Class<?> clazz)
-
isSubtypeButNotSynonym
protected boolean isSubtypeButNotSynonym(LightweightTypeReference expectation, java.lang.Class<?> clazz)
Same asLightweightTypeReference.isSubtypeOf(Class)but does not accept synonym types as subtypes.
-
normalizeFunctionTypeReference
protected LightweightTypeReference normalizeFunctionTypeReference(LightweightTypeReference type)
A function type reference may be known to have the type argumentNumberbut still use a more specific return typeInteger. Normalization converts such a reference to the return typeNumber.
-
doNormalizeElementType
protected LightweightTypeReference doNormalizeElementType(LightweightTypeReference actual, LightweightTypeReference expected)
If the expected type is not a wildcard, it may supersede the actual element type.
-
computeCollectionTypeCandidates
protected java.util.List<LightweightTypeReference> computeCollectionTypeCandidates(XCollectionLiteral literal, org.eclipse.xtext.common.types.JvmGenericType collectionType, LightweightTypeReference elementTypeExpectation, ITypeComputationState state)
Creates a list of collection type references from the element types of a collection literal.
-
getElementOrComponentType
protected LightweightTypeReference getElementOrComponentType(LightweightTypeReference iterableOrArray, ITypeComputationState state)
-
getElementOrComponentType
protected LightweightTypeReference getElementOrComponentType(LightweightTypeReference iterableOrArray, ITypeReferenceOwner owner)
Delegates toElementOrComponentTypeComputer.compute(LightweightTypeReference, ITypeReferenceOwner). Clients may override.
-
-