Class FunctionType

java.lang.Object
gw.lang.reflect.AbstractType
gw.lang.reflect.FunctionType
All Implemented Interfaces:
IFunctionType, IGenericMethodInfo, IInvocableType, INonLoadableType, IType, Serializable
Direct Known Subclasses:
BlockType, DelegateFunctionType, ErrorTypeInfo.UniversalFunctionType

public class FunctionType extends AbstractType implements IFunctionType, IGenericMethodInfo
See Also:
  • Field Details

  • Constructor Details

    • FunctionType

      public FunctionType(String strFunctionName, IType retType, IType[] paramTypes)
      Construct a FunctionType with the specified return type and parameter types array.
      Parameters:
      strFunctionName - The name of the function
      retType - The return type of the function.
      paramTypes - The parameter types. Can be null if no params.
    • FunctionType

      public FunctionType(String strFunctionName, IType retType, IType[] paramTypes, IGenericTypeVariable[] typeVars)
      Construct a generic FunctionType with the specified return type, parameter types, and generic type variables.
      Parameters:
      strFunctionName - The name of the function
      retType - The return type of the function.
      paramTypes - The parameter types. Can be null if no params.
      typeVars - The generic type variables. If null, does not create a generic function type.
    • FunctionType

      public FunctionType(IMethodInfo mi)
    • FunctionType

      public FunctionType(IMethodInfo mi, boolean lazyTypes)
    • FunctionType

      public FunctionType(FunctionType source, IType gsClass)
    • FunctionType

      protected FunctionType(FunctionType source, IType returnType, IType[] paramTypes)
    • FunctionType

      protected FunctionType(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars)
  • Method Details

    • setName

      private void setName(String name)
    • initLazyMethodInfoState

      private void initLazyMethodInfoState()
    • initLazyMethodInfoState_NoLock

      private void initLazyMethodInfoState_NoLock()
    • copyFields

      protected void copyFields(FunctionType source)
    • parameterize

      public FunctionType parameterize(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars)
      Create a new FunctionType based on the type parameters assigned to the type vars in actualParamByVarName.

      It is important to note that this form of parameterization is different from calling getParameterizedType(). The latter creates a parameterization of a generic function e.g., function foo<T>() where T is a type var on the function.

      This here method is for parameterizing a function type that has references to external type vars e.g., class Fred<T> { function foo( t : T ){} } where T is a type var on the containing class.

      Parameters:
      source - The raw form of a FunctionType having possible references to type vars defined in its containing class.
      actualParamByVarName - A map of concrete types by type var name e.g., "T" -> String
      bKeepTypeVars - Indicates whether or not a type var referenced in the source FunctionType that cannot be resolved via the actualParamByVarName map should remain as a TypeVariableType or should be converted to its bounding type.
      Returns:
      A parameterized version of the source FunctionType
    • assignParamTypesFromTypeParams

      private void assignParamTypesFromTypeParams(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars)
    • assignTypeVars

      private void assignTypeVars(IGenericTypeVariable[] gtvs, TypeVarToTypeMap actualParamByVarName)
    • assignReturnTypeFromTypeParams

      private void assignReturnTypeFromTypeParams(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars)
    • getIntrinsicType

      public IType getIntrinsicType()
      Returns:
      The instrinic type of this FunctionType's return type.
    • getReturnType

      public IType getReturnType()
      Specified by:
      getReturnType in interface IFunctionType
    • setRetType

      public void setRetType(IType retType)
    • getParameterTypes

      public IType[] getParameterTypes()
      Specified by:
      getParameterTypes in interface IFunctionType
      Specified by:
      getParameterTypes in interface IInvocableType
    • setArgumentTypes

      public void setArgumentTypes(IType[] paramTypes)
    • getMethodInfo

      public IMethodInfo getMethodInfo()
      Description copied from interface: IFunctionType
      An associated IMethodInfo. Optional.
      Specified by:
      getMethodInfo in interface IFunctionType
    • getMethodOrConstructorInfo

      public IFeatureInfo getMethodOrConstructorInfo()
      Specified by:
      getMethodOrConstructorInfo in interface IFunctionType
    • clearParamSignature

      private void clearParamSignature()
    • getParamSignature

      public String getParamSignature()
      Description copied from interface: IFunctionType
      Formatted signature of the form " ( param-list )"
      Specified by:
      getParamSignature in interface IFunctionType
      Specified by:
      getParamSignature in interface IInvocableType
    • getParamSignatureForCurrentModule

      public String getParamSignatureForCurrentModule()
      Specified by:
      getParamSignatureForCurrentModule in interface IFunctionType
    • getParamTypeNameFromJavaBackedType

      public static String getParamTypeNameFromJavaBackedType(IType paramType)
    • getName

      public String getName()
      Description copied from interface: IType
      The fully qualified name of this intrinsic type.
      Specified by:
      getName in interface IType
    • 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
    • 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
    • getTypeLoader

      public ITypeLoader getTypeLoader()
      Description copied from interface: IType
      Returns the type loader responsible for loading this intrinsic type.
      Specified by:
      getTypeLoader 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
    • 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.
    • isEnum

      public boolean isEnum()
      Description copied from interface: IType
      Returns true if this type is an enumeration.
      Specified by:
      isEnum in interface IType
    • 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
    • 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 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 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 IGenericTypeVariable[] 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
    • getParameterizedType

      public ParameterizedFunctionType getParameterizedType(IType... typeParams)
      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:
      typeParams - The type parameters.
      Returns:
      The concrete type associated with the type parameters.
    • inferParameterizedTypeFromArgTypesAndContextType

      public IFunctionType inferParameterizedTypeFromArgTypesAndContextType(IType[] argTypes, IType ctxType)
      Specified by:
      inferParameterizedTypeFromArgTypesAndContextType in interface IFunctionType
    • 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
    • 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
    • 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
    • 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
    • makeArrayInstance

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

      private IJavaClassInfo getFunctionClass()
    • 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
    • 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 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 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
    • isAssignableFrom

      public boolean isAssignableFrom(IType type, boolean bContravariant)
      Specified by:
      isAssignableFrom in interface IFunctionType
    • areReturnTypesAssignable

      protected boolean areReturnTypesAssignable(FunctionType from)
    • isThisReturnTypeNotVoidThatReturnTypeVoid

      private boolean isThisReturnTypeNotVoidThatReturnTypeVoid(IType toType, IType fromType)
    • areParamsCompatible

      public boolean areParamsCompatible(IFunctionType fromType)
      Specified by:
      areParamsCompatible in interface IFunctionType
    • areParamsCompatible

      public static boolean areParamsCompatible(IFunctionType toType, IFunctionType fromType)
    • areParamsCompatible

      private static boolean areParamsCompatible(IFunctionType toType, IFunctionType fromType, boolean bContravariant)
    • findContravariantParams

      public static IType[] findContravariantParams(IType[] lhsParams, IType[] rhsParams)
    • 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.
      Specified by:
      isMutable in interface IType
      Returns:
      True if this type is mutable.
    • 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:
    • 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
    • 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:
    • setModifiers

      public void setModifiers(int iModifiers)
    • isAbstract

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

      public IScriptPartId getScriptPart()
      Specified by:
      getScriptPart in interface IFunctionType
    • newInstance

      public IType newInstance(IType[] paramTypes, IType returnType)
      Specified by:
      newInstance in interface IFunctionType
      Returns:
      a new copy of this IFunctionType with the given parameter and return types
    • cloneTypeVars

      private IGenericTypeVariable[] cloneTypeVars()
    • setScriptPart

      public void setScriptPart(IScriptPartId scriptPart)
    • equals

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

      protected boolean areEnclosingTypesEqual(FunctionType funcType)
    • areSameTypes

      protected boolean areSameTypes(IType t1, IType t2)
    • hashCode

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

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

      public TypeVarToTypeMap inferTypeParametersFromArgumentTypes2(IType owningParameterizedType, IType... argTypes)
      Specified by:
      inferTypeParametersFromArgumentTypes2 in interface IGenericMethodInfo
    • inferTypeParametersFromArgumentTypes

      public TypeVarToTypeMap inferTypeParametersFromArgumentTypes(IType... argTypes)
      Specified by:
      inferTypeParametersFromArgumentTypes in interface IGenericMethodInfo
      Parameters:
      argTypes - The argument types from a generic method call.
      Returns:
      A map of inferred type parameters based on the argTypes. The map contains only the types that could be inferred -- the map may be empty.

      E.g., given generic method: T[] toArray( T[] ) and call: list.toArray( new String[list.size()] ); => the toArray() method call should be automatically parameterized with based on the new String[0].

    • getTypeVariables

      public IGenericTypeVariable[] getTypeVariables()
      Specified by:
      getTypeVariables in interface IGenericMethodInfo
      Returns:
      An array of generic type variables if this feature corresponds with a generic type.
    • getParameterizedReturnType

      public IType getParameterizedReturnType(IType... typeParams)
      Specified by:
      getParameterizedReturnType in interface IGenericMethodInfo
    • getParameterizedParameterTypes

      public IType[] getParameterizedParameterTypes(IType... typeParams)
      Specified by:
      getParameterizedParameterTypes in interface IGenericMethodInfo
    • getParameterizedParameterTypes2

      public IType[] getParameterizedParameterTypes2(IType ownersType, IType... typeParams)
      Specified by:
      getParameterizedParameterTypes2 in interface IGenericMethodInfo
    • getRuntimeType

      public FunctionType getRuntimeType()
    • mapTypes

      private TypeVarToTypeMap mapTypes(TypeVarToTypeMap actualParamByVarName, IType... types)
    • 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
    • getDefaultValueExpressions

      public IExpression[] getDefaultValueExpressions()
      Specified by:
      getDefaultValueExpressions in interface IInvocableType
    • hasOptionalParams

      public boolean hasOptionalParams()
      Specified by:
      hasOptionalParams in interface IInvocableType
    • getParameterNames

      public String[] getParameterNames()
      Specified by:
      getParameterNames in interface IInvocableType
    • getOwningParameterizedType

      public IType getOwningParameterizedType()
    • setEnclosingType

      public void setEnclosingType(IType gosuClass)