Class JavaType

All Implemented Interfaces:
IJavaTypeInternal, IParameterizableType, IFileRepositoryBasedType, IHasInnerClass, ICanBeAnnotation, IDefaultArrayType, IEnhanceableType, IHasJavaClass, IType, IJavaArrayType, IJavaBackedType, IJavaBackedTypeData, IJavaType, Serializable
Direct Known Subclasses:
JavaEnumType

class JavaType extends InnerClassCapableType implements IJavaTypeInternal
  • Field Details

    • _strName

      private String _strName
    • _typeParams

      private IType[] _typeParams
    • _classInfo

      protected transient IJavaClassInfo _classInfo
    • _typeInfo

      private transient ITypeInfo _typeInfo
    • _strRelativeName

      private transient String _strRelativeName
    • _strSimpleName

      private transient String _strSimpleName
    • _allTypesInHierarchy

      private transient volatile Set<IType> _allTypesInHierarchy
    • _bArray

      private transient boolean _bArray
    • _bPrimitive

      private transient boolean _bPrimitive
    • _bHasSuperType

      private transient LockingLazyVar<Boolean> _bHasSuperType
    • _superType

      private transient volatile IType _superType
    • _tempInterfaces

      private transient List<IType> _tempInterfaces
    • _interfaces

      private transient volatile IType[] _interfaces
    • _functionalInterface

      private transient LocklessLazyVar<IFunctionType> _functionalInterface
    • _adapterClass

      private transient IGosuClassInternal _adapterClass
    • _tempGenericTypeVars

      private transient GenericTypeVariable[] _tempGenericTypeVars
    • _lazyGenericTypeVars

      private transient LockingLazyVar<GenericTypeVariable[]> _lazyGenericTypeVars
    • _bDefiningGenericTypes

      private transient boolean _bDefiningGenericTypes
    • _parameterizationByParamsName

      private transient ConcurrentMap<String,IJavaTypeInternal> _parameterizationByParamsName
    • _arrayType

      private transient volatile IJavaTypeInternal _arrayType
    • _componentType

      private IJavaTypeInternal _componentType
    • _typeLoader

      private transient DefaultTypeLoader _typeLoader
    • _bDoesNotHaveExplicitTypeInfo

      private transient boolean _bDoesNotHaveExplicitTypeInfo
    • _explicitTypeInfoClass

      private Class<?> _explicitTypeInfoClass
    • _bDiscarded

      private transient boolean _bDiscarded
    • _typeRef

      private IJavaTypeInternal _typeRef
    • _tiChecksum

      private transient int _tiChecksum
    • _innerClasses

      private transient volatile List<IJavaType> _innerClasses
    • _bStrictGenerics

      private transient Boolean _bStrictGenerics
    • SPECIAL_TYPE_INFO

      private static Set<String> SPECIAL_TYPE_INFO
  • Constructor Details

  • Method Details

    • get

      public static IJavaTypeInternal get(Class cls, DefaultTypeLoader loader)
    • getPrimitiveType

      public static IJavaType getPrimitiveType(String strPrimitiveClassName)
    • define

      private static IJavaTypeInternal define(Class cls, DefaultTypeLoader loader)
    • create

      public static IJavaTypeInternal create(IJavaClassInfo cls, DefaultTypeLoader loader)
    • isDefiningGenericTypes

      public boolean isDefiningGenericTypes()
      Specified by:
      isDefiningGenericTypes in interface IJavaTypeInternal
    • assignGenericTypeVariables

      public GenericTypeVariable[] assignGenericTypeVariables()
      Specified by:
      assignGenericTypeVariables in interface IJavaTypeInternal
    • assignGenericTypeVarPlaceholders

      private void assignGenericTypeVarPlaceholders()
    • init

      private void init(IJavaClassInfo cls, DefaultTypeLoader loader)
    • assignTypeVarsFromTypeParams

      private GenericTypeVariable[] assignTypeVarsFromTypeParams(IType[] typeParams)
      Note a gosu class can be BOTH parameterzied AND generic. For example,

      class Bar { function blah() : T {...} } class Foo extends Bar {}

      The class Bar here is parameterized by the type var from Foo, yet it is still a generic class. The blah() method in Foo's typeinfo must have a return type consistent with Foo's type var upper bound, CharSequence. //## todo: maybe we don't need this concept any longer? i.e., parameterization should work correctly regardless.

      Parameters:
      typeParams - type parameters
      Returns:
      generic type variables
    • getTypeLoader

      public DefaultTypeLoader getTypeLoader()
      Description copied from interface: IType
      Returns the type loader responsible for loading this intrinsic type.
      Specified by:
      getTypeLoader in interface IType
    • getName

      public String getName()
      Description copied from interface: IType
      The fully qualified name of this intrinsic type.
      Specified by:
      getName in interface IType
    • computeQualifiedName

      String computeQualifiedName()
    • getDisplayName

      public String getDisplayName()
      Description copied from interface: IType
      The display name of this intrinsic type. Often this is simply the same as IType.getName(), but in some cases a type may want to modify it's name for presentation to the user.
      Specified by:
      getDisplayName in interface IType
    • 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 interface IType
    • getSimpleName

      public String getSimpleName()
      Specified by:
      getSimpleName in interface IJavaTypeInternal
    • 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 interface IType
    • isArray

      public boolean isArray()
      Description copied from interface: IType
      True if this is an array.
      Specified by:
      isArray in interface IType
    • 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 interface IType
    • makeArrayInstance

      public Object makeArrayInstance(int iLength)
      Description copied from interface: IType
      Construct an array instance of specified length.
      Specified by:
      makeArrayInstance in interface IType
    • isAssignableFrom

      public boolean isAssignableFrom(IType type)
      Description copied from interface: IType
      Determines if the type represented by this intrinsic type is either the same as, or is a super-type of the type represented by the specified type parameter.
      Specified by:
      isAssignableFrom in interface IType
    • isAssignableFromJavaBackedType

      private boolean isAssignableFromJavaBackedType(IType type)
    • isMutable

      public boolean isMutable()
      Note eventhough some classes are indeed immutable (e.g. java.lang.String) there's no such info in a java class, so we default to mutable.
      Specified by:
      isMutable in interface IType
      Returns:
      True if this type is mutable.
    • getIntrinsicClass

      public Class getIntrinsicClass()
      Description copied from interface: IJavaType
      Returns the java class for this java type
      Specified by:
      getIntrinsicClass in interface IJavaType
      Returns:
      the java class for this java type
    • getBackingClassInfo

      public IJavaClassInfo getBackingClassInfo()
      Specified by:
      getBackingClassInfo in interface IJavaBackedTypeData
      Specified by:
      getBackingClassInfo in interface IJavaType
    • getBackingClass

      public Class getBackingClass()
      Specified by:
      getBackingClass in interface IHasJavaClass
    • getTypeInfo

      public ITypeInfo getTypeInfo()
      Description copied from interface: IType
      Get the type information for this intrinsic type.
      Specified by:
      getTypeInfo in interface IType
      See Also:
    • getAdapterClass

      public IGosuClassInternal getAdapterClass()
      Description copied from interface: IJavaType
      Returns the Gosu proxy for this class.
      Specified by:
      getAdapterClass in interface IJavaType
      Specified by:
      getAdapterClass in interface IJavaTypeInternal
    • getAdapterClassDirectly

      public IGosuClassInternal getAdapterClassDirectly()
      Specified by:
      getAdapterClassDirectly in interface IJavaTypeInternal
    • loadTypeInfo

      private ITypeInfo loadTypeInfo()
    • unloadTypeInfo

      public void unloadTypeInfo()
      Description copied from interface: IType
      Unload or nullify any references to this IType's ITypeInfo.
      Specified by:
      unloadTypeInfo in interface IType
    • isInterface

      public boolean isInterface()
      Description copied from interface: IType
      Returns true if this type is an interface.
      Specified by:
      isInterface in interface IType
    • isEnum

      public boolean isEnum()
      Description copied from interface: IType
      Returns true if this type is an enumeration.
      Specified by:
      isEnum in interface IType
    • getInterfaces

      public IType[] getInterfaces()
      Specified by:
      getInterfaces in interface IType
      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 interface IType
    • notDeletedSupertype

      private IType notDeletedSupertype()
    • getInnerClasses

      public List<IJavaType> getInnerClasses()
      Specified by:
      getInnerClasses in interface IHasInnerClass
      Specified by:
      getInnerClasses in interface IJavaType
      Returns:
      An array of Java types reflecting all the classes and interfaces declared as members of the class represented by this Class object. These include public, protected, internal, and private classes and interfaces declared by the class, but excludes inherited classes and interfaces.
    • getInnerClass

      public IType getInnerClass(CharSequence name)
      Description copied from interface: IHasInnerClass
      returns the appropriate inner class
      Specified by:
      getInnerClass in interface IHasInnerClass
      Returns:
    • getInnerClassSimple

      private IJavaTypeInternal getInnerClassSimple(String simpleName)
    • getSourceFileHandle

      public ISourceFileHandle getSourceFileHandle()
      Specified by:
      getSourceFileHandle in interface IFileRepositoryBasedType
    • getLoadedInnerClasses

      public List<? extends IType> getLoadedInnerClasses()
      Specified by:
      getLoadedInnerClasses in interface IHasInnerClass
    • getClassType

      public ClassType getClassType()
      Specified by:
      getClassType in interface IFileRepositoryBasedType
    • 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 interface IType
    • getGenericType

      public IJavaTypeInternal 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 interface IJavaType
      Specified by:
      getGenericType in interface IType
    • isFinal

      public boolean isFinal()
      Description copied from interface: IType
      True if this type cannot be extended.
      Specified by:
      isFinal in interface IType
    • 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 ArrayList is a Generic Type, while the class ArrayList is a Parameterized Type of the the Generic Type ArrayList.

      Specified by:
      isParameterizedType in interface IType
    • isGenericType

      public boolean isGenericType()
      Description copied from interface: IType
      Returns true if this ia a Generic Type.
      Specified by:
      isGenericType in interface IType
      See Also:
    • 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 interface IType
    • 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 interface IType
    • getParameterizedType

      public IType getParameterizedType(IType... paramTypes)
      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 interface IType
      Parameters:
      paramTypes - The type parameters.
      Returns:
      The concrete type associated with the type parameters.
    • 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 interface IType
    • addGenericTypes

      private void addGenericTypes(IType type, Set<IType> includeGenericTypes)
    • thisRef

      private IJavaTypeInternal thisRef()
    • getArrayType

      public IType getArrayType()
      Description copied from interface: IType
      Make an array type from this type. E.g., String -> String[]
      Specified by:
      getArrayType in interface IType
    • 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 interface IType
      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 interface IType
      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
    • getInterfaces

      private void getInterfaces(Class clazz, Set<Class> classes)
    • 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 interface IType
      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 IJavaTypeInternal 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 interface IType
    • setComponentType

      public void setComponentType(IJavaTypeInternal componentType)
      Specified by:
      setComponentType in interface IJavaTypeInternal
    • getTypeInfoChecksum

      public int getTypeInfoChecksum()
      Specified by:
      getTypeInfoChecksum in interface IJavaTypeInternal
    • hasAncestorBeenUpdated

      public boolean hasAncestorBeenUpdated()
      Specified by:
      hasAncestorBeenUpdated in interface IJavaTypeInternal
    • haveAncestorsBeenUpdated

      private static boolean haveAncestorsBeenUpdated(IJavaTypeInternal type, int tiChecksum, Set<IType> visited)
    • hasBeenUpdated

      public static boolean hasBeenUpdated(IJavaTypeInternal type, int tiChecksum, Set<IType> visited)
    • writeReplace

      public Object writeReplace()
      Specified by:
      writeReplace in interface IJavaTypeInternal
    • 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 interface IType
      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.
      Specified by:
      isValid in interface IType
      Returns:
      true if this type is valid.
    • 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 for public, protected, private, final, static, abstract they should be decoded using the methods of class Modifier.
      Specified by:
      getModifiers in interface IType
      See Also:
    • isAbstract

      public boolean isAbstract()
      Specified by:
      isAbstract in interface IType
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getExplicitTypeInfo

      public ITypeInfo getExplicitTypeInfo()
      Specified by:
      getExplicitTypeInfo in interface IJavaTypeInternal
    • convertToTypeInfo

      private ITypeInfo convertToTypeInfo()
    • setAdapterClass

      public void setAdapterClass(IGosuClassInternal adapterClass)
      Specified by:
      setAdapterClass in interface IJavaTypeInternal
    • createAdapterClass

      public IGosuClassInternal createAdapterClass()
      Description copied from interface: IJavaType
      Creates the Gosu proxy type for this class.
      Specified by:
      createAdapterClass in interface IJavaType
      Returns:
      The newly created proxy type.
    • convertClassArray

      public static IJavaType[] convertClassArray(Class[] args)
    • unloadTypes

      public static void unloadTypes()
    • 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 interface IType
    • setDiscarded

      public void setDiscarded(boolean bDiscarded)
      Specified by:
      setDiscarded in interface IType
    • isCompoundType

      public boolean isCompoundType()
      Specified by:
      isCompoundType in interface IType
    • getCompoundTypeComponents

      public Set<IType> getCompoundTypeComponents()
      Specified by:
      getCompoundTypeComponents in interface IType
    • getConcreteClass

      public IJavaClassInfo getConcreteClass()
      Specified by:
      getConcreteClass in interface IDefaultArrayType
    • getTypeFromJavaBackedType

      public IType getTypeFromJavaBackedType()
      Specified by:
      getTypeFromJavaBackedType in interface IJavaBackedType
    • getRetainedMemory

      public ObjectSize getRetainedMemory()
      Specified by:
      getRetainedMemory in interface IJavaType
    • getLoaderParameterizedTypes

      public IType[] getLoaderParameterizedTypes()
      Specified by:
      getLoaderParameterizedTypes in interface IParameterizableType
    • isStrictGenerics

      public boolean isStrictGenerics()
      Specified by:
      isStrictGenerics in interface IParameterizableType
    • getSourceFiles

      public IFile[] getSourceFiles()
      Specified by:
      getSourceFiles in interface IType
    • isAnnotation

      public boolean isAnnotation()
      Specified by:
      isAnnotation in interface ICanBeAnnotation
    • getFunctionalInterface

      public IFunctionType getFunctionalInterface()
      Specified by:
      getFunctionalInterface in interface IType
    • getTheRef

      protected IType getTheRef()
      Overrides:
      getTheRef in class AbstractType
    • isCompilable

      public boolean isCompilable()
      Specified by:
      isCompilable in interface IType
    • compile

      public byte[] compile()
      Specified by:
      compile in interface IType