public class CollectionLiteralsTypeComputer extends AbstractTypeComputer
Constructor and Description |
---|
CollectionLiteralsTypeComputer() |
Modifier and Type | Method and Description |
---|---|
protected void |
computeArrayLiteralType(XListLiteral literal,
LightweightTypeReference expectedArrayType,
ITypeExpectation expectation,
ITypeComputationState state) |
protected java.util.List<LightweightTypeReference> |
computeCollectionTypeCandidates(XCollectionLiteral literal,
JvmGenericType collectionType,
LightweightTypeReference elementTypeExpectation,
ITypeComputationState state)
Creates a list of collection type references from the element types of a collection literal.
|
void |
computeType(XListLiteral literal,
ITypeComputationState state)
Entry point from the
XbaseTypeComputer . |
protected void |
computeType(XListLiteral literal,
JvmGenericType listType,
ITypeExpectation expectation,
ITypeComputationState state) |
void |
computeType(XSetLiteral literal,
ITypeComputationState state)
Entry point from the
XbaseTypeComputer . |
protected void |
computeType(XSetLiteral literal,
JvmGenericType setType,
JvmGenericType mapType,
ITypeExpectation expectation,
ITypeComputationState state) |
protected ITypeComputationResult |
computeTypes(XExpression element,
LightweightTypeReference expectation,
ITypeComputationState state) |
protected LightweightTypeReference |
createCollectionTypeReference(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 LightweightTypeReference |
createMapTypeReference(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 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.
|
protected LightweightTypeReference |
doNormalizeElementType(LightweightTypeReference actual,
LightweightTypeReference expected)
If the expected type is not a wildcard, it may supersede the actual element type.
|
protected LightweightTypeReference |
getCommonSuperType(java.util.List<LightweightTypeReference> types,
ITypeComputationState state)
Specializes the super implementation such that is allows an empty list of types.
|
protected LightweightTypeReference |
getElementOrComponentType(LightweightTypeReference iterableOrArray,
ITypeComputationState state) |
protected LightweightTypeReference |
getElementOrComponentType(LightweightTypeReference iterableOrArray,
ITypeReferenceOwner owner)
|
protected LightweightTypeReference |
getMapExpectation(LightweightTypeReference expectation)
If the expected type is a subtype of
Map , the resolved super type is returned. |
protected void |
handleCollectionTypeNotAvailable(XCollectionLiteral literal,
ITypeComputationState state,
java.lang.Class<?> clazz)
Process all children and assign an unknown type to the literal.
|
protected boolean |
isExpectedType(LightweightTypeReference expectation,
java.lang.Class<?> clazz) |
protected boolean |
isIterableExpectation(LightweightTypeReference expectation) |
protected boolean |
isMapExpectation(LightweightTypeReference expectation) |
protected boolean |
isMapLiteral(LightweightTypeReference expectation,
LightweightTypeReference elementType) |
protected boolean |
isSubtypeButNotSynonym(LightweightTypeReference expectation,
java.lang.Class<?> clazz)
Same as
LightweightTypeReference.isSubtypeOf(Class) but does not accept synonym types as subtypes. |
protected boolean |
matchesExpectation(LightweightTypeReference elementType,
LightweightTypeReference expectation)
Implements fall-back strategy.
|
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.
|
protected LightweightTypeReference |
normalizeFunctionTypeReference(LightweightTypeReference type)
A function type reference may be known to have the type argument
Number but still use a more
specific return type Integer . |
protected void |
refineElementTypeExpectation(XCollectionLiteral literal,
LightweightTypeReference expectation,
ITypeComputationState state) |
protected void |
setUnboundCollectionType(XCollectionLiteral literal,
JvmGenericType collectionType,
ITypeExpectation expectation,
LightweightTypeReference elementTypeExpectation,
ITypeComputationState state) |
deferredBindTypeArgument, findDeclaredType, findDeclaredType, getCommonSuperType, getPrimitiveVoid, getRawTypeForName, getRawTypeForName, getTypeForName
public void computeType(XSetLiteral literal, ITypeComputationState state)
XbaseTypeComputer
.public void computeType(XListLiteral literal, ITypeComputationState state)
XbaseTypeComputer
.protected LightweightTypeReference getCommonSuperType(java.util.List<LightweightTypeReference> types, ITypeComputationState state)
null
for those.
Computes the common super type for the given list of types. The list may not be empty.getCommonSuperType
in class AbstractTypeComputer
protected void computeType(XSetLiteral literal, JvmGenericType setType, JvmGenericType mapType, ITypeExpectation expectation, ITypeComputationState state)
protected void setUnboundCollectionType(XCollectionLiteral literal, JvmGenericType collectionType, ITypeExpectation expectation, LightweightTypeReference elementTypeExpectation, ITypeComputationState state)
protected void refineElementTypeExpectation(XCollectionLiteral literal, LightweightTypeReference expectation, ITypeComputationState state)
protected boolean isMapLiteral(LightweightTypeReference expectation, LightweightTypeReference elementType)
protected boolean isMapExpectation(LightweightTypeReference expectation)
protected void computeType(XListLiteral literal, JvmGenericType listType, ITypeExpectation expectation, ITypeComputationState state)
protected void computeArrayLiteralType(XListLiteral literal, LightweightTypeReference expectedArrayType, ITypeExpectation expectation, ITypeComputationState state)
protected ITypeComputationResult computeTypes(XExpression element, LightweightTypeReference expectation, ITypeComputationState state)
protected void handleCollectionTypeNotAvailable(XCollectionLiteral literal, ITypeComputationState state, java.lang.Class<?> clazz)
protected LightweightTypeReference createNormalizedPairType(LightweightTypeReference pairType, LightweightTypeReference mapType, ITypeReferenceOwner owner)
protected LightweightTypeReference createCollectionTypeReference(JvmGenericType collectionType, LightweightTypeReference elementType, LightweightTypeReference expectedType, ITypeReferenceOwner owner)
protected LightweightTypeReference createMapTypeReference(JvmGenericType mapType, LightweightTypeReference pairType, LightweightTypeReference expectation, ITypeReferenceOwner owner)
protected boolean matchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation)
protected LightweightTypeReference getMapExpectation(LightweightTypeReference expectation)
Map
, the resolved super type is returned.
This allows to query for the type arguments that are available on the expectation.protected LightweightTypeReference normalizeElementType(LightweightTypeReference collectionElementType, LightweightTypeReference expectedCollectionType, ITypeReferenceOwner owner)
Collection<CharSequence>
may yield a type List<CharSequence>
for the literal
['a']
even though it would be List<? extends String>
if no expectation was given.protected boolean isIterableExpectation(LightweightTypeReference expectation)
protected boolean isExpectedType(LightweightTypeReference expectation, java.lang.Class<?> clazz)
protected boolean isSubtypeButNotSynonym(LightweightTypeReference expectation, java.lang.Class<?> clazz)
LightweightTypeReference.isSubtypeOf(Class)
but does not accept synonym types as subtypes.protected LightweightTypeReference normalizeFunctionTypeReference(LightweightTypeReference type)
Number
but still use a more
specific return type Integer
. Normalization converts such a reference to the return type Number
.protected LightweightTypeReference doNormalizeElementType(LightweightTypeReference actual, LightweightTypeReference expected)
protected java.util.List<LightweightTypeReference> computeCollectionTypeCandidates(XCollectionLiteral literal, JvmGenericType collectionType, LightweightTypeReference elementTypeExpectation, ITypeComputationState state)
protected LightweightTypeReference getElementOrComponentType(LightweightTypeReference iterableOrArray, ITypeComputationState state)
protected LightweightTypeReference getElementOrComponentType(LightweightTypeReference iterableOrArray, ITypeReferenceOwner owner)
ElementOrComponentTypeComputer.compute(LightweightTypeReference, ITypeReferenceOwner)
.
Clients may override.