public class FunctionType extends PrototypeObjectType implements FunctionTypeI
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.
Modifier and Type | Class and Description |
---|---|
private static class |
FunctionType.Kind |
private static class |
FunctionType.PropAccess |
JSType.EqCache, JSType.ImplCache, JSType.MatchStatus, JSType.TypePair
Modifier and Type | Field and Description |
---|---|
private ArrowType |
call
[[Call]] property. |
private com.google.common.collect.ImmutableList<ObjectType> |
extendedInterfaces
The interfaces directly extended by this function (for interfaces)
It is only relevant for constructors.
|
private com.google.common.collect.ImmutableList<ObjectType> |
implementedInterfaces
The interfaces directly implemented by this function (for constructors)
It is only relevant for constructors.
|
private boolean |
isStructuralInterface
if this is an interface, indicate whether or not it supports
structural interface matching
|
private FunctionType.Kind |
kind
Whether a function is a constructor, an interface, or just an ordinary
function.
|
private FunctionType.PropAccess |
propAccess
Whether the instances are structs, dicts, or unrestricted.
|
private Property |
prototypeSlot
The
prototype property. |
private static long |
serialVersionUID |
private Node |
source
The function node which this type represents.
|
private java.util.List<FunctionType> |
subTypes
The types which are subtypes of this function.
|
private JSType |
typeOfThis
The type of
this in the scope of this function. |
ALPHA, registry, templateTypeMap
Modifier | Constructor and Description |
---|---|
(package private) |
FunctionType(JSTypeRegistry registry,
java.lang.String name,
Node source,
ArrowType arrowType,
JSType typeOfThis,
TemplateTypeMap templateTypeMap,
boolean isConstructor,
boolean nativeType)
Creates an instance for a function that might be a constructor.
|
private |
FunctionType(JSTypeRegistry registry,
java.lang.String name,
Node source,
TemplateTypeMap typeParameters)
Creates an instance for a function that is an interface.
|
Modifier and Type | Method and Description |
---|---|
private void |
addRelatedExtendedInterfaces(ObjectType instance,
java.util.Set<ObjectType> set) |
private void |
addRelatedInterfaces(ObjectType instance,
java.util.Set<ObjectType> set) |
private void |
addSubType(FunctionType subType)
Adds a type to the list of subtypes for this type.
|
(package private) void |
addSubTypeIfNotPresent(FunctionType subType) |
private void |
appendArgString(java.lang.StringBuilder b,
Node p,
boolean forAnnotations) |
private void |
appendOptionalArgString(java.lang.StringBuilder builder,
JSType paramType,
boolean forAnnotations)
Gets the string representation of an optional param.
|
private void |
appendVarArgsString(java.lang.StringBuilder builder,
JSType paramType,
boolean forAnnotations)
Gets the string representation of a var args param.
|
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
|
java.util.List<FunctionType> |
checkExtendsLoop(java.util.HashSet<FunctionType> cache,
java.util.List<FunctionType> path) |
(package private) boolean |
checkFunctionEquivalenceHelper(FunctionType that,
EquivalenceMethod eqMethod,
JSType.EqCache eqCache)
Two function types are equal if their signatures match.
|
void |
clearCachedValues()
Clear cached values.
|
TypeI |
convertMethodToFunction()
Creates a new function type B based on the original function type A.
|
(package private) boolean |
defineProperty(java.lang.String name,
JSType type,
boolean inferred,
Node propertyNode)
Defines a property.
|
boolean |
explicitlyImplOrExtInterface(FunctionType interfaceType)
check whether or not this function type has implemented
the given interface
if this function is an interface, check whether or not
this interface has extended the given interface
|
void |
extendTemplateTypeMapBasedOn(ObjectType type)
Extends the TemplateTypeMap of the function's this type, based on the
specified type.
|
FunctionType |
forgetParameterAndReturnTypes()
Create a new constructor with the parameters and return type stripped.
|
(package private) static FunctionType |
forInterface(JSTypeRegistry registry,
java.lang.String name,
Node source,
TemplateTypeMap typeParameters)
Creates an instance for a function that is an interface.
|
java.lang.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.
|
private FunctionType |
getCallOrBindSignature(boolean isCall)
Notice that "call" and "bind" have the same argument signature,
except that all the arguments of "bind" (except the first)
are optional.
|
private java.lang.String |
getDebugHashCodeStringOf(JSType type) |
java.lang.Iterable<ObjectType> |
getExtendedInterfaces()
Returns interfaces directly extended by an interface
|
int |
getExtendedInterfacesCount()
Returns the number of interfaces directly extended by an interface
|
java.lang.Iterable<ObjectType> |
getImplementedInterfaces()
Returns interfaces implemented directly by a class or its superclass.
|
ObjectType |
getInstanceType()
Gets the type of instance of this function.
|
(package private) ArrowType |
getInternalArrowType()
Gets the internal arrow type.
|
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.
|
java.lang.Iterable<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 an LP node that contains all params.
|
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. |
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.
|
java.util.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,
java.lang.String propertyName)
Given an interface and a property, finds the top-most super interface
that has the property defined (including this interface).
|
ObjectType |
getTopMostDefiningType(java.lang.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 |
hasProperties() |
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 or
a named type that points to such a type. |
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,
JSType.ImplCache implicitImplCache)
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, 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.
|
(package private) JSType |
resolveInternal(ErrorReporter t,
StaticTypedScope<JSType> scope) |
private com.google.common.collect.ImmutableList<ObjectType> |
resolveTypeListHelper(com.google.common.collect.ImmutableList<ObjectType> list,
ErrorReporter t,
StaticTypedScope<JSType> scope)
Resolve each item in the list, and return a new list if any
references changed.
|
void |
setDict() |
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.
|
(package private) void |
setInstanceType(ObjectType instanceType)
Sets the instance type.
|
(package private) boolean |
setPrototype(ObjectType prototype,
Node propertyNode)
Sets the prototype.
|
void |
setPrototypeBasedOn(ObjectType baseType)
Sets the prototype, creating the prototype object from the given
base type.
|
(package private) void |
setPrototypeBasedOn(ObjectType baseType,
Node propertyNode) |
private boolean |
setPrototypeNoCheck(ObjectType prototype,
Node propertyNode)
Set the prototype without doing any sanity checks.
|
void |
setSource(Node source)
Sets the source node.
|
void |
setStruct() |
(package private) FunctionType |
supAndInfHelper(FunctionType that,
boolean leastSuper)
Computes the supremum or infimum of two functions.
|
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.
|
(package private) java.lang.String |
toStringHelper(boolean forAnnotations)
Informally, a function is represented by
function (params): returnType where the params is a comma
separated list of types, the first one being a special
this:T if the function expects a known type for this . |
protected boolean |
treatThisTypesAsCovariant(FunctionType other,
JSType.ImplCache implicitImplCache) |
private FunctionType |
tryMergeFunctionPiecewise(FunctionType other,
boolean leastSuper)
Try to get the sup/inf of two functions by looking at the
piecewise components.
|
private static void |
updatePropertyTypeMap(FunctionType type,
java.util.Map<java.lang.String,JSType> propTypeMap,
java.util.HashSet<FunctionType> cache) |
(package private) <T> T |
visit(RelationshipVisitor<T> visitor,
JSType that)
Visit the types with the given visitor.
|
<T> T |
visit(Visitor<T> visitor)
Visit this type with the given visitor.
|
getConstructor, getCtorExtendedInterfaces, getCtorImplementedInterfaces, getImplicitPrototype, getOwnerFunction, getPropertyMap, getReferenceName, hasReferenceName, isAnonymous, isNativeObjectType, isPrettyPrint, isSubtype, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, matchRecordTypeConstraint, removeProperty, setImplicitPrototype, setOwnerFunction, setPrettyPrint, setPropertyJSDocInfo, setPropertyNode, unboxesTo
cast, checkStructuralEquivalenceHelper, collectPropertyNames, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, detectImplicitPrototypeCycle, detectInheritanceCycle, findPropertyType, getDisplayName, getJSDocInfo, getNormalizedReferenceName, getOwnPropertyJSDocInfo, getOwnSlot, getParentScope, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyNames, getPropertyNode, getRootNode, getTemplateTypes, hasOwnDeclaredProperty, hasOwnProperty, hasProperty, isFunctionPrototypeType, isImplicitPrototype, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, isStructuralSubtype, isStructuralType, isUnknownType, setJSDocInfo, testForEquality
autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, checkEquivalenceHelper, checkEquivalenceHelper, collapseUnion, dereference, differsFrom, equals, extendTemplateTypeMap, filterNoResolvedType, getGreatestSubtype, getGreatestSubtype, getLeastSupertype, getLeastSupertype, getNativeType, getRestrictedTypeGivenToBooleanOutcome, getTemplateTypeMap, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, hasAnyTemplateTypes, hasDisplayName, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isBottom, isCheckedUnknownType, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExemptFromTemplateTypeInvariance, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isNamedType, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isRecordType, isRegexpType, isResolved, isString, isStringObjectType, isStringValueType, isStruct, isSubtypeHelper, isSubtypeOf, isSubtypeWithoutStructuralTyping, isTemplateType, isTemplatizedType, isTheObjectType, isUnionType, isVoidable, isVoidType, matchesInt32Context, matchesUint32Context, resolve, restrictByNotNullOrUndefined, safeResolve, setResolvedTypeInternal, setValidator, testForEqualityHelper, toAnnotationString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toNonNullAnnotationString, toObjectType, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getReferenceName
isBottom, isEquivalentTo, isFunctionType, isSubtypeOf, isUnknownType, restrictByNotNullOrUndefined, toMaybeObjectType
private static final long serialVersionUID
private ArrowType call
[[Call]]
property.private Property prototypeSlot
prototype
property. This field is lazily initialized by
#getPrototype()
. The most important reason for lazily
initializing this field is that there are cycles in the native types
graph, so some prototypes must temporarily be null
during
the construction of the graph.
If non-null, the type must be a PrototypeObjectType.private final FunctionType.Kind kind
private FunctionType.PropAccess propAccess
private JSType typeOfThis
this
in the scope of this function.private Node source
null
.private boolean isStructuralInterface
private com.google.common.collect.ImmutableList<ObjectType> implementedInterfaces
null
.private com.google.common.collect.ImmutableList<ObjectType> extendedInterfaces
null
.private java.util.List<FunctionType> subTypes
null
.FunctionType(JSTypeRegistry registry, java.lang.String name, Node source, ArrowType arrowType, JSType typeOfThis, TemplateTypeMap templateTypeMap, boolean isConstructor, boolean nativeType)
private FunctionType(JSTypeRegistry registry, java.lang.String name, Node source, TemplateTypeMap typeParameters)
static FunctionType forInterface(JSTypeRegistry registry, java.lang.String name, Node source, TemplateTypeMap typeParameters)
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 interface TypeI
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 interface TypeI
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 interface TypeI
toMaybeFunctionType
in class JSType
public boolean canBeCalled()
JSType
canBeCalled
in class PrototypeObjectType
true
if this type might be callable.public boolean hasImplementedInterfaces()
public java.lang.Iterable<Node> getParameters()
public Node getParametersNode()
public int getMinArguments()
public int getMaxArguments()
public JSType getReturnType()
public boolean isReturnTypeInferred()
ArrowType getInternalArrowType()
public Property getSlot(java.lang.String name)
ObjectType
getSlot
in class ObjectType
public java.util.Set<java.lang.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.void setPrototypeBasedOn(ObjectType baseType, Node propertyNode)
public void extendTemplateTypeMapBasedOn(ObjectType type)
type
- boolean setPrototype(ObjectType prototype, Node propertyNode)
prototype
- the prototype. If this value is null
it will
silently be discarded.private boolean setPrototypeNoCheck(ObjectType prototype, Node propertyNode)
public boolean explicitlyImplOrExtInterface(FunctionType interfaceType)
interfaceType
- the interface typepublic java.lang.Iterable<ObjectType> getAllImplementedInterfaces()
private void addRelatedInterfaces(ObjectType instance, java.util.Set<ObjectType> set)
public java.lang.Iterable<ObjectType> getImplementedInterfaces()
public java.lang.Iterable<ObjectType> getOwnImplementedInterfaces()
public void setImplementedInterfaces(java.util.List<ObjectType> implementedInterfaces)
private void addRelatedExtendedInterfaces(ObjectType instance, java.util.Set<ObjectType> set)
public java.lang.Iterable<ObjectType> getExtendedInterfaces()
public int getExtendedInterfacesCount()
public void setExtendedInterfaces(java.util.List<ObjectType> extendedInterfaces) throws java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException
public JSType getPropertyType(java.lang.String name)
ObjectType
getPropertyType
in class ObjectType
UnknownType
. This method never
returns null
.public FunctionType getBindReturnType(int argsToBind)
private FunctionType getCallOrBindSignature(boolean isCall)
boolean defineProperty(java.lang.String name, JSType type, boolean inferred, Node propertyNode)
ObjectType
For clarity, callers should prefer ObjectType.defineDeclaredProperty(java.lang.String, com.google.javascript.rhino.jstype.JSType, com.google.javascript.rhino.Node)
and
ObjectType.defineInferredProperty(java.lang.String, com.google.javascript.rhino.jstype.JSType, com.google.javascript.rhino.Node)
.
defineProperty
in class PrototypeObjectType
name
- the property's nametype
- the typeinferred
- true
if this property's type is inferredpropertyNode
- the node that represents the definition of property.
Depending on the actual sub-type the node type might be different.
The general idea is to have an estimate of where in the source code
this property is defined.FunctionType supAndInfHelper(FunctionType that, boolean leastSuper)
leastSuper
- If true, compute the supremum of this
with
that
. Otherwise, compute the infimum.private FunctionType tryMergeFunctionPiecewise(FunctionType other, boolean leastSuper)
public FunctionType getSuperClassConstructor()
null
if none exists.public static ObjectType getTopDefiningInterface(ObjectType type, java.lang.String propertyName)
public ObjectType getTopMostDefiningType(java.lang.String propertyName)
boolean checkFunctionEquivalenceHelper(FunctionType that, EquivalenceMethod eqMethod, JSType.EqCache eqCache)
public boolean hasEqualCallType(FunctionType otherType)
java.lang.String toStringHelper(boolean forAnnotations)
function (params): returnType
where the params
is a comma
separated list of types, the first one being a special
this:T
if the function expects a known type for this
.toStringHelper
in class PrototypeObjectType
forAnnotations
- Whether this is for use in code generator
annotations. Otherwise, it's for warnings.private void appendArgString(java.lang.StringBuilder b, Node p, boolean forAnnotations)
private void appendVarArgsString(java.lang.StringBuilder builder, JSType paramType, boolean forAnnotations)
private void appendOptionalArgString(java.lang.StringBuilder builder, JSType paramType, boolean forAnnotations)
public boolean isSubtype(JSType that)
this
is a subtype of that
with regard to
the prototype chain.isSubtype
in class PrototypeObjectType
this <: that
protected boolean isSubtype(JSType that, JSType.ImplCache implicitImplCache)
JSType
isSubtype
in class PrototypeObjectType
implicitImplCache
- 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.protected boolean treatThisTypesAsCovariant(FunctionType other, JSType.ImplCache implicitImplCache)
public <T> T visit(Visitor<T> visitor)
JSType
visit
in class ObjectType
Visitor
<T> T visit(RelationshipVisitor<T> visitor, JSType that)
JSType
visit
in class ObjectType
RelationshipVisitor
public ObjectType getInstanceType()
getInstanceType
in interface FunctionTypeI
java.lang.IllegalStateException
- if this function is not a constructor
(see isConstructor()
).void setInstanceType(ObjectType instanceType)
public boolean hasInstanceType()
public JSType getTypeOfThis()
this
in this function.getTypeOfThis
in interface FunctionTypeI
getTypeOfThis
in class ObjectType
public Node getSource()
getSource
in interface FunctionTypeI
public void setSource(Node source)
setSource
in interface FunctionTypeI
void addSubTypeIfNotPresent(FunctionType subType)
private void addSubType(FunctionType subType)
public void clearCachedValues()
ObjectType
clearCachedValues
in class ObjectType
public java.util.List<FunctionType> getSubTypes()
getSubTypes
in interface FunctionTypeI
public boolean hasCachedValues()
ObjectType
hasCachedValues
in class PrototypeObjectType
JSType resolveInternal(ErrorReporter t, StaticTypedScope<JSType> scope)
private com.google.common.collect.ImmutableList<ObjectType> resolveTypeListHelper(com.google.common.collect.ImmutableList<ObjectType> list, ErrorReporter t, StaticTypedScope<JSType> scope)
public java.lang.String toDebugHashCodeString()
JSType
toDebugHashCodeString
in class JSType
private java.lang.String getDebugHashCodeStringOf(JSType type)
public FunctionType forgetParameterAndReturnTypes()
public boolean hasAnyTemplateTypesInternal()
hasAnyTemplateTypesInternal
in class JSType
public TypeI convertMethodToFunction()
FunctionTypeI
convertMethodToFunction
in interface FunctionTypeI
public boolean hasProperties()
hasProperties
in interface FunctionTypeI
public void setImplicitMatch(boolean flag)
flag
- indicates whether or not it should support SMIpublic boolean isStructuralInterface()
isStructuralInterface
in class JSType
public java.util.Map<java.lang.String,JSType> getPropertyTypeMap()
getPropertyTypeMap
in class ObjectType
private static void updatePropertyTypeMap(FunctionType type, java.util.Map<java.lang.String,JSType> propTypeMap, java.util.HashSet<FunctionType> cache)
public java.util.List<FunctionType> checkExtendsLoop()
public java.util.List<FunctionType> checkExtendsLoop(java.util.HashSet<FunctionType> cache, java.util.List<FunctionType> path)