Class LightweightTypeReference
- java.lang.Object
-
- org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
-
- Direct Known Subclasses:
AnyTypeReference,ArrayTypeReference,CompoundTypeReference,ParameterizedTypeReference,UnboundTypeReference,UnknownTypeReference,WildcardTypeReference
public abstract class LightweightTypeReference extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLightweightTypeReference.IdentifierFunctionstatic classLightweightTypeReference.JavaIdentifierFunctionstatic classLightweightTypeReference.SimpleNameFunctionstatic classLightweightTypeReference.UniqueIdentifierFunction
-
Field Summary
Fields Modifier and Type Field Description static intKIND_ANY_TYPE_REFERENCEstatic intKIND_ARRAY_TYPE_REFERENCEstatic intKIND_COMPOUND_TYPE_REFERENCEstatic intKIND_FUNCTION_TYPE_REFERENCEstatic intKIND_INNER_FUNCTION_TYPE_REFERENCEstatic intKIND_INNER_TYPE_REFERENCEstatic intKIND_LIGHTWEIGHT_TYPE_REFERENCEstatic intKIND_PARAMETERIZED_TYPE_REFERENCEstatic intKIND_UNBOUND_TYPE_REFERENCEstatic intKIND_UNKNOWN_TYPE_REFERENCEstatic intKIND_WILDCARD_TYPE_REFERENCE
-
Constructor Summary
Constructors Modifier Constructor Description protectedLightweightTypeReference(ITypeReferenceOwner owner)
-
Method Summary
All Methods Instance Methods Abstract 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)protected voidcollectSuperTypes(int level, java.util.List<LightweightTypeReference> references, TypeParameterSubstitutor<?> substitutor, SuperTypeAcceptor acceptor, java.util.Set<org.eclipse.xtext.common.types.JvmType> seenTypes)voidcollectSuperTypes(SuperTypeAcceptor acceptor)LightweightTypeReferencecopyInto(ITypeReferenceOwner owner)protected TypeParameterSubstitutor<?>createSubstitutor()protected abstract LightweightTypeReferencedoCopyInto(ITypeReferenceOwner owner)protected <T> java.util.List<T>expose(java.util.List<T> list)protected org.eclipse.xtext.common.types.JvmTypefindNonNullType(java.lang.Class<?> type)protected org.eclipse.xtext.common.types.JvmTypefindType(java.lang.Class<?> type)java.util.List<LightweightTypeReference>getAllSuperTypes()Returns the list of all super types which includes the super class and the implemented interfaces.FunctionTypeReferencegetAsFunctionTypeReference()Returns the equivalentFunctionTypeReferenceif this reference points to afunctionorprocedureor if it is already a function type reference.LightweightTypeReferencegetComponentType()Returns the component type of the current array type.LightweightTypeReferencegetConstraintSubstitute()Returns the constraint type of this reference.FunctionTypeKindgetFunctionTypeKind()java.lang.StringgetHumanReadableName()Prints a human readable name of this type reference.abstract java.lang.StringgetIdentifier()Returns the identifier of this type reference.LightweightTypeReferencegetInvariantBoundSubstitute()Returns the invariant bound of this reference.abstract java.lang.StringgetJavaIdentifier()intgetKind()Subclasses must override this method.LightweightTypeReferencegetLowerBoundSubstitute()Returns the lower bound of this reference.java.util.List<LightweightTypeReference>getMultiTypeComponents()LightweightTypeReferencegetNamedType()Returns the named type if this is an anonymous type.protected java.util.List<LightweightTypeReference>getNonInterfaceTypes(java.util.List<LightweightTypeReference> components)LightweightTypeReferencegetOuter()ITypeReferenceOwnergetOwner()LightweightTypeReferencegetPrimitiveIfWrapperType()org.eclipse.xtext.common.types.util.Primitives.PrimitivegetPrimitiveKind()org.eclipse.xtext.common.types.util.Primitives.PrimitivegetPrimitiveKindIfWrapperType()LightweightTypeReferencegetRawTypeReference()java.util.List<org.eclipse.xtext.common.types.JvmType>getRawTypes()protected CommonTypeComputationServicesgetServices()abstract 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.java.util.List<LightweightTypeReference>getSuperTypes()Returns the list of immediate super types which includes the super class and the implemented interfaces.protected abstract java.util.List<LightweightTypeReference>getSuperTypes(TypeParameterSubstitutor<?> substitutor)abstract org.eclipse.xtext.common.types.JvmTypegetType()java.util.List<LightweightTypeReference>getTypeArguments()Returns the type arguments of this reference if it has any.protected org.eclipse.xtext.common.types.TypesFactorygetTypesFactory()abstract java.lang.StringgetUniqueIdentifier()Returns an identifier that allows to disambiguate type parameter names that have different origins.protected java.lang.StringgetUniqueIdentifier(org.eclipse.xtext.common.types.JvmType type)LightweightTypeReferencegetUpperBoundSubstitute()Returns the upper bound of this reference.LightweightTypeReferencegetWrapperTypeIfPrimitive()booleanhasTypeArguments()protected LightweightTypeReferenceinternalFindTopLevelType(java.lang.Class<?> rawType)intinternalIsAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument)booleanisAnonymous()booleanisAny()booleanisArray()booleanisAssignableFrom(java.lang.Class<?> clazz)Determines if this type reference denotes the same type or a supertype of the givenclazz.booleanisAssignableFrom(org.eclipse.xtext.common.types.JvmType type)Determines if this type reference denotes the same type or a supertype of the giventype.booleanisAssignableFrom(LightweightTypeReference reference)Determines if this type reference denotes the same or a supertype of the givenreference.booleanisAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument)booleanisFunctionType()booleanisInterfaceType()booleanisMultiType()booleanisOwnedBy(ITypeReferenceOwner owner)booleanisPrimitive()booleanisPrimitiveVoid()booleanisRawType()Returnstrueis this type points to a raw type.booleanisResolved()booleanisSubtypeOf(java.lang.Class<?> clazz)Determines if this type reference denotes the same type or a subtype of the givenclazz.booleanisSubtypeOf(org.eclipse.xtext.common.types.JvmType type)Determines if this type reference denotes the same type or a subtype of the giventype.booleanisSynonym()abstract booleanisType(java.lang.Class<?> clazz)Returns true if this type reference represents an type with the given raw typeclazz.booleanisUnknown()booleanisValidHint()abstract booleanisVisible(IVisibilityHelper visibilityHelper)Returnstrueif this type is fully visible according to the givenvisibilityHelper.booleanisWildcard()booleanisWrapper()org.eclipse.xtext.common.types.JvmTypeReferencetoJavaCompliantTypeReference()Converts this type reference to aJvmTypeReferencethat can be used in Java source code.protected org.eclipse.xtext.common.types.JvmTypeReferencetoJavaCompliantTypeReference(java.util.List<LightweightTypeReference> types, IVisibilityHelper visibilityHelper)abstract 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.java.lang.StringtoString()abstract 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.
-
-
-
Field Detail
-
KIND_LIGHTWEIGHT_TYPE_REFERENCE
public static final int KIND_LIGHTWEIGHT_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_ANY_TYPE_REFERENCE
public static final int KIND_ANY_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_ARRAY_TYPE_REFERENCE
public static final int KIND_ARRAY_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_COMPOUND_TYPE_REFERENCE
public static final int KIND_COMPOUND_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_PARAMETERIZED_TYPE_REFERENCE
public static final int KIND_PARAMETERIZED_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_UNBOUND_TYPE_REFERENCE
public static final int KIND_UNBOUND_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_UNKNOWN_TYPE_REFERENCE
public static final int KIND_UNKNOWN_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_WILDCARD_TYPE_REFERENCE
public static final int KIND_WILDCARD_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_FUNCTION_TYPE_REFERENCE
public static final int KIND_FUNCTION_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_INNER_TYPE_REFERENCE
public static final int KIND_INNER_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
KIND_INNER_FUNCTION_TYPE_REFERENCE
public static final int KIND_INNER_FUNCTION_TYPE_REFERENCE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LightweightTypeReference
protected LightweightTypeReference(ITypeReferenceOwner owner)
-
-
Method Detail
-
getKind
public int getKind()
Subclasses must override this method.
-
getTypeArguments
public java.util.List<LightweightTypeReference> getTypeArguments()
Returns 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.
-
getOuter
public LightweightTypeReference getOuter()
-
hasTypeArguments
public boolean hasTypeArguments()
-
isResolved
public boolean isResolved()
-
getOwner
public ITypeReferenceOwner getOwner()
-
getTypesFactory
protected org.eclipse.xtext.common.types.TypesFactory getTypesFactory()
-
getServices
protected CommonTypeComputationServices getServices()
-
isOwnedBy
public boolean isOwnedBy(ITypeReferenceOwner owner)
-
expose
protected <T> java.util.List<T> expose(java.util.List<T> list)
-
toTypeReference
public abstract org.eclipse.xtext.common.types.JvmTypeReference toTypeReference()
-
toJavaCompliantTypeReference
public final org.eclipse.xtext.common.types.JvmTypeReference toJavaCompliantTypeReference()
Converts this type reference to aJvmTypeReferencethat can be used in Java source code.
-
isVisible
public abstract boolean isVisible(IVisibilityHelper visibilityHelper)
Returnstrueif 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.
-
toJavaCompliantTypeReference
public abstract org.eclipse.xtext.common.types.JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
Converts this type reference to aJvmTypeReferencethat can be used in Java source code.
-
toJavaCompliantTypeReference
protected org.eclipse.xtext.common.types.JvmTypeReference toJavaCompliantTypeReference(java.util.List<LightweightTypeReference> types, IVisibilityHelper visibilityHelper)
-
getNonInterfaceTypes
protected java.util.List<LightweightTypeReference> getNonInterfaceTypes(java.util.List<LightweightTypeReference> components)
-
getType
public abstract org.eclipse.xtext.common.types.JvmType getType()
-
getWrapperTypeIfPrimitive
public LightweightTypeReference getWrapperTypeIfPrimitive()
-
getPrimitiveIfWrapperType
public LightweightTypeReference getPrimitiveIfWrapperType()
-
getPrimitiveKind
public org.eclipse.xtext.common.types.util.Primitives.Primitive getPrimitiveKind()
-
getPrimitiveKindIfWrapperType
public org.eclipse.xtext.common.types.util.Primitives.Primitive getPrimitiveKindIfWrapperType()
-
getRawTypes
public java.util.List<org.eclipse.xtext.common.types.JvmType> getRawTypes()
-
getRawTypeReference
public LightweightTypeReference getRawTypeReference()
- Returns:
- the erasure type of this type reference
-
getUpperBoundSubstitute
public LightweightTypeReference getUpperBoundSubstitute()
Returns the upper bound of this reference. The upper bound of a wildcard reference is its upper constraint, e.g.? extends CharSequencehas the upper boundCharSequence.
-
getLowerBoundSubstitute
public LightweightTypeReference getLowerBoundSubstitute()
Returns the lower bound of this reference. The lower bound of a wildcard reference is its lower constraint, e.g.? super CharSequencehas the upper boundCharSequence.
-
getInvariantBoundSubstitute
public LightweightTypeReference getInvariantBoundSubstitute()
Returns 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.
-
getConstraintSubstitute
public LightweightTypeReference getConstraintSubstitute()
Returns 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.
-
isRawType
public boolean isRawType()
Returnstrueis 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.
-
isArray
public boolean isArray()
-
isAny
public boolean isAny()
-
isAnonymous
public boolean isAnonymous()
-
getNamedType
public LightweightTypeReference getNamedType()
Returns the named type if this is an anonymous type.
-
isUnknown
public boolean isUnknown()
-
isValidHint
public boolean isValidHint()
-
tryConvertToListType
public LightweightTypeReference tryConvertToListType()
Returns 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.- Returns:
- an equivalent list type or
null.
-
getComponentType
public LightweightTypeReference getComponentType()
Returns the component type of the current array type. Does not attempt to convert this reference from iterable to array, first.- Returns:
- the compoent type of the current array or
null. - See Also:
isArray()
-
getSuperTypes
public java.util.List<LightweightTypeReference> getSuperTypes()
Returns the list of immediate super types which includes the super class and the implemented interfaces. The type parameters of the provided super types are resolved. That means, the super type ofList<String>isCollection<String>rather thanCollection<E>.- Returns:
- the list of super types, can be empty.
-
getSuperType
public LightweightTypeReference getSuperType(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.- Parameters:
rawType- the raw type that should be resolved.- Returns:
- the resolved super type.
-
getSuperType
public LightweightTypeReference getSuperType(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.- Parameters:
rawType- the raw type that should be resolved.- Returns:
- the resolved super type.
-
getAllSuperTypes
public java.util.List<LightweightTypeReference> getAllSuperTypes()
Returns the list of all super types which includes the super class and the implemented interfaces. The type parameters of the provided super types are resolved. That means, the super types ofArrayList<String>includesList<String>andCollection<String>rather thanCollection<E>.- Returns:
- the list of all super types, can be empty.
-
createSubstitutor
protected TypeParameterSubstitutor<?> createSubstitutor()
-
getSuperTypes
protected abstract java.util.List<LightweightTypeReference> getSuperTypes(TypeParameterSubstitutor<?> substitutor)
-
collectSuperTypes
public void collectSuperTypes(SuperTypeAcceptor acceptor)
-
collectSuperTypes
protected void collectSuperTypes(int level, java.util.List<LightweightTypeReference> references, TypeParameterSubstitutor<?> substitutor, SuperTypeAcceptor acceptor, java.util.Set<org.eclipse.xtext.common.types.JvmType> seenTypes)
-
isPrimitive
public boolean isPrimitive()
-
isWrapper
public boolean isWrapper()
-
isPrimitiveVoid
public boolean isPrimitiveVoid()
-
isAssignableFrom
public boolean isAssignableFrom(LightweightTypeReference reference)
Determines if this type reference denotes the same or a supertype of the givenreference.
-
isAssignableFrom
public boolean isAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument)
-
internalIsAssignableFrom
public int internalIsAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument)
-
isAssignableFrom
public boolean isAssignableFrom(java.lang.Class<?> clazz)
Determines if this type reference denotes the same type or a supertype of the givenclazz.
-
isAssignableFrom
public boolean isAssignableFrom(org.eclipse.xtext.common.types.JvmType type)
Determines if this type reference denotes the same type or a supertype of the giventype.
-
isSubtypeOf
public boolean isSubtypeOf(java.lang.Class<?> clazz)
Determines if this type reference denotes the same type or a subtype of the givenclazz.
-
isSubtypeOf
public boolean isSubtypeOf(org.eclipse.xtext.common.types.JvmType type)
Determines if this type reference denotes the same type or a subtype of the giventype.
-
copyInto
public LightweightTypeReference copyInto(ITypeReferenceOwner owner)
-
doCopyInto
protected abstract LightweightTypeReference doCopyInto(ITypeReferenceOwner owner)
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getSimpleName
public abstract java.lang.String getSimpleName()
Prints the simple name of this type reference. Useful for testing.
-
getHumanReadableName
public java.lang.String getHumanReadableName()
Prints a human readable name of this type reference. May be specialized by means of a customimplementation. This is the variant that should be used in the UI.
-
getIdentifier
public abstract java.lang.String getIdentifier()
Returns the identifier of this type reference. Usually the qualified name with a dollar delimiter.
-
getUniqueIdentifier
public abstract java.lang.String getUniqueIdentifier()
Returns 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.
-
getUniqueIdentifier
protected java.lang.String getUniqueIdentifier(org.eclipse.xtext.common.types.JvmType type)
-
getJavaIdentifier
public abstract java.lang.String getJavaIdentifier()
-
findType
protected org.eclipse.xtext.common.types.JvmType findType(java.lang.Class<?> type)
-
internalFindTopLevelType
protected LightweightTypeReference internalFindTopLevelType(java.lang.Class<?> rawType)
- Noreference:
- This method is not intended to be referenced by clients.
-
findNonNullType
protected org.eclipse.xtext.common.types.JvmType findNonNullType(java.lang.Class<?> type)
-
isType
public abstract boolean isType(java.lang.Class<?> clazz)
Returns 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.
-
accept
public void accept(TypeReferenceVisitor visitor)
-
accept
public <Param> void accept(TypeReferenceVisitorWithParameter<Param> visitor, Param param)
-
accept
public <Result> Result accept(TypeReferenceVisitorWithResult<Result> visitor)
-
accept
public <Param,Result> Result accept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor, Param param)
-
isFunctionType
public boolean isFunctionType()
-
isInterfaceType
public boolean isInterfaceType()
-
getFunctionTypeKind
public FunctionTypeKind getFunctionTypeKind()
-
getAsFunctionTypeReference
public FunctionTypeReference getAsFunctionTypeReference()
Returns the equivalentFunctionTypeReferenceif this reference points to afunctionorprocedureor if it is already a function type reference. Otherwise returnsnull.
-
tryConvertToFunctionTypeReference
public FunctionTypeReference tryConvertToFunctionTypeReference(boolean rawType)
Converts this reference to aFunctionTypeReferenceif the referenced type is a SAM type. Returnsnullif this reference does not point to a valid function type.- Parameters:
rawType- if a raw view on the function type is sufficient.- See Also:
getAsFunctionTypeReference()
-
tryConvertToArray
public ArrayTypeReference tryConvertToArray()
Returns 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.- Returns:
- an equivalent
ArrayTypeReferenceornull.
-
isWildcard
public boolean isWildcard()
-
isMultiType
public boolean isMultiType()
-
isSynonym
public boolean isSynonym()
-
toJavaType
public LightweightTypeReference toJavaType()
Converts 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.
-
getMultiTypeComponents
public java.util.List<LightweightTypeReference> getMultiTypeComponents()
-
-