Package gw.internal.gosu.parser
Class TypeVariableType
- java.lang.Object
-
- gw.lang.reflect.AbstractType
-
- gw.internal.gosu.parser.TypeVariableType
-
- All Implemented Interfaces:
INonLoadableType
,IType
,ITypeVariableType
,Serializable
public class TypeVariableType extends AbstractType implements ITypeVariableType
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface gw.lang.reflect.IType
EMPTY_ARRAY, EMPTY_TYPE_ARRAY, EMPTY_TYPE_LIST
-
-
Constructor Summary
Constructors Constructor Description TypeVariableType(ITypeVariableDefinition typeVarDef, boolean forFunction)
TypeVariableType(IType ownersType, IGenericTypeVariable typeVar)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Ok, here's the deal.Set<IType>
getAllTypesInHierarchy()
Returns a Set of all IIntrinsicTypes that this class is assignable from, including this class.Object
getArrayComponent(Object array, int iIndex)
Returns the value of the indexed component in the specified array object.int
getArrayLength(Object array)
Returns the length of the specified array object.IType
getArrayType()
Make an array type from this type.IType
getBoundingType()
IType
getComponentType()
If this is an array type, a type representing the component type of the array.Set<IType>
getCompoundTypeComponents()
String
getDisplayName()
The display name of this intrinsic type.IType
getEnclosingType()
Returns the type immediately enclosing this type.IType
getGenericType()
If this is a parameterized type, returns the generic type this type parameterizes.GenericTypeVariable[]
getGenericTypeVariables()
Returns an array of GenericTypeVariables declared with this Generic Type.IType[]
getInterfaces()
int
getModifiers()
Returns the modifiers for this type, encoded in an integer.String
getName()
The fully qualified name of this intrinsic type.String
getNamespace()
The namespace for this class.String
getNameWithBoundingType()
String
getNameWithEnclosingType()
IType
getParameterizedType(IType... ofType)
Assuming this intrinsic type is a Generic type, return the parameterized type associated with the given list of type parameters.String
getRelativeName()
The relative or unqualified name.IType
getSupertype()
Returns the type representing the supertype of this type.ITypeInfo
getTypeInfo()
Get the type information for this intrinsic type.ITypeLoader
getTypeLoader()
Returns the type loader responsible for loading this intrinsic type.IType[]
getTypeParameters()
If this is a parameterized type, returns the specific types used to create this type, null otherwies.ITypeVariableDefinition
getTypeVarDef()
int
hashCode()
boolean
isAbstract()
boolean
isArray()
True if this is an array.boolean
isAssignableFrom(IType type)
A type variable type is assignable only to/from itself or a reference thereof.boolean
isCompoundType()
boolean
isDiscarded()
True if this type has been replaced with a newer version of the same name in the type system.boolean
isEnum()
Returns true if this type is an enumeration.boolean
isFinal()
True if this type cannot be extended.boolean
isFunctionStatement()
boolean
isGenericType()
Returns true if this ia a Generic Type.boolean
isInterface()
Returns true if this type is an interface.boolean
isMutable()
Are intances of this type mutable?boolean
isParameterizedType()
Returns true if this ia a Parameterized Type.boolean
isPrimitive()
True if this type represents a primitive type e.g., Java int, char, etc.boolean
isValid()
Defines this type if it is not yet fully defined.Object
makeArrayInstance(int iLength)
Construct an array instance of specified length.Object
readResolve()
IType requires this method be implemented to ensure IType instances can be centrally defined and cached.void
setArrayComponent(Object array, int iIndex, Object value)
Sets the value of the indexed component in the specified array object.void
setDiscarded(boolean bDiscarded)
String
toString()
void
unloadTypeInfo()
Unload or nullify any references to this IType's ITypeInfo.-
Methods inherited from class gw.lang.reflect.AbstractType
getLiteralMetaType, getMetaType, getTheRef
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface gw.lang.reflect.IType
compile, getFunctionalInterface, getLiteralMetaType, getMetaType, getSourceFiles, isCompilable, isDynamic
-
-
-
-
Constructor Detail
-
TypeVariableType
public TypeVariableType(ITypeVariableDefinition typeVarDef, boolean forFunction)
-
TypeVariableType
public TypeVariableType(IType ownersType, IGenericTypeVariable typeVar)
-
-
Method Detail
-
getTypeVarDef
public ITypeVariableDefinition getTypeVarDef()
- Specified by:
getTypeVarDef
in interfaceITypeVariableType
-
getName
public String getName()
Description copied from interface:IType
The fully qualified name of this intrinsic type.
-
getDisplayName
public String getDisplayName()
Description copied from interface:IType
The display name of this intrinsic type. Often this is simply the same asIType.getName()
, but in some cases a type may want to modify it's name for presentation to the user.- Specified by:
getDisplayName
in interfaceIType
-
getRelativeName
public String getRelativeName()
Description copied from interface:IType
The relative or unqualified name. For a class this should be just the class name without the package name.- Specified by:
getRelativeName
in interfaceIType
-
getNameWithEnclosingType
public String getNameWithEnclosingType()
- Specified by:
getNameWithEnclosingType
in interfaceITypeVariableType
-
getNameWithBoundingType
public String getNameWithBoundingType()
-
getNamespace
public String getNamespace()
Description copied from interface:IType
The namespace for this class. For a java class this will be the package, while for other types of intrinsic types it could be another logical name.- Specified by:
getNamespace
in interfaceIType
-
getTypeLoader
public ITypeLoader getTypeLoader()
Description copied from interface:IType
Returns the type loader responsible for loading this intrinsic type.- Specified by:
getTypeLoader
in interfaceIType
-
getBoundingType
public IType getBoundingType()
- Specified by:
getBoundingType
in interfaceITypeVariableType
-
isInterface
public boolean isInterface()
Description copied from interface:IType
Returns true if this type is an interface.- Specified by:
isInterface
in interfaceIType
-
isEnum
public boolean isEnum()
Description copied from interface:IType
Returns true if this type is an enumeration.
-
getInterfaces
public IType[] getInterfaces()
- Specified by:
getInterfaces
in interfaceIType
- Returns:
- If this is a class, returns a list of all the interfaces this type implements. Similarly, if this is an interface, returns a list of all the interfaces this type extends. In any case, returns an empty list if this type neither implements nor extends interfaces.
-
getSupertype
public IType getSupertype()
Description copied from interface:IType
Returns the type representing the supertype of this type. Returns null if this type has no supertype.- Specified by:
getSupertype
in interfaceIType
-
getEnclosingType
public IType getEnclosingType()
Description copied from interface:IType
Returns the type immediately enclosing this type. If this type is not enclosed, returns null.- Specified by:
getEnclosingType
in interfaceIType
-
getGenericType
public IType getGenericType()
Description copied from interface:IType
If this is a parameterized type, returns the generic type this type parameterizes. Otherwise, returns null.- Specified by:
getGenericType
in interfaceIType
-
isFinal
public boolean isFinal()
Description copied from interface:IType
True if this type cannot be extended.
-
isParameterizedType
public boolean isParameterizedType()
Description copied from interface:IType
Returns true if this ia a Parameterized Type. Note a Parameterzied Type is not the same as a Generic Type. The difference is that a Parameterized Type is a concrete version of a Generic Type. For instance, the class ArrayListis a Generic Type, while the class ArrayList is a Parameterized Type of the the Generic Type ArrayList . - Specified by:
isParameterizedType
in interfaceIType
-
isGenericType
public boolean isGenericType()
Description copied from interface:IType
Returns true if this ia a Generic Type.- Specified by:
isGenericType
in interfaceIType
- See Also:
IType.isParameterizedType()
-
getGenericTypeVariables
public GenericTypeVariable[] getGenericTypeVariables()
Description copied from interface:IType
Returns an array of GenericTypeVariables declared with this Generic Type. Otherwise, returns null if this is not a Generic Type.- Specified by:
getGenericTypeVariables
in interfaceIType
-
getParameterizedType
public IType getParameterizedType(IType... ofType)
Description copied from interface:IType
Assuming this intrinsic type is a Generic type, return the parameterized type associated with the given list of type parameters. If the type has not been created yet, creates the parameterized type. Successive calls to this method having identical parameter types must return the identical parameterized type.- Specified by:
getParameterizedType
in interfaceIType
- Parameters:
ofType
- The type parameters.- Returns:
- The concrete type associated with the type parameters.
-
getTypeParameters
public IType[] getTypeParameters()
Description copied from interface:IType
If this is a parameterized type, returns the specific types used to create this type, null otherwies.- Specified by:
getTypeParameters
in interfaceIType
-
getAllTypesInHierarchy
public Set<IType> getAllTypesInHierarchy()
Description copied from interface:IType
Returns a Set of all IIntrinsicTypes that this class is assignable from, including this class. This includes implemented interfaces and superclasses, recursively up the hieararchy. For array types, this will be a Set of all types that its component type is assignable from.- Specified by:
getAllTypesInHierarchy
in interfaceIType
-
isArray
public boolean isArray()
Description copied from interface:IType
True if this is an array.
-
isPrimitive
public boolean isPrimitive()
Description copied from interface:IType
True if this type represents a primitive type e.g., Java int, char, etc.- Specified by:
isPrimitive
in interfaceIType
-
getArrayType
public IType getArrayType()
Description copied from interface:IType
Make an array type from this type. E.g., String -> String[]- Specified by:
getArrayType
in interfaceIType
-
makeArrayInstance
public Object makeArrayInstance(int iLength)
Description copied from interface:IType
Construct an array instance of specified length.- Specified by:
makeArrayInstance
in interfaceIType
-
getArrayComponent
public Object getArrayComponent(Object array, int iIndex) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
Description copied from interface:IType
Returns the value of the indexed component in the specified array object.- Specified by:
getArrayComponent
in interfaceIType
- Parameters:
array
- An array instance of this intrinsic type.iIndex
- The index of the component to get.- Returns:
- The value of the indexed component in the specified array.
- Throws:
IllegalArgumentException
- If the specified object is not an array.ArrayIndexOutOfBoundsException
- If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
-
setArrayComponent
public void setArrayComponent(Object array, int iIndex, Object value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
Description copied from interface:IType
Sets the value of the indexed component in the specified array object.- Specified by:
setArrayComponent
in interfaceIType
- Parameters:
array
- An array instance of this intrinsic type.iIndex
- The index of the component to set.value
- The new value of the indexed component.- Throws:
IllegalArgumentException
- If the specified object is not an array.ArrayIndexOutOfBoundsException
- If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
-
getArrayLength
public int getArrayLength(Object array) throws IllegalArgumentException
Description copied from interface:IType
Returns the length of the specified array object.- Specified by:
getArrayLength
in interfaceIType
- Parameters:
array
- An array instance of this intrinsic type.- Returns:
- The length of the array.
- Throws:
IllegalArgumentException
- If the object argument is not an array.
-
getComponentType
public IType getComponentType()
Description copied from interface:IType
If this is an array type, a type representing the component type of the array. Otherwise null.- Specified by:
getComponentType
in interfaceIType
-
isAssignableFrom
public boolean isAssignableFrom(IType type)
A type variable type is assignable only to/from itself or a reference thereof.For example:
function foo
( t: T, s: S ) { t = s // illegal, T and S may not have the same type at runtime t = "hello" // illegal, T may not be a String var x: T = t // ok, x and t are both of type T } - Specified by:
isAssignableFrom
in interfaceIType
-
equals
public boolean equals(Object obj)
Ok, here's the deal. By all rights type variable types should have identity equality. That's not the case right now for at least these two reasons:- We compile in multiple phases (header, decl, def). Each phase recompiles the header, including type vars. Each time a new type var type is created for the type var definition. It's not too hard to re-use the prior type var type, but then there's this problem...
- If a subclass is generic and parameterizes its super with its type vars the super parameterizd type retains whatever the type var type from the first phase of the subclass' compilation. And, in studio, we don't refresh the type system, just the type we're editing. So the super class parameterized with the subclass' type vars and whatever else stemming from there that refs the type vars remains. So the subclass can be edited and refreshed a zillion time, but the super parameterized class will still have the type var from way back.
-
isMutable
public boolean isMutable()
Description copied from interface:IType
Are intances of this type mutable? Note sometimes it's difficult to determine. For instance, java classes don't contain any information about mutability. In which case we always assume mutable, even when the underlying type may in fact be immutable. E.g., even though java.lang.String is not mutable, its corresponding JavaIntrinsicType will say it is.
-
getTypeInfo
public ITypeInfo getTypeInfo()
Description copied from interface:IType
Get the type information for this intrinsic type.- Specified by:
getTypeInfo
in interfaceIType
- See Also:
ITypeInfo
-
unloadTypeInfo
public void unloadTypeInfo()
Description copied from interface:IType
Unload or nullify any references to this IType's ITypeInfo.- Specified by:
unloadTypeInfo
in interfaceIType
-
readResolve
public Object readResolve() throws ObjectStreamException
Description copied from interface:IType
IType requires this method be implemented to ensure IType instances can be centrally defined and cached.- Specified by:
readResolve
in interfaceIType
- Throws:
ObjectStreamException
-
isValid
public boolean isValid()
Description copied from interface:IType
Defines this type if it is not yet fully defined. For instance, if this type has source code associated with it, it must fully compile the source for it to be fully defined.
-
getModifiers
public int getModifiers()
Description copied from interface:IType
Returns the modifiers for this type, encoded in an integer. The modifiers consist of the constants forpublic
,protected
,private
,final
,static
,abstract
they should be decoded using the methods of classModifier
.- Specified by:
getModifiers
in interfaceIType
- See Also:
Modifier
-
isAbstract
public boolean isAbstract()
- Specified by:
isAbstract
in interfaceIType
-
isFunctionStatement
public boolean isFunctionStatement()
- Specified by:
isFunctionStatement
in interfaceITypeVariableType
-
isDiscarded
public boolean isDiscarded()
Description copied from interface:IType
True if this type has been replaced with a newer version of the same name in the type system.- Specified by:
isDiscarded
in interfaceIType
-
setDiscarded
public void setDiscarded(boolean bDiscarded)
- Specified by:
setDiscarded
in interfaceIType
-
isCompoundType
public boolean isCompoundType()
- Specified by:
isCompoundType
in interfaceIType
-
getCompoundTypeComponents
public Set<IType> getCompoundTypeComponents()
- Specified by:
getCompoundTypeComponents
in interfaceIType
-
-