|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.javascript.rhino.jstype.JSType
com.google.javascript.rhino.jstype.ObjectType
com.google.javascript.rhino.jstype.FunctionType
public class FunctionType
This derived type provides extended information about a function, including its return type and argument types.
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.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class com.google.javascript.rhino.jstype.JSType |
|---|
JSType.TypePair |
| Field Summary |
|---|
| Fields inherited from class com.google.javascript.rhino.jstype.JSType |
|---|
EMPTY_TYPE_COMPONENT, ENUMDECL, NOT_A_CLASS, NOT_A_TYPE, NOT_ENUMDECL, UNKNOWN_NAME |
| Method Summary | ||
|---|---|---|
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. |
|
Iterable<ObjectType> |
getAllImplementedInterfaces()
Returns all interfaces implemented by a class or its superclass and any superclasses for any of those interfaces. |
|
FunctionType |
getConstructor()
Gets this object's constructor. |
|
JSType |
getGreatestSubtype(JSType that)
Gets the greatest subtype of this and that. |
|
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. |
|
JSType |
getLeastSupertype(JSType that)
Gets the least supertype of this and that. |
|
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. |
|
JSDocInfo |
getOwnPropertyJSDocInfo(String propertyName)
Gets the docInfo on the specified property on this type. |
|
Set<String> |
getOwnPropertyNames()
Returns the names of all the properties directly on this type. |
|
Iterable<Node> |
getParameters()
|
|
Node |
getParametersNode()
Gets an LP node that contains all params. |
|
int |
getPropertiesCount()
Gets the number of properties of this object. |
|
Node |
getPropertyNode(String propertyName)
Gets the node corresponding to the definition of the specified property. |
|
JSType |
getPropertyType(String name)
Gets the property type of the property whose name is given. |
|
FunctionPrototypeType |
getPrototype()
Gets the prototype property of this function type. |
|
String |
getReferenceName()
Gets the reference name for this object. |
|
JSType |
getReturnType()
|
|
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. |
|
String |
getTemplateTypeName()
Gets the template type name. |
|
JSType |
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). |
|
ObjectType |
getTypeOfThis()
Gets the type of this in this function. |
|
boolean |
hasCachedValues()
Returns true if any cached valeus 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 |
hasOwnProperty(String name)
Checks whether the property whose name is given is present directly on the object. |
|
boolean |
hasProperty(String name)
Checks whether the property whose name is given is present on the object. |
|
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 |
isEquivalentTo(JSType otherType)
Two function types are equal if their signatures match. |
|
boolean |
isFunctionType()
|
|
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 |
isPropertyInExterns(String propertyName)
Checks whether the property was defined in the externs. |
|
boolean |
isPropertyTypeDeclared(String property)
Checks whether the property's type is declared. |
|
boolean |
isPropertyTypeInferred(String property)
Checks whether the property's type is inferred. |
|
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 |
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 |
setImplementedInterfaces(List<ObjectType> implementedInterfaces)
|
|
void |
setPropertyJSDocInfo(String propertyName,
JSDocInfo info,
boolean inExterns)
Sets the docInfo for the specified property from the JSDocInfo on its definition. |
|
boolean |
setPrototype(FunctionPrototypeType prototype)
Sets the prototype. |
|
void |
setPrototypeBasedOn(ObjectType baseType)
Sets the prototype, creating the prototype object from the given base type. |
|
void |
setSource(Node source)
Sets the source node. |
|
String |
toDebugHashCodeString()
A hash code function for diagnosing complicated issues around type-identity. |
|
String |
toString()
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. |
|
JSType |
unboxesTo()
Gets the type to which this type unboxes. |
|
|
visit(Visitor<T> visitor)
Visit this type with the given visitor. |
|
| Methods inherited from class com.google.javascript.rhino.jstype.ObjectType |
|---|
cast, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, findPropertyType, getCtorImplementedInterfaces, getDisplayName, getIndexType, getJSDocInfo, getNormalizedReferenceName, getParameterType, getPossibleToBooleanOutcomes, getPropertyNames, isObject, isUnknownType, setJSDocInfo, testForEquality |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public boolean isInstanceType()
JSType
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 boolean isInterface()
JSTypeFunctionType that is an interface or a named
type that points to such a type.
isInterface in class JSTypepublic boolean isOrdinaryFunction()
JSTypeFunctionType that is an ordinary function or
a named type that points to such a type.
isOrdinaryFunction in class JSTypepublic boolean isFunctionType()
isFunctionType in class JSTypepublic boolean canBeCalled()
JSType
true if this type might be callable.public boolean hasImplementedInterfaces()
public Iterable<Node> getParameters()
public Node getParametersNode()
public int getMinArguments()
public int getMaxArguments()
public JSType getReturnType()
public boolean isReturnTypeInferred()
public FunctionPrototypeType getPrototype()
prototype property of this function type. This is
equivalent to (ObjectType) getPropertyType("prototype").
public void setPrototypeBasedOn(ObjectType baseType)
baseType - The base type.public boolean setPrototype(FunctionPrototypeType prototype)
prototype - the prototype. If this value is null it will
silently be discarded.public Iterable<ObjectType> getAllImplementedInterfaces()
public Iterable<ObjectType> getImplementedInterfaces()
public void setImplementedInterfaces(List<ObjectType> implementedInterfaces)
public boolean hasProperty(String name)
ObjectType
public boolean hasOwnProperty(String name)
ObjectType
public JSType getPropertyType(String name)
ObjectType
UnknownType. This method never
returns null.public boolean isPropertyTypeInferred(String property)
ObjectType
public JSType getLeastSupertype(JSType that)
JSTypethis and that.
The least supertype is the join (∨) or supremum of both types in the
type lattice.Examples:
number ∨ * = *number ∨ Object = (number, Object)Number ∨ Object = Object
getLeastSupertype in class JSTypethis ∨ thatpublic JSType getGreatestSubtype(JSType that)
JSTypethis and that.
The greatest subtype is the meet (∧) or infimum of both types in the
type lattice.Examples
Number ∧ Any = Anynumber ∧ Object = AnyNumber ∧ Object = Number
getGreatestSubtype in class JSTypethis ∨ thatpublic FunctionType getSuperClassConstructor()
null if none exists.
public JSType getTopMostDefiningType(String propertyName)
public boolean isEquivalentTo(JSType otherType)
isEquivalentTo in class JSTypepublic int hashCode()
hashCode in class JSTypepublic boolean hasEqualCallType(FunctionType otherType)
public String toString()
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.
public boolean isSubtype(JSType that)
this is a subtype of that with regard to
the prototype chain.
this <: thatpublic <T> T visit(Visitor<T> visitor)
JSType
visit in class ObjectTypeVisitorpublic ObjectType getInstanceType()
IllegalStateException - if this function is not a constructor
(see isConstructor()).public boolean hasInstanceType()
public ObjectType getTypeOfThis()
this in this function.
public Node getSource()
public void setSource(Node source)
public void clearCachedValues()
ObjectType
clearCachedValues in class ObjectTypepublic List<FunctionType> getSubTypes()
public boolean hasCachedValues()
ObjectType
public String getTemplateTypeName()
public String toDebugHashCodeString()
JSType
toDebugHashCodeString in class JSTypepublic int getPropertiesCount()
getPropertiesCount in class ObjectTypepublic Set<String> getOwnPropertyNames()
ObjectType
getOwnPropertyNames in class ObjectTypepublic boolean isPropertyTypeDeclared(String property)
ObjectType
isPropertyTypeDeclared in class ObjectTypepublic boolean isPropertyInExterns(String propertyName)
ObjectType
isPropertyInExterns in class ObjectTypepublic Node getPropertyNode(String propertyName)
ObjectType
getPropertyNode in class ObjectTypepropertyName - the name of the property
Node corresponding to the property or null.public JSDocInfo getOwnPropertyJSDocInfo(String propertyName)
ObjectType
getOwnPropertyJSDocInfo in class ObjectType
public void setPropertyJSDocInfo(String propertyName,
JSDocInfo info,
boolean inExterns)
ObjectTypeJSDocInfo on its definition.
setPropertyJSDocInfo in class ObjectTypeinfo - JSDocInfo for the property definition. May be
null.inExterns - true if this property was defined in an externs
file. TightenTypes assumes that any function passed to an externs
property could be called, so setting this incorrectly could result
in live code being removed.public boolean matchesNumberContext()
JSType
matchesNumberContext in class JSTypepublic boolean matchesStringContext()
JSTypeString 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 JSTypepublic JSType unboxesTo()
JSType
unboxesTo in class JSTypenull if this type does not unbox.public boolean matchesObjectContext()
JSTypeObject 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 JSTypepublic FunctionType getConstructor()
ObjectType
getConstructor in class ObjectTypenull if it is a native
object (constructed natively v.s. by instantiation of a function)public ObjectType getImplicitPrototype()
ObjectType[[Prototype]] property).
getImplicitPrototype in class ObjectTypepublic String getReferenceName()
ObjectType
getReferenceName in class ObjectTypenull if this is an anonymous
objectpublic boolean hasReferenceName()
ObjectType
hasReferenceName in class ObjectTypepublic boolean isNativeObjectType()
isNativeObjectType in class ObjectType
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||