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 class
LightweightTypeReference.IdentifierFunction
static class
LightweightTypeReference.JavaIdentifierFunction
static class
LightweightTypeReference.SimpleNameFunction
static class
LightweightTypeReference.UniqueIdentifierFunction
-
Field Summary
Fields Modifier and Type Field Description static int
KIND_ANY_TYPE_REFERENCE
static int
KIND_ARRAY_TYPE_REFERENCE
static int
KIND_COMPOUND_TYPE_REFERENCE
static int
KIND_FUNCTION_TYPE_REFERENCE
static int
KIND_INNER_FUNCTION_TYPE_REFERENCE
static int
KIND_INNER_TYPE_REFERENCE
static int
KIND_LIGHTWEIGHT_TYPE_REFERENCE
static int
KIND_PARAMETERIZED_TYPE_REFERENCE
static int
KIND_UNBOUND_TYPE_REFERENCE
static int
KIND_UNKNOWN_TYPE_REFERENCE
static int
KIND_WILDCARD_TYPE_REFERENCE
-
Constructor Summary
Constructors Modifier Constructor Description protected
LightweightTypeReference(ITypeReferenceOwner owner)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
accept(TypeReferenceVisitor visitor)
<Param> void
accept(TypeReferenceVisitorWithParameter<Param> visitor, Param param)
<Param,Result>
Resultaccept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor, Param param)
<Result> Result
accept(TypeReferenceVisitorWithResult<Result> visitor)
protected void
collectSuperTypes(int level, java.util.List<LightweightTypeReference> references, TypeParameterSubstitutor<?> substitutor, SuperTypeAcceptor acceptor, java.util.Set<org.eclipse.xtext.common.types.JvmType> seenTypes)
void
collectSuperTypes(SuperTypeAcceptor acceptor)
LightweightTypeReference
copyInto(ITypeReferenceOwner owner)
protected TypeParameterSubstitutor<?>
createSubstitutor()
protected abstract LightweightTypeReference
doCopyInto(ITypeReferenceOwner owner)
protected <T> java.util.List<T>
expose(java.util.List<T> list)
protected org.eclipse.xtext.common.types.JvmType
findNonNullType(java.lang.Class<?> type)
protected org.eclipse.xtext.common.types.JvmType
findType(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.FunctionTypeReference
getAsFunctionTypeReference()
Returns the equivalentFunctionTypeReference
if this reference points to afunction
orprocedure
or if it is already a function type reference.LightweightTypeReference
getComponentType()
Returns the component type of the current array type.LightweightTypeReference
getConstraintSubstitute()
Returns the constraint type of this reference.FunctionTypeKind
getFunctionTypeKind()
java.lang.String
getHumanReadableName()
Prints a human readable name of this type reference.abstract java.lang.String
getIdentifier()
Returns the identifier of this type reference.LightweightTypeReference
getInvariantBoundSubstitute()
Returns the invariant bound of this reference.abstract java.lang.String
getJavaIdentifier()
int
getKind()
Subclasses must override this method.LightweightTypeReference
getLowerBoundSubstitute()
Returns the lower bound of this reference.java.util.List<LightweightTypeReference>
getMultiTypeComponents()
LightweightTypeReference
getNamedType()
Returns the named type if this is an anonymous type.protected java.util.List<LightweightTypeReference>
getNonInterfaceTypes(java.util.List<LightweightTypeReference> components)
LightweightTypeReference
getOuter()
ITypeReferenceOwner
getOwner()
LightweightTypeReference
getPrimitiveIfWrapperType()
org.eclipse.xtext.common.types.util.Primitives.Primitive
getPrimitiveKind()
org.eclipse.xtext.common.types.util.Primitives.Primitive
getPrimitiveKindIfWrapperType()
LightweightTypeReference
getRawTypeReference()
java.util.List<org.eclipse.xtext.common.types.JvmType>
getRawTypes()
protected CommonTypeComputationServices
getServices()
abstract java.lang.String
getSimpleName()
Prints the simple name of this type reference.LightweightTypeReference
getSuperType(java.lang.Class<?> rawType)
Returns the resolved super type for the given raw type ornull
if the raw type is not a valid super type of this type.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.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.JvmType
getType()
java.util.List<LightweightTypeReference>
getTypeArguments()
Returns the type arguments of this reference if it has any.protected org.eclipse.xtext.common.types.TypesFactory
getTypesFactory()
abstract java.lang.String
getUniqueIdentifier()
Returns an identifier that allows to disambiguate type parameter names that have different origins.protected java.lang.String
getUniqueIdentifier(org.eclipse.xtext.common.types.JvmType type)
LightweightTypeReference
getUpperBoundSubstitute()
Returns the upper bound of this reference.LightweightTypeReference
getWrapperTypeIfPrimitive()
boolean
hasTypeArguments()
protected LightweightTypeReference
internalFindTopLevelType(java.lang.Class<?> rawType)
int
internalIsAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument)
boolean
isAnonymous()
boolean
isAny()
boolean
isArray()
boolean
isAssignableFrom(java.lang.Class<?> clazz)
Determines if this type reference denotes the same type or a supertype of the givenclazz
.boolean
isAssignableFrom(org.eclipse.xtext.common.types.JvmType type)
Determines if this type reference denotes the same type or a supertype of the giventype
.boolean
isAssignableFrom(LightweightTypeReference reference)
Determines if this type reference denotes the same or a supertype of the givenreference
.boolean
isAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument)
boolean
isFunctionType()
boolean
isInterfaceType()
boolean
isMultiType()
boolean
isOwnedBy(ITypeReferenceOwner owner)
boolean
isPrimitive()
boolean
isPrimitiveVoid()
boolean
isRawType()
Returnstrue
is this type points to a raw type.boolean
isResolved()
boolean
isSubtypeOf(java.lang.Class<?> clazz)
Determines if this type reference denotes the same type or a subtype of the givenclazz
.boolean
isSubtypeOf(org.eclipse.xtext.common.types.JvmType type)
Determines if this type reference denotes the same type or a subtype of the giventype
.boolean
isSynonym()
abstract boolean
isType(java.lang.Class<?> clazz)
Returns true if this type reference represents an type with the given raw typeclazz
.boolean
isUnknown()
boolean
isValidHint()
abstract boolean
isVisible(IVisibilityHelper visibilityHelper)
Returnstrue
if this type is fully visible according to the givenvisibilityHelper
.boolean
isWildcard()
boolean
isWrapper()
org.eclipse.xtext.common.types.JvmTypeReference
toJavaCompliantTypeReference()
Converts this type reference to aJvmTypeReference
that can be used in Java source code.protected org.eclipse.xtext.common.types.JvmTypeReference
toJavaCompliantTypeReference(java.util.List<LightweightTypeReference> types, IVisibilityHelper visibilityHelper)
abstract org.eclipse.xtext.common.types.JvmTypeReference
toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
Converts this type reference to aJvmTypeReference
that can be used in Java source code.LightweightTypeReference
toJavaType()
Converts types to references that can be expressed as Java type references in source code.java.lang.String
toString()
abstract org.eclipse.xtext.common.types.JvmTypeReference
toTypeReference()
ArrayTypeReference
tryConvertToArray()
Returns the array representation of this reference if its represents a subtype ofIterable
or already an array itself.FunctionTypeReference
tryConvertToFunctionTypeReference(boolean rawType)
Converts this reference to aFunctionTypeReference
if the referenced type is a SAM type.LightweightTypeReference
tryConvertToListType()
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 aJvmTypeReference
that can be used in Java source code.
-
isVisible
public abstract boolean isVisible(IVisibilityHelper visibilityHelper)
Returnstrue
if this type is fully visible according to the givenvisibilityHelper
. All components and bounds are taken into account, e.g.arrays
use theircomponent type
andgenerified types
check their type arguments, too.
-
toJavaCompliantTypeReference
public abstract org.eclipse.xtext.common.types.JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
Converts this type reference to aJvmTypeReference
that 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 CharSequence
has 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 CharSequence
has 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 & Serializable
has a compound constraint substitute of the formCharSequence & Serializable
.
-
isRawType
public boolean isRawType()
Returnstrue
is 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 returnnull
if 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 ornull
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.
-
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:
toString
in 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 equivalentFunctionTypeReference
if this reference points to afunction
orprocedure
or if it is already a function type reference. Otherwise returnsnull
.
-
tryConvertToFunctionTypeReference
public FunctionTypeReference tryConvertToFunctionTypeReference(boolean rawType)
Converts this reference to aFunctionTypeReference
if the referenced type is a SAM type. Returnsnull
if 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 ofIterable
or 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 returnnull
if the conversion is not possible.- Returns:
- an equivalent
ArrayTypeReference
ornull
.
-
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()
-
-