public class FunctionType extends ObjectType
Note: the parameters list is the LP 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.
JSType.TypePair
EMPTY_TYPE_COMPONENT, ENUMDECL, NOT_A_CLASS, NOT_A_TYPE, NOT_ENUMDECL, templateTypeMap, UNKNOWN_NAME
Modifier and Type | Method and Description |
---|---|
boolean |
canBeCalled()
This predicate is used to test whether a given type can be used as the
'function' in a function call.
|
void |
clearCachedValues()
Clear cached values.
|
FunctionType |
cloneWithoutArrowType()
Create a new constructor with the parameters and return type stripped.
|
void |
extendTemplateTypeMapBasedOn(ObjectType type)
Extends the TemplateTypeMap of the function's this type, based on the
specified type.
|
Iterable<ObjectType> |
getAllExtendedInterfaces()
Returns all extended interfaces declared by an interfaces or its super-
interfaces.
|
Iterable<ObjectType> |
getAllImplementedInterfaces()
Returns all interfaces implemented by a class or its superclass and any
superclasses for any of those interfaces.
|
FunctionType |
getBindReturnType(int argsToBind)
Get the return value of calling "bind" on this function
with the specified number of arguments.
|
FunctionType |
getConstructor()
Gets this object's constructor.
|
Iterable<ObjectType> |
getCtorExtendedInterfaces()
Gets the interfaces extended by the interface associated with this type.
|
Iterable<ObjectType> |
getCtorImplementedInterfaces()
Gets the interfaces implemented by the ctor associated with this type.
|
Iterable<ObjectType> |
getExtendedInterfaces()
Returns interfaces directly extended by an interface
|
int |
getExtendedInterfacesCount()
Returns the number of interfaces directly extended by an interface
|
Iterable<ObjectType> |
getImplementedInterfaces()
Returns interfaces implemented directly by a class or its superclass.
|
ObjectType |
getImplicitPrototype()
Gets the implicit prototype (a.k.a.
|
ObjectType |
getInstanceType()
Gets the type of instance of this function.
|
int |
getMaxArguments()
Gets the maximum number of arguments that this function requires,
or Integer.MAX_VALUE if this is a variable argument function.
|
int |
getMinArguments()
Gets the minimum number of arguments that this function requires.
|
FunctionType |
getOwnerFunction()
Gets the owner of this if it's a function prototype.
|
Iterable<ObjectType> |
getOwnImplementedInterfaces()
Returns interfaces directly implemented by the class.
|
Set<String> |
getOwnPropertyNames()
Includes the prototype iff someone has created it.
|
Iterable<Node> |
getParameters() |
Node |
getParametersNode()
Gets an LP node that contains all params.
|
JSType |
getPropertyType(String name)
Gets the property type of the property whose name is given.
|
ObjectType |
getPrototype()
Gets the
prototype property of this function type. |
String |
getReferenceName()
Gets the reference name for this object.
|
JSType |
getReturnType() |
Property |
getSlot(String name)
Default getSlot implementation.
|
Node |
getSource()
Gets the source node or null if this is an unknown function.
|
List<FunctionType> |
getSubTypes()
Returns a list of types that are subtypes of this type.
|
FunctionType |
getSuperClassConstructor()
Given a constructor or an interface type, get its superclass constructor
or
null if none exists. |
static ObjectType |
getTopDefiningInterface(ObjectType type,
String propertyName)
Given an interface and a property, finds the top-most super interface
that has the property defined (including this interface).
|
ObjectType |
getTopMostDefiningType(String propertyName)
Given a constructor or an interface type and a property, finds the
top-most superclass that has the property defined (including this
constructor).
|
JSType |
getTypeOfThis()
Gets the type of
this in this function. |
boolean |
hasAnyTemplateTypesInternal() |
boolean |
hasCachedValues()
Returns true if any cached values have been set for this type.
|
boolean |
hasEqualCallType(FunctionType otherType) |
int |
hashCode() |
boolean |
hasImplementedInterfaces() |
boolean |
hasInstanceType()
Returns whether this function type has an instance type.
|
boolean |
hasReferenceName()
Returns true if the object is named.
|
boolean |
isConstructor()
Whether this type is a
FunctionType that is a constructor or a
named type that points to such a type. |
boolean |
isInstanceType()
Whether this type is an Instance object of some constructor.
|
boolean |
isInterface()
Whether this type is a
FunctionType that is an interface or a named
type that points to such a type. |
boolean |
isNativeObjectType()
Whether this is a built-in object.
|
boolean |
isOrdinaryFunction()
Whether this type is a
FunctionType that is an ordinary function or
a named type that points to such a type. |
boolean |
isReturnTypeInferred() |
boolean |
isSubtype(JSType that)
A function is a subtype of another if their call methods are related via
subtyping and
this is a subtype of that with regard to
the prototype chain. |
boolean |
makesDicts()
When a class B inherits from A and A is annotated as a dict, then B
automatically gets the annotation, even if B's constructor is not
explicitly annotated.
|
boolean |
makesStructs()
When a class B inherits from A and A is annotated as a struct, then B
automatically gets the annotation, even if B's constructor is not
explicitly annotated.
|
void |
matchConstraint(JSType constraint)
Modify this type so that it matches the specified type.
|
boolean |
matchesNumberContext()
This predicate is used to test whether a given type can appear in a
numeric context, such as an operand of a multiply operator.
|
boolean |
matchesObjectContext()
This predicate is used to test whether a given type can appear in an
Object context, such as the expression in a with statement. |
boolean |
matchesStringContext()
This predicate is used to test whether a given type can appear in a
String context, such as an operand of a string concat (+) operator. |
void |
matchRecordTypeConstraint(ObjectType constraintObj) |
boolean |
removeProperty(String name)
Removes the declared or inferred property from this ObjectType.
|
void |
setDict() |
void |
setExtendedInterfaces(List<ObjectType> extendedInterfaces) |
void |
setImplementedInterfaces(List<ObjectType> implementedInterfaces) |
void |
setPropertyJSDocInfo(String propertyName,
JSDocInfo info)
Sets the docInfo for the specified property from the
JSDocInfo on its definition. |
void |
setPrototypeBasedOn(ObjectType baseType)
Sets the prototype, creating the prototype object from the given
base type.
|
void |
setSource(Node source)
Sets the source node.
|
void |
setStruct() |
String |
toDebugHashCodeString()
A hash code function for diagnosing complicated issues
around type-identity.
|
FunctionType |
toMaybeFunctionType()
Downcasts this to a FunctionType, or returns null if this is not
a function.
|
JSType |
unboxesTo()
Turn an object type to its corresponding scalar type.
|
<T> T |
visit(Visitor<T> visitor)
Visit this type with the given visitor.
|
cast, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, findPropertyType, getDisplayName, getJSDocInfo, getNormalizedReferenceName, getOwnPropertyJSDocInfo, getOwnSlot, getParentScope, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyNames, getPropertyNode, getRootNode, getTemplateTypes, hasOwnProperty, hasProperty, isFunctionPrototypeType, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, isUnknownType, setJSDocInfo, testForEquality
autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, clearResolved, collapseUnion, dereference, differsFrom, equals, extendTemplateTypeMap, getGreatestSubtype, getLeastSupertype, getRestrictedTypeGivenToBooleanOutcome, getTemplateTypeMap, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, hasAnyTemplateTypes, hasDisplayName, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isCheckedUnknownType, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isFunctionType, isGlobalThisType, isInvariant, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isRecordType, isRegexpType, isResolved, isString, isStringObjectType, isStringValueType, isStruct, isTemplateType, isTemplatizedType, isUnionType, isVoidType, matchesInt32Context, matchesUint32Context, resolve, restrictByNotNullOrUndefined, setValidator, toAnnotationString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeTemplatizedType, toMaybeUnionType, toObjectType, toString
public boolean isInstanceType()
JSType
InstanceObjectType
.isInstanceType
in class JSType
public boolean isConstructor()
JSType
FunctionType
that is a constructor or a
named type that points to such a type.isConstructor
in class JSType
public boolean isInterface()
JSType
FunctionType
that is an interface or a named
type that points to such a type.isInterface
in class JSType
public boolean isOrdinaryFunction()
JSType
FunctionType
that is an ordinary function or
a named type that points to such a type.isOrdinaryFunction
in class JSType
public boolean makesStructs()
public boolean makesDicts()
public void setStruct()
public void setDict()
public FunctionType toMaybeFunctionType()
JSType
toMaybeFunctionType
in class JSType
public boolean canBeCalled()
JSType
true
if this type might be callable.public boolean hasImplementedInterfaces()
public Node getParametersNode()
public int getMinArguments()
public int getMaxArguments()
public JSType getReturnType()
public boolean isReturnTypeInferred()
public Property getSlot(String name)
ObjectType
getSlot
in interface StaticScope<JSType>
getSlot
in class ObjectType
name
- The name of the variable slot to look up.null
if no
definition exists.public Set<String> getOwnPropertyNames()
getOwnPropertyNames
in class ObjectType
public ObjectType getPrototype()
prototype
property of this function type. This is
equivalent to (ObjectType) getPropertyType("prototype")
.public void setPrototypeBasedOn(ObjectType baseType)
baseType
- The base type.public void extendTemplateTypeMapBasedOn(ObjectType type)
type
- public Iterable<ObjectType> getAllImplementedInterfaces()
public Iterable<ObjectType> getImplementedInterfaces()
public Iterable<ObjectType> getOwnImplementedInterfaces()
public void setImplementedInterfaces(List<ObjectType> implementedInterfaces)
public Iterable<ObjectType> getAllExtendedInterfaces()
public Iterable<ObjectType> getExtendedInterfaces()
public int getExtendedInterfacesCount()
public void setExtendedInterfaces(List<ObjectType> extendedInterfaces) throws UnsupportedOperationException
UnsupportedOperationException
public JSType getPropertyType(String name)
ObjectType
getPropertyType
in class ObjectType
UnknownType
. This method never
returns null
.public FunctionType getBindReturnType(int argsToBind)
public FunctionType getSuperClassConstructor()
null
if none exists.public static ObjectType getTopDefiningInterface(ObjectType type, String propertyName)
public ObjectType getTopMostDefiningType(String propertyName)
public boolean hasEqualCallType(FunctionType otherType)
public boolean isSubtype(JSType that)
this
is a subtype of that
with regard to
the prototype chain.this <: that
public <T> T visit(Visitor<T> visitor)
JSType
visit
in class ObjectType
Visitor
public ObjectType getInstanceType()
IllegalStateException
- if this function is not a constructor
(see isConstructor()
).public boolean hasInstanceType()
public JSType getTypeOfThis()
this
in this function.getTypeOfThis
in interface StaticScope<JSType>
getTypeOfThis
in class ObjectType
public Node getSource()
public void setSource(Node source)
public void clearCachedValues()
ObjectType
clearCachedValues
in class ObjectType
public List<FunctionType> getSubTypes()
public boolean hasCachedValues()
ObjectType
public String toDebugHashCodeString()
JSType
toDebugHashCodeString
in class JSType
public FunctionType cloneWithoutArrowType()
public boolean hasAnyTemplateTypesInternal()
public boolean removeProperty(String name)
ObjectType
removeProperty
in class ObjectType
name
- the property's namepublic void setPropertyJSDocInfo(String propertyName, JSDocInfo info)
ObjectType
JSDocInfo
on its definition.setPropertyJSDocInfo
in class ObjectType
info
- JSDocInfo
for the property definition. May be
null
.public boolean matchesNumberContext()
JSType
matchesNumberContext
in class JSType
public boolean matchesStringContext()
JSType
String
context, such as an operand of a string concat (+) operator.
All types have at least the potential for converting to String
.
When we add externally defined types, such as a browser OM, we may choose
to add types that do not automatically convert to String
.matchesStringContext
in class JSType
public JSType unboxesTo()
JSType
public boolean matchesObjectContext()
JSType
Object
context, such as the expression in a with statement.
Most types we will encounter, except notably null
, have at least
the potential for converting to Object
. Host defined objects can
get peculiar.matchesObjectContext
in class JSType
public FunctionType getConstructor()
ObjectType
getConstructor
in class ObjectType
null
if it is a native
object (constructed natively v.s. by instantiation of a function)public ObjectType getImplicitPrototype()
ObjectType
[[Prototype]]
property).getImplicitPrototype
in class ObjectType
public String getReferenceName()
ObjectType
getReferenceName
in class ObjectType
null
if this is an anonymous
objectpublic boolean hasReferenceName()
ObjectType
hasReferenceName
in class ObjectType
public boolean isNativeObjectType()
isNativeObjectType
in class ObjectType
public FunctionType getOwnerFunction()
ObjectType
getOwnerFunction
in class ObjectType
public Iterable<ObjectType> getCtorImplementedInterfaces()
ObjectType
getCtorImplementedInterfaces
in class ObjectType
public Iterable<ObjectType> getCtorExtendedInterfaces()
ObjectType
getCtorExtendedInterfaces
in class ObjectType
public void matchConstraint(JSType constraint)
JSType
matchConstraint
in class JSType
public void matchRecordTypeConstraint(ObjectType constraintObj)
Copyright © 2009–2014 Google. All rights reserved.