public class FunctionType extends PrototypeObjectType implements java.io.Serializable
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
FunctionType.Builder
A builder class for function and arrow types.
|
ObjectType.PropertyOptionalityJSType.HasPropertyKind, JSType.Nullability, JSType.SubtypingMode, JSType.TypePairtemplateTypeMap| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsArguments(java.util.List<? extends JSType> argumentTypes) |
static FunctionType.Builder |
builder(JSTypeRegistry registry) |
boolean |
canBeCalled()
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 chain
|
void |
clearCachedValues()
Clear cached values.
|
FunctionType |
forgetParameterAndReturnTypes()
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() |
FunctionType |
getBindReturnType(int argsToBind)
Get the return value of calling "bind" on this function with the specified number of arguments.
|
ClosurePrimitive |
getClosurePrimitive()
Returns the
@closurePrimitive identifier associated with this function |
com.google.common.collect.ImmutableList<TemplateType> |
getConstructorOnlyTemplateParameters()
Returns a list of template types present on the constructor but not on the instance.
|
java.lang.Iterable<FunctionType> |
getDirectSubTypes() |
com.google.common.collect.ImmutableList<ObjectType> |
getExtendedInterfaces()
Returns interfaces directly extended by an interface
|
int |
getExtendedInterfacesCount()
Returns the number of interfaces directly extended by an interface
|
com.google.common.collect.ImmutableList<ObjectType> |
getImplementedInterfaces()
Returns interfaces implemented directly by a class or its superclass.
|
ObjectType |
getInstanceType()
Gets the type of instance of this function.
|
int |
getMaxArity()
Gets the maximum number of arguments that this function requires, or Integer.MAX_VALUE if this
is a variable argument function.
|
int |
getMinArity()
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.
|
java.lang.Iterable<Node> |
getParameters() |
Node |
getParametersNode()
Gets a PARAM_LIST node that contains all params.
|
java.lang.Iterable<JSType> |
getParameterTypes() |
JSType |
getPropertyType(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 type
|
ObjectType |
getPrototype()
Gets the
prototype property of this function type. |
ObjectType |
getPrototypeProperty() |
JSType |
getReturnType() |
Property |
getSlot(java.lang.String name)
Default getSlot implementation.
|
Node |
getSource()
Gets the source node or null if this is an unknown function.
|
FunctionType |
getSuperClassConstructor()
Given a constructor or an interface type, get its superclass constructor or
null if
none exists. |
JSType |
getTypeOfThis()
Gets the type of
this in this function. |
boolean |
hasCachedValues()
Returns true if any cached values have been set for this type.
|
boolean |
hasEqualCallType(FunctionType otherType) |
boolean |
hasImplementedInterfaces() |
boolean |
hasInstanceType()
Returns whether this function type has an instance type.
|
boolean |
hasProperties() |
boolean |
isAbstract() |
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 |
isOrdinaryFunction()
Whether this type is a
FunctionType that is an ordinary function (i.e. |
boolean |
isReturnTypeInferred() |
boolean |
isStructuralInterface() |
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. |
protected boolean |
isSubtype(JSType that,
com.google.javascript.rhino.jstype.JSType.ImplCache implicitImplCache,
JSType.SubtypingMode subtypingMode)
checking isSubtype with structural interface matching
|
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.
|
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.
|
void |
setDict() |
void |
setExplicitUnrestricted() |
void |
setExtendedInterfaces(java.util.List<ObjectType> extendedInterfaces) |
void |
setImplementedInterfaces(java.util.List<ObjectType> implementedInterfaces) |
void |
setImplicitMatch(boolean flag)
sets the current interface type to support structural interface matching (abbr.
|
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() |
java.lang.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.
|
<T> T |
visit(Visitor<T> visitor)
Visit this type with the given visitor.
|
getConstructor, getCtorExtendedInterfaces, getCtorImplementedInterfaces, getImplicitPrototype, getOwnerFunction, getReferenceName, isAnonymous, isNativeObjectType, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesSymbolContext, matchRecordTypeConstraint, removeProperty, setPropertyJSDocInfo, setPropertyNode, unboxesTocast, 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, getTopMostDefiningType, hasOwnProperty, hasReferenceName, instantiateGenericsWithUnknown, isAmbiguousObject, isFunctionPrototypeType, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, isStructuralSubtypeHelper, isStructuralType, isUnknownType, setJSDocInfo, testForEqualityassertFunctionType, assertObjectType, autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, collapseUnion, dereference, differsFrom, equals, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getGreatestSubtypeWithProperty, getInstantiatedTypeArgument, getLeastSupertype, getPropertyKind, getRestrictedTypeGivenToBooleanOutcome, getTemplateTypeMap, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isCheckedUnknownType, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExplicitlyVoidable, isFullyInstantiated, isFunctionType, isGenericObjectType, isGlobalThisType, isLiteralObject, isNamedType, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isPartiallyInstantiated, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStruct, isSubtype, isSubtypeOf, isSubtypeWithoutStructuralTyping, isSuccessfullyResolved, isSymbol, isSymbolObjectType, isSymbolValueType, isTemplateType, isTemplatizedType, isTypeVariable, isUnionType, isUnresolved, isUnresolvedOrResolvedUnknown, isUnsuccessfullyResolved, isVoidable, isVoidType, meetWith, prependTemplateTypeMap, resolve, restrictByNotNullOrUndefined, restrictByNotUndefined, setValidator, toAnnotationString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toObjectType, toStringpublic final boolean isInstanceType()
JSTypeInstanceObjectType.isInstanceType in class JSTypepublic boolean isConstructor()
JSTypeFunctionType that is a constructor or a
named type that points to such a type.isConstructor in class JSTypepublic final boolean isInterface()
JSTypeFunctionType that is an interface or a named
type that points to such a type.isInterface in class JSTypepublic final boolean isOrdinaryFunction()
JSTypeFunctionType that is an ordinary function (i.e. not a
constructor, nominal interface, or record interface), or a named type that points to such a
type.isOrdinaryFunction in class JSTypepublic final boolean makesStructs()
public final boolean makesDicts()
public final void setStruct()
public final void setDict()
public final void setExplicitUnrestricted()
public FunctionType toMaybeFunctionType()
JSTypeFor 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.
toMaybeFunctionType in class JSTypepublic final boolean canBeCalled()
JSTypecanBeCalled in class JSTypetrue if this type might be callable.public final boolean hasImplementedInterfaces()
public final java.lang.Iterable<Node> getParameters()
public final java.lang.Iterable<JSType> getParameterTypes()
public final Node getParametersNode()
public final int getMinArity()
public final int getMaxArity()
public final JSType getReturnType()
public final boolean isReturnTypeInferred()
public final Property getSlot(java.lang.String name)
ObjectTypegetSlot in class ObjectTypepublic final java.util.Set<java.lang.String> getOwnPropertyNames()
getOwnPropertyNames in class ObjectTypepublic final ObjectType getPrototypeProperty()
public final ObjectType getPrototype()
prototype property of this function type. This is equivalent to (ObjectType) getPropertyType("prototype").public final void setPrototypeBasedOn(ObjectType baseType)
baseType - The base type.public final java.lang.Iterable<ObjectType> getAllImplementedInterfaces()
public final java.util.Collection<ObjectType> getAncestorInterfaces()
public final com.google.common.collect.ImmutableList<ObjectType> getImplementedInterfaces()
public final com.google.common.collect.ImmutableList<ObjectType> getOwnImplementedInterfaces()
public final void setImplementedInterfaces(java.util.List<ObjectType> implementedInterfaces)
public final com.google.common.collect.ImmutableList<ObjectType> getExtendedInterfaces()
public final int getExtendedInterfacesCount()
public final void setExtendedInterfaces(java.util.List<ObjectType> extendedInterfaces)
public final JSType getPropertyType(java.lang.String name)
ObjectTypegetPropertyType in class ObjectTypeUnknownType. This method never
returns null.public final FunctionType getBindReturnType(int argsToBind)
If -1 is passed, then we will return a result that accepts any parameters.
public final FunctionType getSuperClassConstructor()
null if
none exists.getSuperClassConstructor in class ObjectTypepublic final boolean hasEqualCallType(FunctionType otherType)
public boolean isSubtype(JSType that)
this is a subtype of that with regard to the prototype chain.isSubtype in class PrototypeObjectTypethis <: thatprotected boolean isSubtype(JSType that, com.google.javascript.rhino.jstype.JSType.ImplCache implicitImplCache, JSType.SubtypingMode subtypingMode)
JSTypeisSubtype in class PrototypeObjectTypeimplicitImplCache - a cache that records the checked
or currently checking type pairs, for example, if previous
checking found that constructor C is a subtype of interface I,
then in the cache, table key <I,C> maps to IMPLEMENT status.public <T> T visit(Visitor<T> visitor)
JSTypevisit in class ObjectTypeVisitorpublic final ObjectType getInstanceType()
java.lang.IllegalStateException - if this function is not a constructor (see isConstructor()).public final boolean hasInstanceType()
public final JSType getTypeOfThis()
this in this function.getTypeOfThis in class ObjectTypepublic final Node getSource()
public final void setSource(Node source)
public final void clearCachedValues()
ObjectTypeclearCachedValues in class ObjectTypepublic final java.lang.Iterable<FunctionType> getDirectSubTypes()
public final boolean hasCachedValues()
ObjectTypehasCachedValues in class ObjectTypepublic final java.lang.String toDebugHashCodeString()
JSTypetoDebugHashCodeString in class JSTypepublic final boolean hasProperties()
public final void setImplicitMatch(boolean flag)
flag - indicates whether or not it should support SMIpublic final boolean isStructuralInterface()
isStructuralInterface in class JSTypepublic final boolean isAbstract()
public final java.util.Map<java.lang.String,JSType> getPropertyTypeMap()
getPropertyTypeMap in class ObjectTypepublic final java.util.List<FunctionType> checkExtendsLoop()
public final boolean acceptsArguments(java.util.List<? extends JSType> argumentTypes)
public final FunctionType forgetParameterAndReturnTypes()
public final com.google.common.collect.ImmutableList<TemplateType> getConstructorOnlyTemplateParameters()
public final ClosurePrimitive getClosurePrimitive()
@closurePrimitive identifier associated with this functionpublic static FunctionType.Builder builder(JSTypeRegistry registry)
Copyright © 2009-2019 Google. All Rights Reserved.