Class UnboundTypeReference
- java.lang.Object
-
- org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
-
- org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference
-
public class UnboundTypeReference extends LightweightTypeReference
A type reference that points to a type parameter that is not yet resolved.UnboundTypeReferenceshould be created with a concreteITypeExpectationvia the factory methodITypeExpectation.createUnboundTypeReference(XExpression, JvmTypeParameter)orcreate(ITypeExpectation, XExpression, JvmTypeParameter)respectively. Such type references may be produced in cases likeval x = newArrayListwherexhas the inferred typeArrayList<Unbound[E]>. Unbound types may be enhanced withhintsto allow the type inferrer to find the most suitable type.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
LightweightTypeReference.IdentifierFunction, LightweightTypeReference.JavaIdentifierFunction, LightweightTypeReference.SimpleNameFunction, LightweightTypeReference.UniqueIdentifierFunction
-
-
Field Summary
-
Fields inherited from class org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
KIND_ANY_TYPE_REFERENCE, KIND_ARRAY_TYPE_REFERENCE, KIND_COMPOUND_TYPE_REFERENCE, KIND_FUNCTION_TYPE_REFERENCE, KIND_INNER_FUNCTION_TYPE_REFERENCE, KIND_INNER_TYPE_REFERENCE, KIND_LIGHTWEIGHT_TYPE_REFERENCE, KIND_PARAMETERIZED_TYPE_REFERENCE, KIND_UNBOUND_TYPE_REFERENCE, KIND_UNKNOWN_TYPE_REFERENCE, KIND_WILDCARD_TYPE_REFERENCE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)protectedUnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter, java.lang.Object handle)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(TypeReferenceVisitor visitor)<Param> voidaccept(TypeReferenceVisitorWithParameter<Param> visitor, Param param)<Param,Result>
Resultaccept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor, Param param)<Result> Resultaccept(TypeReferenceVisitorWithResult<Result> visitor)voidacceptHint(LightweightBoundTypeArgument hint)voidacceptHint(LightweightTypeReference hint, BoundTypeArgumentSource source, java.lang.Object origin, VarianceInfo expectedVariance, VarianceInfo actualVariance)Attach a resolution hint to this unbound type reference.voidacceptHint(VarianceInfo variance)booleancanResolveTo(LightweightTypeReference reference)Returns true if the existing hints would allow to resolve to the given reference.protected booleancanResolveTo(LightweightTypeReference reference, java.util.List<LightweightBoundTypeArgument> allHints)LightweightTypeReferencecopyInto(ITypeReferenceOwner owner)Always copies the reference since we want to reduce the nesting level of references if this one was resolved but points to something unresolved.static UnboundTypeReferencecreate(ITypeExpectation expectation, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)Create a new, managed unbound type reference for the given type parameter which was first encountered for the given expression.protected UnboundTypeReferencecreateCopy(ITypeReferenceOwner owner)protected LightweightTypeReferencedoCopyInto(ITypeReferenceOwner owner)booleanequalHandles(UnboundTypeReference reference)java.util.List<LightweightBoundTypeArgument>getAllHints()LightweightTypeReferencegetComponentType()Returns the component type of the current array type.LightweightTypeReferencegetConstraintSubstitute()Returns the constraint type of this reference.XExpressiongetExpression()FunctionTypeKindgetFunctionTypeKind()java.lang.ObjectgetHandle()Returns the identifying handle for this reference.java.lang.StringgetIdentifier()Returns the identifier of this type reference.LightweightTypeReferencegetInvariantBoundSubstitute()Returns the invariant bound of this reference.java.lang.StringgetJavaIdentifier()intgetKind()Subclasses must override this method.LightweightTypeReferencegetLowerBoundSubstitute()Returns the lower bound of this reference.java.util.List<LightweightTypeReference>getMultiTypeComponents()LightweightTypeReferencegetPrimitiveIfWrapperType()org.eclipse.xtext.common.types.util.Primitives.PrimitivegetPrimitiveKind()org.eclipse.xtext.common.types.util.Primitives.PrimitivegetPrimitiveKindIfWrapperType()LightweightTypeReferencegetResolvedTo()Returns the resolved reference for this unbound reference.java.lang.StringgetSimpleName()Prints the simple name of this type reference.LightweightTypeReferencegetSuperType(java.lang.Class<?> rawType)Returns the resolved super type for the given raw type ornullif the raw type is not a valid super type of this type.LightweightTypeReferencegetSuperType(org.eclipse.xtext.common.types.JvmType rawType)Returns the resolved super type for the given raw type or null if the raw type is not a valid super type of this type.protected java.util.List<LightweightTypeReference>getSuperTypes(TypeParameterSubstitutor<?> substitutor)org.eclipse.xtext.common.types.JvmTypegetType()java.util.List<LightweightTypeReference>getTypeArguments()Returns the type arguments of this reference if it has any.org.eclipse.xtext.common.types.JvmTypeParametergetTypeParameter()java.lang.StringgetUniqueIdentifier()Returns an identifier that allows to disambiguate type parameter names that have different origins.LightweightTypeReferencegetUpperBoundSubstitute()Returns the upper bound of this reference.LightweightTypeReferencegetWrapperTypeIfPrimitive()booleanhasSignificantHints()booleanhasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints)protected booleanhasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints, boolean constraintsAreSignificant)booleanhasTypeArguments()LightweightTypeReferenceinternalGetResolvedTo()booleaninternalIsResolved()booleanisAnonymous()booleanisAny()booleanisArray()booleanisInterfaceType()booleanisMultiType()booleanisPrimitive()booleanisPrimitiveVoid()booleanisRawType()Returnstrueis this type points to a raw type.booleanisResolved()booleanisSynonym()booleanisType(java.lang.Class<?> clazz)Returns true if this type reference represents an type with the given raw typeclazz.booleanisUnknown()booleanisVisible(IVisibilityHelper visibilityHelper)Returnstrueif this type is fully visible according to the givenvisibilityHelper.booleanisWildcard()booleanisWrapper()protected voidpropageResolvedTypeToConstraints(java.util.List<LightweightBoundTypeArgument> hints)LightweightTypeReferenceresolve()Force this reference to be resolved.protected voidresolveAgainstConstraints()protected booleanresolveWithHints(java.util.List<LightweightBoundTypeArgument> allHints)org.eclipse.xtext.common.types.JvmTypeReferencetoJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)Converts this type reference to aJvmTypeReferencethat can be used in Java source code.LightweightTypeReferencetoJavaType()Converts types to references that can be expressed as Java type references in source code.org.eclipse.xtext.common.types.JvmTypeReferencetoTypeReference()ArrayTypeReferencetryConvertToArray()Returns the array representation of this reference if its represents a subtype ofIterableor already an array itself.FunctionTypeReferencetryConvertToFunctionTypeReference(boolean rawType)Converts this reference to aFunctionTypeReferenceif the referenced type is a SAM type.LightweightTypeReferencetryConvertToListType()Returns the list representation of this reference if it represents an array or is already a subtype ofList.voidtryResolve()Try to resolve this reference iff there are hints available.voidtryResolve(boolean constraintsAreSignificant)Try to resolve this reference iff there are hints available.-
Methods inherited from class org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
collectSuperTypes, collectSuperTypes, createSubstitutor, expose, findNonNullType, findType, getAllSuperTypes, getAsFunctionTypeReference, getHumanReadableName, getNamedType, getNonInterfaceTypes, getOuter, getOwner, getRawTypeReference, getRawTypes, getServices, getSuperTypes, getTypesFactory, getUniqueIdentifier, internalFindTopLevelType, internalIsAssignableFrom, isAssignableFrom, isAssignableFrom, isAssignableFrom, isAssignableFrom, isFunctionType, isOwnedBy, isSubtypeOf, isSubtypeOf, isValidHint, toJavaCompliantTypeReference, toJavaCompliantTypeReference, toString
-
-
-
-
Constructor Detail
-
UnboundTypeReference
protected UnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)
-
UnboundTypeReference
protected UnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter, java.lang.Object handle)
-
-
Method Detail
-
create
public static UnboundTypeReference create(ITypeExpectation expectation, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)
Create a new, managed unbound type reference for the given type parameter which was first encountered for the given expression.- Parameters:
expression- the expression that used / referenced the type parametertypeParameter- the type parameterexpectation- the decision path that uses the type parameter
-
getKind
public int getKind()
Subclasses must override this method.- Overrides:
getKindin classLightweightTypeReference
-
getExpression
public XExpression getExpression()
-
createCopy
protected UnboundTypeReference createCopy(ITypeReferenceOwner owner)
-
tryResolve
public void tryResolve()
Try to resolve this reference iff there are hints available. May be invoked multiple times since it will simply returns if the reference is already resolved. This is fully equivalent totryResolve(true).- See Also:
tryResolve(boolean)
-
tryResolve
public void tryResolve(boolean constraintsAreSignificant)
Try to resolve this reference iff there are hints available. May be invoked multiple times since it will simply returns if the reference is already resolved. The caller can decide whether type constraints are considered to be significant hints or not.
-
canResolveTo
public boolean canResolveTo(LightweightTypeReference reference)
Returns true if the existing hints would allow to resolve to the given reference.
-
hasSignificantHints
public boolean hasSignificantHints()
-
hasSignificantHints
public boolean hasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints)
-
hasSignificantHints
protected boolean hasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints, boolean constraintsAreSignificant)
-
toTypeReference
public org.eclipse.xtext.common.types.JvmTypeReference toTypeReference()
- Specified by:
toTypeReferencein classLightweightTypeReference
-
toJavaCompliantTypeReference
public org.eclipse.xtext.common.types.JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
Description copied from class:LightweightTypeReferenceConverts this type reference to aJvmTypeReferencethat can be used in Java source code.- Specified by:
toJavaCompliantTypeReferencein classLightweightTypeReference
-
isRawType
public boolean isRawType()
Description copied from class:LightweightTypeReferenceReturnstrueis this type points to a raw type. That is, it points to a parameterized type but does not define type arguments or it points to an external type parameter that has a raw type constraint. Type parameters that are declared by the current owner are not considered to be raw types. A type is also a raw type if it inherits from a raw type.- Overrides:
isRawTypein classLightweightTypeReference
-
isAnonymous
public boolean isAnonymous()
- Overrides:
isAnonymousin classLightweightTypeReference
-
getTypeParameter
public org.eclipse.xtext.common.types.JvmTypeParameter getTypeParameter()
-
getHandle
public java.lang.Object getHandle()
Returns the identifying handle for this reference.- See Also:
handle
-
getResolvedTo
public LightweightTypeReference getResolvedTo()
Returns the resolved reference for this unbound reference. It does not try to resolve this reference but only returns the resolved representation if this one was resolved by other clients explicitly.- Returns:
- the resolved reference or
null.
-
getUpperBoundSubstitute
public LightweightTypeReference getUpperBoundSubstitute()
Description copied from class:LightweightTypeReferenceReturns the upper bound of this reference. The upper bound of a wildcard reference is its upper constraint, e.g.? extends CharSequencehas the upper boundCharSequence.- Overrides:
getUpperBoundSubstitutein classLightweightTypeReference
-
getLowerBoundSubstitute
public LightweightTypeReference getLowerBoundSubstitute()
Description copied from class:LightweightTypeReferenceReturns the lower bound of this reference. The lower bound of a wildcard reference is its lower constraint, e.g.? super CharSequencehas the upper boundCharSequence.- Overrides:
getLowerBoundSubstitutein classLightweightTypeReference
-
getInvariantBoundSubstitute
public LightweightTypeReference getInvariantBoundSubstitute()
Description copied from class:LightweightTypeReferenceReturns the invariant bound of this reference. The invariant bound of a wildcard reference is its lower constraint, if any. Otherwise it's the upper bound.- Overrides:
getInvariantBoundSubstitutein classLightweightTypeReference
-
getConstraintSubstitute
public LightweightTypeReference getConstraintSubstitute()
Description copied from class:LightweightTypeReferenceReturns the constraint type of this reference. The constraint of a type parameter is its declared super type.T extends CharSequence & Serializablehas a compound constraint substitute of the formCharSequence & Serializable.- Overrides:
getConstraintSubstitutein classLightweightTypeReference
-
resolve
public LightweightTypeReference resolve()
Force this reference to be resolved. If not hints are available, the reference is resolved to the constraints of the type parameters.- Returns:
- the resolved representation. Never
null.
-
resolveAgainstConstraints
protected void resolveAgainstConstraints()
-
canResolveTo
protected boolean canResolveTo(LightweightTypeReference reference, java.util.List<LightweightBoundTypeArgument> allHints)
-
resolveWithHints
protected boolean resolveWithHints(java.util.List<LightweightBoundTypeArgument> allHints)
-
propageResolvedTypeToConstraints
protected void propageResolvedTypeToConstraints(java.util.List<LightweightBoundTypeArgument> hints)
-
copyInto
public LightweightTypeReference copyInto(ITypeReferenceOwner owner)
Always copies the reference since we want to reduce the nesting level of references if this one was resolved but points to something unresolved. In that case, we only want to copy the remaining unresolved parts. Otherwise we copy this reference.- Overrides:
copyIntoin classLightweightTypeReference
-
isResolved
public boolean isResolved()
- Overrides:
isResolvedin classLightweightTypeReference
-
internalIsResolved
public boolean internalIsResolved()
-
internalGetResolvedTo
public LightweightTypeReference internalGetResolvedTo()
-
getTypeArguments
public java.util.List<LightweightTypeReference> getTypeArguments()
Description copied from class:LightweightTypeReferenceReturns the type arguments of this reference if it has any. The type argument ofList<String>isString.is also the type argument of a wildcard reference with upper bound ? extends List<String>. Raw types don't carry type arguments. Wildcards with more than one upper bound don't carry type arguments.- Overrides:
getTypeArgumentsin classLightweightTypeReference
-
hasTypeArguments
public boolean hasTypeArguments()
- Overrides:
hasTypeArgumentsin classLightweightTypeReference
-
isArray
public boolean isArray()
- Overrides:
isArrayin classLightweightTypeReference
-
isVisible
public boolean isVisible(IVisibilityHelper visibilityHelper)
Description copied from class:LightweightTypeReferenceReturnstrueif this type is fully visible according to the givenvisibilityHelper. All components and bounds are taken into account, e.g.arraysuse theircomponent typeandgenerified typescheck their type arguments, too.- Specified by:
isVisiblein classLightweightTypeReference
-
isAny
public boolean isAny()
- Overrides:
isAnyin classLightweightTypeReference
-
isUnknown
public boolean isUnknown()
- Overrides:
isUnknownin classLightweightTypeReference
-
getFunctionTypeKind
public FunctionTypeKind getFunctionTypeKind()
- Overrides:
getFunctionTypeKindin classLightweightTypeReference
-
tryConvertToArray
public ArrayTypeReference tryConvertToArray()
Description copied from class:LightweightTypeReferenceReturns the array representation of this reference if its represents a subtype ofIterableor already an array itself. If the iterable's type is a primitive wrapper, the array is not the primitive array but the wrapper array. May returnnullif the conversion is not possible.- Overrides:
tryConvertToArrayin classLightweightTypeReference- Returns:
- an equivalent
ArrayTypeReferenceornull.
-
tryConvertToFunctionTypeReference
public FunctionTypeReference tryConvertToFunctionTypeReference(boolean rawType)
Description copied from class:LightweightTypeReferenceConverts this reference to aFunctionTypeReferenceif the referenced type is a SAM type. Returnsnullif this reference does not point to a valid function type.- Overrides:
tryConvertToFunctionTypeReferencein classLightweightTypeReference- Parameters:
rawType- if a raw view on the function type is sufficient.- See Also:
LightweightTypeReference.getAsFunctionTypeReference()
-
tryConvertToListType
public LightweightTypeReference tryConvertToListType()
Description copied from class:LightweightTypeReferenceReturns the list representation of this reference if it represents an array or is already a subtype ofList. If the array's type is a primitive, the list's element type is the wrapper. May returnnullif the conversion is not possible.- Overrides:
tryConvertToListTypein classLightweightTypeReference- Returns:
- an equivalent list type or
null.
-
getComponentType
public LightweightTypeReference getComponentType()
Description copied from class:LightweightTypeReferenceReturns the component type of the current array type. Does not attempt to convert this reference from iterable to array, first.- Overrides:
getComponentTypein classLightweightTypeReference- Returns:
- the compoent type of the current array or
null. - See Also:
LightweightTypeReference.isArray()
-
isWrapper
public boolean isWrapper()
- Overrides:
isWrapperin classLightweightTypeReference
-
isPrimitive
public boolean isPrimitive()
- Overrides:
isPrimitivein classLightweightTypeReference
-
getPrimitiveKind
public org.eclipse.xtext.common.types.util.Primitives.Primitive getPrimitiveKind()
- Overrides:
getPrimitiveKindin classLightweightTypeReference
-
getPrimitiveKindIfWrapperType
public org.eclipse.xtext.common.types.util.Primitives.Primitive getPrimitiveKindIfWrapperType()
- Overrides:
getPrimitiveKindIfWrapperTypein classLightweightTypeReference
-
isPrimitiveVoid
public boolean isPrimitiveVoid()
- Overrides:
isPrimitiveVoidin classLightweightTypeReference
-
isInterfaceType
public boolean isInterfaceType()
- Overrides:
isInterfaceTypein classLightweightTypeReference
-
getPrimitiveIfWrapperType
public LightweightTypeReference getPrimitiveIfWrapperType()
- Overrides:
getPrimitiveIfWrapperTypein classLightweightTypeReference
-
getType
public org.eclipse.xtext.common.types.JvmType getType()
- Specified by:
getTypein classLightweightTypeReference
-
isType
public boolean isType(java.lang.Class<?> clazz)
Description copied from class:LightweightTypeReferenceReturns true if this type reference represents an type with the given raw typeclazz. Returns false if this is not exactly the given type, but a sub type, a super type or a completely unrelated type.- Specified by:
isTypein classLightweightTypeReference
-
getSuperTypes
protected java.util.List<LightweightTypeReference> getSuperTypes(TypeParameterSubstitutor<?> substitutor)
- Specified by:
getSuperTypesin classLightweightTypeReference
-
getSuperType
public LightweightTypeReference getSuperType(org.eclipse.xtext.common.types.JvmType rawType)
Description copied from class:LightweightTypeReferenceReturns the resolved super type for the given raw type or null if the raw type is not a valid super type of this type.- Overrides:
getSuperTypein classLightweightTypeReference- Parameters:
rawType- the raw type that should be resolved.- Returns:
- the resolved super type.
-
getSuperType
public LightweightTypeReference getSuperType(java.lang.Class<?> rawType)
Description copied from class:LightweightTypeReferenceReturns the resolved super type for the given raw type ornullif the raw type is not a valid super type of this type.- Overrides:
getSuperTypein classLightweightTypeReference- Parameters:
rawType- the raw type that should be resolved.- Returns:
- the resolved super type.
-
getWrapperTypeIfPrimitive
public LightweightTypeReference getWrapperTypeIfPrimitive()
- Overrides:
getWrapperTypeIfPrimitivein classLightweightTypeReference
-
doCopyInto
protected LightweightTypeReference doCopyInto(ITypeReferenceOwner owner)
- Specified by:
doCopyIntoin classLightweightTypeReference
-
getSimpleName
public java.lang.String getSimpleName()
Description copied from class:LightweightTypeReferencePrints the simple name of this type reference. Useful for testing.- Specified by:
getSimpleNamein classLightweightTypeReference
-
getIdentifier
public java.lang.String getIdentifier()
Description copied from class:LightweightTypeReferenceReturns the identifier of this type reference. Usually the qualified name with a dollar delimiter.- Specified by:
getIdentifierin classLightweightTypeReference
-
getUniqueIdentifier
public java.lang.String getUniqueIdentifier()
Description copied from class:LightweightTypeReferenceReturns an identifier that allows to disambiguate type parameter names that have different origins. Rather than just giving the name of the type parameter, it also prints the declarator.- Specified by:
getUniqueIdentifierin classLightweightTypeReference
-
getJavaIdentifier
public java.lang.String getJavaIdentifier()
- Specified by:
getJavaIdentifierin classLightweightTypeReference
-
accept
public void accept(TypeReferenceVisitor visitor)
- Overrides:
acceptin classLightweightTypeReference
-
accept
public <Param> void accept(TypeReferenceVisitorWithParameter<Param> visitor, Param param)
- Overrides:
acceptin classLightweightTypeReference
-
accept
public <Result> Result accept(TypeReferenceVisitorWithResult<Result> visitor)
- Overrides:
acceptin classLightweightTypeReference
-
accept
public <Param,Result> Result accept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor, Param param)
- Overrides:
acceptin classLightweightTypeReference
-
acceptHint
public void acceptHint(VarianceInfo variance)
-
acceptHint
public void acceptHint(LightweightTypeReference hint, BoundTypeArgumentSource source, java.lang.Object origin, VarianceInfo expectedVariance, VarianceInfo actualVariance)
Attach a resolution hint to this unbound type reference.
Only
validhints can be accepted. The given source indicates the quality of this hint. Thevariancesindicate how the hint was used and how it was expected to be used. A hint from a co-variant location may not have the same impact for a contra-variant usage as a contra-variant hint. Consider a return type of a method
and its usage<T> Collection<? extends T> m(..) { }Collection<? super CharSequence> variable = m(..)The hint that stems from the variable declaration may not be very useful since the variances are not compatible. Nevertheless, it can be accepted to produce better error messages.
- Parameters:
hint- the reference that provides the hint.source- the source of this hint, e.g. an inferred hint, or an expectation.origin- the object that produced the hint. Only for debugging purpose to trace the origin of a hint.expectedVariance- the expected variance, e.g. where this unbound type reference is used.actualVariance- how the hint is used.- See Also:
LightweightTypeReference.isValidHint()
-
acceptHint
public void acceptHint(LightweightBoundTypeArgument hint)
-
getAllHints
public java.util.List<LightweightBoundTypeArgument> getAllHints()
-
equalHandles
public boolean equalHandles(UnboundTypeReference reference)
-
isWildcard
public boolean isWildcard()
- Overrides:
isWildcardin classLightweightTypeReference
-
isMultiType
public boolean isMultiType()
- Overrides:
isMultiTypein classLightweightTypeReference
-
isSynonym
public boolean isSynonym()
- Overrides:
isSynonymin classLightweightTypeReference
-
toJavaType
public LightweightTypeReference toJavaType()
Description copied from class:LightweightTypeReferenceConverts types to references that can be expressed as Java type references in source code. Any types will be expressed as Object whereas multi types will be expressed as their common super type. Unknown types are considered to be ok thus returned as is.- Overrides:
toJavaTypein classLightweightTypeReference
-
getMultiTypeComponents
public java.util.List<LightweightTypeReference> getMultiTypeComponents()
- Overrides:
getMultiTypeComponentsin classLightweightTypeReference
-
-