Class FunctionType
- java.lang.Object
-
- com.google.javascript.rhino.jstype.JSType
-
- com.google.javascript.rhino.jstype.ObjectType
-
- com.google.javascript.rhino.jstype.PrototypeObjectType
-
- com.google.javascript.rhino.jstype.FunctionType
-
- All Implemented Interfaces:
JSType.WithSourceRef
- Direct Known Subclasses:
NoObjectType
public class FunctionType extends PrototypeObjectType implements JSType.WithSourceRef
This derived type provides extended information about a function, including its return type and argument types.Note: the parameters list is the PARAM_LIST node that is the parent of the actual NAME node containing the parsed argument list (annotated with JSDOC_TYPE_PROP's for the compile-time type of each argument.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFunctionType.BuilderA builder class for function and arrow types.static classFunctionType.ParameterModels a single JavaScript parameter.-
Nested classes/interfaces inherited from class com.google.javascript.rhino.jstype.JSType
JSType.HasPropertyKind, JSType.Nullability, JSType.SubtypingMode, JSType.TypePair, JSType.WithSourceRef
-
-
Field Summary
-
Fields inherited from class com.google.javascript.rhino.jstype.JSType
templateTypeMap
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptsArguments(java.util.List<? extends JSType> argumentTypes)static FunctionType.Builderbuilder(JSTypeRegistry registry)booleancanBeCalled()This predicate is used to test whether a given type can be used as the 'function' in a function call.java.util.List<FunctionType>checkExtendsLoop()check if there is a loop in the type extends chainvoidclearCachedValues()Clear cached values.FunctionTypeforgetParameterAndReturnTypes()Create a new constructor with the parameters and return type stripped.java.lang.Iterable<ObjectType>getAllImplementedInterfaces()Returns all interfaces implemented by a class or its superclass and any superclasses for any of those interfaces.java.util.Collection<ObjectType>getAncestorInterfaces()FunctionTypegetBindReturnType(int argsToBind)Get the return value of calling "bind" on this function with the specified number of arguments.FunctionTypegetCanonicalRepresentation()ClosurePrimitivegetClosurePrimitive()Returns the@closurePrimitiveidentifier associated with this functionFunctionTypegetConstructor()Gets this object's constructor.com.google.common.collect.ImmutableList<TemplateType>getConstructorOnlyTemplateParameters()Returns a list of template types present on the constructor but not on the instance.com.google.common.collect.ImmutableList<ObjectType>getExtendedInterfaces()Returns interfaces directly extended by an interfaceintgetExtendedInterfacesCount()Returns the number of interfaces directly extended by an interfacejava.lang.StringgetGoogModuleId()The ID of the goog.module in which this type was declared.com.google.common.collect.ImmutableList<ObjectType>getImplementedInterfaces()Returns interfaces implemented directly by a class or its superclass.ObjectTypegetInstanceType()Gets the type of instance of this function.intgetMaxArity()Gets the maximum number of arguments that this function requires, or Integer.MAX_VALUE if this is a variable argument function.intgetMinArity()Gets the minimum number of arguments that this function requires.com.google.common.collect.ImmutableList<ObjectType>getOwnImplementedInterfaces()Returns interfaces directly implemented by the class.java.util.Set<java.lang.String>getOwnPropertyNames()Includes the prototype iff someone has created it.com.google.common.collect.ImmutableList<FunctionType.Parameter>getParameters()JSTypegetPropertyType(java.lang.String name)Gets the property type of the property whose name is given.java.util.Map<java.lang.String,JSType>getPropertyTypeMap()get the map of properties to types covered in a function typeObjectTypegetPrototype()Gets theprototypeproperty of this function type.ObjectTypegetPrototypeProperty()JSTypegetReturnType()PropertygetSlot(java.lang.String name)Default getSlot implementation.NodegetSource()Gets the source node or null if this is an unknown function.FunctionTypegetSuperClassConstructor()Given a constructor or an interface type, get its superclass constructor ornullif none exists.JSTypegetTypeOfThis()Gets the type ofthisin this function.booleanhasCachedValues()Returns true if any cached values have been set for this type.booleanhasEqualCallType(FunctionType that)booleanhasImplementedInterfaces()booleanhasInstanceType()Returns whether this function type has an instance type.booleanhasProperties()booleanisAbstract()booleanisAmbiguousConstructor()Returns true if the constructor does not come from a literal class or function in the AST, or if it extends such an ambiguous constructorbooleanisConstructor()Whether this type is aFunctionTypethat is a constructor or a named type that points to such a type.booleanisInstanceType()Whether this type is an Instance object of some constructor.booleanisInterface()Whether this type is aFunctionTypethat is an interface or a named type that points to such a type.booleanisOrdinaryFunction()Whether this type is aFunctionTypethat is an ordinary function (i.e.booleanisReturnTypeInferred()booleanisStructuralInterface()booleanmakesDicts()When a class B inherits from A and A is annotated as a dict, then B automatically gets the annotation, if B's constructor is not explicitly annotated.booleanmakesStructs()When a class B inherits from A and A is annotated as a struct, then B automatically gets the annotation, if B's constructor is not explicitly annotated.voidsetDict()voidsetExplicitUnrestricted()voidsetExtendedInterfaces(java.util.List<ObjectType> extendedInterfaces)voidsetImplementedInterfaces(java.util.List<ObjectType> implementedInterfaces)voidsetImplicitMatch(boolean flag)sets the current interface type to support structural interface matching (abbr.voidsetPrototypeBasedOn(ObjectType baseType)Sets the prototype, creating the prototype object from the given base type.voidsetSource(Node source)Sets the source node.voidsetStruct()FunctionType.BuildertoBuilder()Copies all the information from another function type.FunctionTypetoMaybeFunctionType()Downcasts this to a FunctionType, or returns null if this is not a function.<T> Tvisit(Visitor<T> visitor)Visit this type with the given visitor.-
Methods inherited from class com.google.javascript.rhino.jstype.PrototypeObjectType
getCtorExtendedInterfaces, getCtorImplementedInterfaces, getImplicitPrototype, getOwnerFunction, getReferenceName, getTemplateParamCount, isAnonymous, isNativeObjectType, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesSymbolContext, matchRecordTypeConstraint, removeProperty, setPropertyJSDocInfo, setPropertyNode
-
Methods inherited from class com.google.javascript.rhino.jstype.ObjectType
cast, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, findClosestDefinition, findPropertyTypeWithoutConsideringTemplateTypes, getClosestDefiningType, getDisplayName, getEnumeratedTypeOfEnumObject, getImplicitPrototypeChain, getJSDocInfo, getNormalizedReferenceName, getOwnPropertyDefSite, getOwnPropertyJSDocInfo, getOwnPropertyKind, getOwnSlot, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyDefSite, getPropertyJSDocInfo, getPropertyKind, getPropertyNames, getPropertyNode, getRawType, getTemplateTypes, hasOwnProperty, hasReferenceName, isFunctionPrototypeType, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, isStructuralType, isUnknownType, setJSDocInfo, testForEquality
-
Methods inherited from class com.google.javascript.rhino.jstype.JSType
areSimilar, assertFunctionType, assertObjectType, autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, collapseUnion, containsReferenceAncestor, dereference, differsFrom, equals, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getLeastSupertype, getPropertyKind, getRestrictedTypeGivenOutcome, getTemplateTypeMap, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, isAllType, isArrayType, isBigIntObjectType, isBigIntOrNumber, isBigIntValueType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isCheckedUnknownType, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isLiteralObject, isNamedType, isNominalConstructorOrInterface, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isOnlyBigInt, isRawTypeOfTemplatizedType, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStruct, isSubtype, isSubtype, isSubtypeOf, isSubtypeOf, isSubtypeWithoutStructuralTyping, isSuccessfullyResolved, isSymbol, isSymbolObjectType, isSymbolValueType, isTemplateType, isTemplatizedType, isUnionType, isUnsuccessfullyResolved, isVoidable, isVoidType, loosenTypecheckingDueToForwardReferencedSupertype, mergeSupertypeTemplateTypes, resolve, restrictByNotNull, restrictByNotNullOrUndefined, restrictByNotUndefined, setValidator, toAnnotationString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toObjectType, toString
-
-
-
-
Method Detail
-
getConstructor
public FunctionType getConstructor()
Description copied from class:ObjectTypeGets this object's constructor.- Overrides:
getConstructorin classPrototypeObjectType- Returns:
- this object's constructor or
nullif it is a native object (constructed natively v.s. by instantiation of a function)
-
isInstanceType
public final boolean isInstanceType()
Description copied from class:JSTypeWhether this type is an Instance object of some constructor. Does not necessarily mean this is anInstanceObjectType.- Overrides:
isInstanceTypein classJSType
-
isConstructor
public final boolean isConstructor()
Description copied from class:JSTypeWhether this type is aFunctionTypethat is a constructor or a named type that points to such a type.- Overrides:
isConstructorin classJSType
-
isInterface
public final boolean isInterface()
Description copied from class:JSTypeWhether this type is aFunctionTypethat is an interface or a named type that points to such a type.- Overrides:
isInterfacein classJSType
-
isOrdinaryFunction
public final boolean isOrdinaryFunction()
Description copied from class:JSTypeWhether this type is aFunctionTypethat is an ordinary function (i.e. not a constructor, nominal interface, or record interface), or a named type that points to such a type.- Overrides:
isOrdinaryFunctionin classJSType
-
makesStructs
public final boolean makesStructs()
When a class B inherits from A and A is annotated as a struct, then B automatically gets the annotation, if B's constructor is not explicitly annotated.
-
makesDicts
public final boolean makesDicts()
When a class B inherits from A and A is annotated as a dict, then B automatically gets the annotation, if B's constructor is not explicitly annotated.
-
setStruct
public final void setStruct()
-
setDict
public final void setDict()
-
setExplicitUnrestricted
public final void setExplicitUnrestricted()
-
toMaybeFunctionType
public FunctionType toMaybeFunctionType()
Description copied from class:JSTypeDowncasts this to a FunctionType, or returns null if this is not a function.For the purposes of this function, we define a MaybeFunctionType as any type in the sub-lattice { x | LEAST_FUNCTION_TYPE <= x <= GREATEST_FUNCTION_TYPE } This definition excludes bottom types like NoType and NoObjectType.
This definition is somewhat arbitrary and axiomatic, but this is the definition that makes the most sense for the most callers.
- Overrides:
toMaybeFunctionTypein classJSType
-
canBeCalled
public final boolean canBeCalled()
Description copied from class:JSTypeThis predicate is used to test whether a given type can be used as the 'function' in a function call.- Overrides:
canBeCalledin classJSType- Returns:
trueif this type might be callable.
-
hasImplementedInterfaces
public final boolean hasImplementedInterfaces()
-
getParameters
public final com.google.common.collect.ImmutableList<FunctionType.Parameter> getParameters()
-
getMinArity
public final int getMinArity()
Gets the minimum number of arguments that this function requires.
-
getMaxArity
public final int getMaxArity()
Gets the maximum number of arguments that this function requires, or Integer.MAX_VALUE if this is a variable argument function.
-
getReturnType
public final JSType getReturnType()
-
isReturnTypeInferred
public final boolean isReturnTypeInferred()
-
getSlot
public final Property getSlot(java.lang.String name)
Description copied from class:ObjectTypeDefault getSlot implementation. This gets overridden by FunctionType for lazily-resolved prototypes.- Overrides:
getSlotin classObjectType
-
getOwnPropertyNames
public final java.util.Set<java.lang.String> getOwnPropertyNames()
Includes the prototype iff someone has created it. We do not want to expose the prototype for ordinary functions.- Overrides:
getOwnPropertyNamesin classObjectType
-
getPrototypeProperty
public final ObjectType getPrototypeProperty()
-
getPrototype
public final ObjectType getPrototype()
Gets theprototypeproperty of this function type. This is equivalent to(ObjectType) getPropertyType("prototype").
-
setPrototypeBasedOn
public final void setPrototypeBasedOn(ObjectType baseType)
Sets the prototype, creating the prototype object from the given base type.- Parameters:
baseType- The base type.
-
getAllImplementedInterfaces
public final java.lang.Iterable<ObjectType> getAllImplementedInterfaces()
Returns all interfaces implemented by a class or its superclass and any superclasses for any of those interfaces. If this is called before all types are resolved, it may return an incomplete set.
-
getAncestorInterfaces
public final java.util.Collection<ObjectType> getAncestorInterfaces()
-
getImplementedInterfaces
public final com.google.common.collect.ImmutableList<ObjectType> getImplementedInterfaces()
Returns interfaces implemented directly by a class or its superclass.
-
getOwnImplementedInterfaces
public final com.google.common.collect.ImmutableList<ObjectType> getOwnImplementedInterfaces()
Returns interfaces directly implemented by the class.
-
setImplementedInterfaces
public final void setImplementedInterfaces(java.util.List<ObjectType> implementedInterfaces)
-
getExtendedInterfaces
public final com.google.common.collect.ImmutableList<ObjectType> getExtendedInterfaces()
Returns interfaces directly extended by an interface
-
getExtendedInterfacesCount
public final int getExtendedInterfacesCount()
Returns the number of interfaces directly extended by an interface
-
setExtendedInterfaces
public final void setExtendedInterfaces(java.util.List<ObjectType> extendedInterfaces)
-
getPropertyType
public final JSType getPropertyType(java.lang.String name)
Description copied from class:ObjectTypeGets the property type of the property whose name is given. If the underlying object does not have this property, the Unknown type is returned to indicate that no information is available on this property. This gets overridden by FunctionType for lazily-resolved call() and bind() functions.- Overrides:
getPropertyTypein classObjectType- Returns:
- the property's type or
UnknownType. This method never returnsnull.
-
getBindReturnType
public final FunctionType getBindReturnType(int argsToBind)
Get the return value of calling "bind" on this function with the specified number of arguments.If -1 is passed, then we will return a result that accepts any parameters.
-
getSuperClassConstructor
public final FunctionType getSuperClassConstructor()
Given a constructor or an interface type, get its superclass constructor ornullif none exists.- Overrides:
getSuperClassConstructorin classObjectType
-
hasEqualCallType
public final boolean hasEqualCallType(FunctionType that)
-
visit
public <T> T visit(Visitor<T> visitor)
Description copied from class:JSTypeVisit this type with the given visitor.- Overrides:
visitin classObjectType- Returns:
- the value returned by the visitor
- See Also:
Visitor
-
getInstanceType
public final ObjectType getInstanceType()
Gets the type of instance of this function. May return null if the `this` type can not be converted to "ObjectType" (see JSType#toObjectType).- Throws:
java.lang.IllegalStateException- if this function is not a constructor (seeisConstructor()).
-
hasInstanceType
public final boolean hasInstanceType()
Returns whether this function type has an instance type.
-
getTypeOfThis
public final JSType getTypeOfThis()
Gets the type ofthisin this function.- Overrides:
getTypeOfThisin classObjectType
-
getSource
public final Node getSource()
Gets the source node or null if this is an unknown function.- Specified by:
getSourcein interfaceJSType.WithSourceRef
-
getGoogModuleId
@Nullable public java.lang.String getGoogModuleId()
Description copied from interface:JSType.WithSourceRefThe ID of the goog.module in which this type was declared.- Specified by:
getGoogModuleIdin interfaceJSType.WithSourceRef
-
setSource
public final void setSource(Node source)
Sets the source node.
-
clearCachedValues
public final void clearCachedValues()
Description copied from class:ObjectTypeClear cached values. Should be called before making changes to a prototype that may have been changed since creation.- Overrides:
clearCachedValuesin classObjectType
-
hasCachedValues
public final boolean hasCachedValues()
Description copied from class:ObjectTypeReturns true if any cached values have been set for this type. If true, then the prototype chain should not be changed, as it might invalidate the cached values.- Overrides:
hasCachedValuesin classObjectType
-
hasProperties
public final boolean hasProperties()
-
setImplicitMatch
public final void setImplicitMatch(boolean flag)
sets the current interface type to support structural interface matching (abbr. SMI)- Parameters:
flag- indicates whether or not it should support SMI
-
isStructuralInterface
public final boolean isStructuralInterface()
- Overrides:
isStructuralInterfacein classJSType
-
isAbstract
public final boolean isAbstract()
-
getPropertyTypeMap
public final java.util.Map<java.lang.String,JSType> getPropertyTypeMap()
get the map of properties to types covered in a function type- Overrides:
getPropertyTypeMapin classObjectType- Returns:
- a Map that maps the property's name to the property's type
-
checkExtendsLoop
public final java.util.List<FunctionType> checkExtendsLoop()
check if there is a loop in the type extends chain- Returns:
- an array of all functions in the loop chain if a loop exists, otherwise returns null
-
acceptsArguments
public final boolean acceptsArguments(java.util.List<? extends JSType> argumentTypes)
-
forgetParameterAndReturnTypes
public final FunctionType forgetParameterAndReturnTypes()
Create a new constructor with the parameters and return type stripped.
-
getConstructorOnlyTemplateParameters
public final com.google.common.collect.ImmutableList<TemplateType> getConstructorOnlyTemplateParameters()
Returns a list of template types present on the constructor but not on the instance.
-
isAmbiguousConstructor
public final boolean isAmbiguousConstructor()
Returns true if the constructor does not come from a literal class or function in the AST, or if it extends such an ambiguous constructor
-
getClosurePrimitive
public final ClosurePrimitive getClosurePrimitive()
Returns the@closurePrimitiveidentifier associated with this function
-
builder
public static FunctionType.Builder builder(JSTypeRegistry registry)
-
toBuilder
public FunctionType.Builder toBuilder()
Copies all the information from another function type.
-
getCanonicalRepresentation
public final FunctionType getCanonicalRepresentation()
-
-