Package gw.lang.reflect
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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LockingLazyVar<FunctionArrayType>private ITypeprivate intprivate IMethodInfoprivate ITypeprivate Map<String,ParameterizedFunctionType> private IType[]private ITypeprivate IScriptPartIdprivate Stringprivate Stringprivate FunctionTypeInfoprivate IGenericTypeVariable[]private static final IType[]private static final IGenericTypeVariable[]Fields inherited from interface gw.lang.reflect.IType
EMPTY_ARRAY, EMPTY_TYPE_ARRAY, EMPTY_TYPE_LIST -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFunctionType(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars) FunctionType(FunctionType source, IType gsClass) protectedFunctionType(FunctionType source, IType returnType, IType[] paramTypes) FunctionType(IMethodInfo mi, boolean lazyTypes) FunctionType(String strFunctionName, IType retType, IType[] paramTypes) Construct a FunctionType with the specified return type and parameter types array.FunctionType(String strFunctionName, IType retType, IType[] paramTypes, IGenericTypeVariable[] typeVars) Construct a generic FunctionType with the specified return type, parameter types, and generic type variables. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanareEnclosingTypesEqual(FunctionType funcType) booleanareParamsCompatible(IFunctionType fromType) static booleanareParamsCompatible(IFunctionType toType, IFunctionType fromType) private static booleanareParamsCompatible(IFunctionType toType, IFunctionType fromType, boolean bContravariant) protected booleanprotected booleanareSameTypes(IType t1, IType t2) private voidassignParamTypesFromTypeParams(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars) private voidassignReturnTypeFromTypeParams(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars) private voidassignTypeVars(IGenericTypeVariable[] gtvs, TypeVarToTypeMap actualParamByVarName) private voidprivate IGenericTypeVariable[]protected voidcopyFields(FunctionType source) booleanstatic IType[]findContravariantParams(IType[] lhsParams, IType[] rhsParams) Returns a Set of all IIntrinsicTypes that this class is assignable from, including this class.getArrayComponent(Object array, int iIndex) Returns the value of the indexed component in the specified array object.intgetArrayLength(Object array) Returns the length of the specified array object.Make an array type from this type.If this is an array type, a type representing the component type of the array.The display name of this intrinsic type.Returns the type immediately enclosing this type.private IJavaClassInfoIf this is a parameterized type, returns the generic type this type parameterizes.Returns an array of GenericTypeVariables declared with this Generic Type.IType[]An associated IMethodInfo.intReturns the modifiers for this type, encoded in an integer.getName()The fully qualified name of this intrinsic type.The namespace for this class.IType[]getParameterizedParameterTypes(IType... typeParams) IType[]getParameterizedParameterTypes2(IType ownersType, IType... typeParams) getParameterizedReturnType(IType... typeParams) getParameterizedType(IType... typeParams) Assuming this intrinsic type is a Generic type, return the parameterized type associated with the given list of type parameters.String[]IType[]Formatted signature of the form "( param-list )" static StringgetParamTypeNameFromJavaBackedType(IType paramType) The relative or unqualified name.Returns the type representing the supertype of this type.Get the type information for this intrinsic type.Returns the type loader responsible for loading this intrinsic type.IType[]If this is a parameterized type, returns the specific types used to create this type, null otherwies.inthashCode()booleaninferParameterizedTypeFromArgTypesAndContextType(IType[] argTypes, IType ctxType) inferTypeParametersFromArgumentTypes(IType... argTypes) inferTypeParametersFromArgumentTypes2(IType owningParameterizedType, IType... argTypes) private voidprivate voidbooleanbooleanisArray()True if this is an array.booleanisAssignableFrom(IType type) 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.booleanisAssignableFrom(IType type, boolean bContravariant) booleanbooleanTrue if this type has been replaced with a newer version of the same name in the type system.booleanisEnum()Returns true if this type is an enumeration.booleanisFinal()True if this type cannot be extended.booleanReturns true if this ia a Generic Type.booleanReturns true if this type is an interface.booleanAre intances of this type mutable? Note sometimes it's difficult to determine.booleanReturns true if this ia a Parameterized Type.booleanTrue if this type represents a primitive type e.g., Java int, char, etc.private booleanisThisReturnTypeNotVoidThatReturnTypeVoid(IType toType, IType fromType) booleanisValid()Defines this type if it is not yet fully defined.makeArrayInstance(int iLength) Construct an array instance of specified length.private TypeVarToTypeMapmapTypes(TypeVarToTypeMap actualParamByVarName, IType... types) newInstance(IType[] paramTypes, IType returnType) parameterize(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars) Create a new FunctionType based on the type parameters assigned to the type vars in actualParamByVarName.IType requires this method be implemented to ensure IType instances can be centrally defined and cached.voidsetArgumentTypes(IType[] paramTypes) voidsetArrayComponent(Object array, int iIndex, Object value) Sets the value of the indexed component in the specified array object.voidsetDiscarded(boolean bDiscarded) voidsetEnclosingType(IType gosuClass) voidsetModifiers(int iModifiers) private voidvoidsetRetType(IType retType) voidsetScriptPart(IScriptPartId scriptPart) toString()voidUnload or nullify any references to this IType's ITypeInfo.Methods inherited from class gw.lang.reflect.AbstractType
getLiteralMetaType, getMetaType, getTheRefMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface gw.lang.reflect.IType
compile, getFunctionalInterface, getLiteralMetaType, getMetaType, getSourceFiles, isCompilable, isDynamic
-
Field Details
-
EMPTY_TYPE_VARS
-
EMPTY_ARGS
-
_retType
-
_paramTypes
-
_mi
-
_strFunctionName
-
_scriptPart
-
_owningParameterizedType
-
_typeVars
-
_iModifiers
private int _iModifiers -
_enclosingType
-
_typeInfo
-
_allTypesInHierarchy
-
_signature
-
_parameterizationByParamsName
-
_arrType
-
-
Constructor Details
-
FunctionType
Construct a FunctionType with the specified return type and parameter types array.- Parameters:
strFunctionName- The name of the functionretType- 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 functionretType- 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
-
FunctionType
-
FunctionType
-
FunctionType
-
FunctionType
protected FunctionType(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars)
-
-
Method Details
-
setName
-
initLazyMethodInfoState
private void initLazyMethodInfoState() -
initLazyMethodInfoState_NoLock
private void initLazyMethodInfoState_NoLock() -
copyFields
-
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" -> StringbKeepTypeVars- 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
-
assignReturnTypeFromTypeParams
private void assignReturnTypeFromTypeParams(FunctionType source, TypeVarToTypeMap actualParamByVarName, boolean bKeepTypeVars) -
getIntrinsicType
- Returns:
- The instrinic type of this FunctionType's return type.
-
getReturnType
- Specified by:
getReturnTypein interfaceIFunctionType
-
setRetType
-
getParameterTypes
- Specified by:
getParameterTypesin interfaceIFunctionType- Specified by:
getParameterTypesin interfaceIInvocableType
-
setArgumentTypes
-
getMethodInfo
Description copied from interface:IFunctionTypeAn associated IMethodInfo. Optional.- Specified by:
getMethodInfoin interfaceIFunctionType
-
getMethodOrConstructorInfo
- Specified by:
getMethodOrConstructorInfoin interfaceIFunctionType
-
clearParamSignature
private void clearParamSignature() -
getParamSignature
Description copied from interface:IFunctionTypeFormatted signature of the form "( param-list )" - Specified by:
getParamSignaturein interfaceIFunctionType- Specified by:
getParamSignaturein interfaceIInvocableType
-
getParamSignatureForCurrentModule
- Specified by:
getParamSignatureForCurrentModulein interfaceIFunctionType
-
getParamTypeNameFromJavaBackedType
-
getName
Description copied from interface:ITypeThe fully qualified name of this intrinsic type. -
getDisplayName
Description copied from interface:ITypeThe 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:
getDisplayNamein interfaceIType
-
getRelativeName
Description copied from interface:ITypeThe relative or unqualified name. For a class this should be just the class name without the package name.- Specified by:
getRelativeNamein interfaceIType
-
getNamespace
Description copied from interface:ITypeThe 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:
getNamespacein interfaceIType
-
getTypeLoader
Description copied from interface:ITypeReturns the type loader responsible for loading this intrinsic type.- Specified by:
getTypeLoaderin interfaceIType
-
isInterface
public boolean isInterface()Description copied from interface:ITypeReturns true if this type is an interface.- Specified by:
isInterfacein interfaceIType
-
getInterfaces
- Specified by:
getInterfacesin 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.
-
isEnum
public boolean isEnum()Description copied from interface:ITypeReturns true if this type is an enumeration. -
getSupertype
Description copied from interface:ITypeReturns the type representing the supertype of this type. Returns null if this type has no supertype.- Specified by:
getSupertypein interfaceIType
-
getEnclosingType
Description copied from interface:ITypeReturns the type immediately enclosing this type. If this type is not enclosed, returns null.- Specified by:
getEnclosingTypein interfaceIType
-
getGenericType
Description copied from interface:ITypeIf this is a parameterized type, returns the generic type this type parameterizes. Otherwise, returns null.- Specified by:
getGenericTypein interfaceIType
-
isFinal
public boolean isFinal()Description copied from interface:ITypeTrue if this type cannot be extended. -
isParameterizedType
public boolean isParameterizedType()Description copied from interface:ITypeReturns 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:
isParameterizedTypein interfaceIType
-
isGenericType
public boolean isGenericType()Description copied from interface:ITypeReturns true if this ia a Generic Type.- Specified by:
isGenericTypein interfaceIType- See Also:
-
getGenericTypeVariables
Description copied from interface:ITypeReturns an array of GenericTypeVariables declared with this Generic Type. Otherwise, returns null if this is not a Generic Type.- Specified by:
getGenericTypeVariablesin interfaceIType
-
getParameterizedType
Description copied from interface:ITypeAssuming 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:
getParameterizedTypein interfaceIType- Parameters:
typeParams- The type parameters.- Returns:
- The concrete type associated with the type parameters.
-
inferParameterizedTypeFromArgTypesAndContextType
public IFunctionType inferParameterizedTypeFromArgTypesAndContextType(IType[] argTypes, IType ctxType) - Specified by:
inferParameterizedTypeFromArgTypesAndContextTypein interfaceIFunctionType
-
getTypeParameters
Description copied from interface:ITypeIf this is a parameterized type, returns the specific types used to create this type, null otherwies.- Specified by:
getTypeParametersin interfaceIType
-
getAllTypesInHierarchy
Description copied from interface:ITypeReturns 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:
getAllTypesInHierarchyin interfaceIType
-
isArray
public boolean isArray()Description copied from interface:ITypeTrue if this is an array. -
isPrimitive
public boolean isPrimitive()Description copied from interface:ITypeTrue if this type represents a primitive type e.g., Java int, char, etc.- Specified by:
isPrimitivein interfaceIType
-
getArrayType
Description copied from interface:ITypeMake an array type from this type. E.g., String -> String[]- Specified by:
getArrayTypein interfaceIType
-
makeArrayInstance
Description copied from interface:ITypeConstruct an array instance of specified length.- Specified by:
makeArrayInstancein interfaceIType
-
getFunctionClass
-
getArrayComponent
public Object getArrayComponent(Object array, int iIndex) throws IllegalArgumentException, ArrayIndexOutOfBoundsException Description copied from interface:ITypeReturns the value of the indexed component in the specified array object.- Specified by:
getArrayComponentin 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:ITypeSets the value of the indexed component in the specified array object.- Specified by:
setArrayComponentin 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
Description copied from interface:ITypeReturns the length of the specified array object.- Specified by:
getArrayLengthin 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
Description copied from interface:ITypeIf this is an array type, a type representing the component type of the array. Otherwise null.- Specified by:
getComponentTypein interfaceIType
-
isAssignableFrom
Description copied from interface:ITypeDetermines 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:
isAssignableFromin interfaceIType
-
isAssignableFrom
- Specified by:
isAssignableFromin interfaceIFunctionType
-
areReturnTypesAssignable
-
isThisReturnTypeNotVoidThatReturnTypeVoid
-
areParamsCompatible
- Specified by:
areParamsCompatiblein interfaceIFunctionType
-
areParamsCompatible
-
areParamsCompatible
private static boolean areParamsCompatible(IFunctionType toType, IFunctionType fromType, boolean bContravariant) -
findContravariantParams
-
isMutable
public boolean isMutable()Description copied from interface:ITypeAre 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
Description copied from interface:ITypeGet the type information for this intrinsic type.- Specified by:
getTypeInfoin interfaceIType- See Also:
-
unloadTypeInfo
public void unloadTypeInfo()Description copied from interface:ITypeUnload or nullify any references to this IType's ITypeInfo.- Specified by:
unloadTypeInfoin interfaceIType
-
readResolve
Description copied from interface:ITypeIType requires this method be implemented to ensure IType instances can be centrally defined and cached.- Specified by:
readResolvein interfaceIType- Throws:
ObjectStreamException
-
isValid
public boolean isValid()Description copied from interface:ITypeDefines 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:ITypeReturns the modifiers for this type, encoded in an integer. The modifiers consist of the constants forpublic,protected,private,final,static,abstractthey should be decoded using the methods of classModifier.- Specified by:
getModifiersin interfaceIType- See Also:
-
setModifiers
public void setModifiers(int iModifiers) -
isAbstract
public boolean isAbstract()- Specified by:
isAbstractin interfaceIType
-
getScriptPart
- Specified by:
getScriptPartin interfaceIFunctionType
-
newInstance
- Specified by:
newInstancein interfaceIFunctionType- Returns:
- a new copy of this IFunctionType with the given parameter and return types
-
cloneTypeVars
-
setScriptPart
-
equals
-
areEnclosingTypesEqual
-
areSameTypes
-
hashCode
public int hashCode() -
toString
-
inferTypeParametersFromArgumentTypes2
public TypeVarToTypeMap inferTypeParametersFromArgumentTypes2(IType owningParameterizedType, IType... argTypes) - Specified by:
inferTypeParametersFromArgumentTypes2in interfaceIGenericMethodInfo
-
inferTypeParametersFromArgumentTypes
- Specified by:
inferTypeParametersFromArgumentTypesin interfaceIGenericMethodInfo- 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
- Specified by:
getTypeVariablesin interfaceIGenericMethodInfo- Returns:
- An array of generic type variables if this feature corresponds with a generic type.
-
getParameterizedReturnType
- Specified by:
getParameterizedReturnTypein interfaceIGenericMethodInfo
-
getParameterizedParameterTypes
- Specified by:
getParameterizedParameterTypesin interfaceIGenericMethodInfo
-
getParameterizedParameterTypes2
- Specified by:
getParameterizedParameterTypes2in interfaceIGenericMethodInfo
-
getRuntimeType
-
mapTypes
-
isDiscarded
public boolean isDiscarded()Description copied from interface:ITypeTrue if this type has been replaced with a newer version of the same name in the type system.- Specified by:
isDiscardedin interfaceIType
-
setDiscarded
public void setDiscarded(boolean bDiscarded) - Specified by:
setDiscardedin interfaceIType
-
isCompoundType
public boolean isCompoundType()- Specified by:
isCompoundTypein interfaceIType
-
getCompoundTypeComponents
- Specified by:
getCompoundTypeComponentsin interfaceIType
-
getDefaultValueExpressions
- Specified by:
getDefaultValueExpressionsin interfaceIInvocableType
-
hasOptionalParams
public boolean hasOptionalParams()- Specified by:
hasOptionalParamsin interfaceIInvocableType
-
getParameterNames
- Specified by:
getParameterNamesin interfaceIInvocableType
-
getOwningParameterizedType
-
setEnclosingType
-