|
|||||||||
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
public abstract class ObjectType
Object type.
In JavaScript, all object types have properties, and each of those
properties has a type. Property types may be DECLARED, INFERRED, or
UNKNOWN.
DECLARED properties have an explicit type annotation, as in:
/xx @type {number} x/
Foo.prototype.bar = 1;
This property may only hold number values, and an assignment to any
other type of value is an error.
INFERRED properties do not have an explicit type annotation. Rather,
we try to find all the possible types that this property can hold.
Foo.prototype.bar = 1;
If the programmer assigns other types of values to this property,
the property will take on the union of all these types.
UNKNOWN properties are properties on the UNKNOWN type. The UNKNOWN
type has all properties, but we do not know whether they are
declared or inferred.
Nested Class Summary | |
---|---|
static class |
ObjectType.Property
|
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 | ||
---|---|---|
static ObjectType |
cast(JSType type)
A null-safe version of JSType#toObjectType. |
|
void |
clearCachedValues()
Clear cached values. |
|
static String |
createDelegateSuffix(String suffix)
Creates a suffix for a proxy delegate. |
|
boolean |
defineDeclaredProperty(String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is synthesized (i.e. |
|
boolean |
defineInferredProperty(String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is inferred. |
|
JSType |
findPropertyType(String propertyName)
Coerces this type to an Object type, then gets the type of the property whose name is given. |
|
abstract 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. |
|
String |
getDisplayName()
Returns a user meaningful label for the JSType instance. |
|
abstract ObjectType |
getImplicitPrototype()
Gets the implicit prototype (a.k.a. |
|
JSType |
getIndexType()
Gets the declared default index type. |
|
JSDocInfo |
getJSDocInfo()
Gets the docInfo for this type. |
|
String |
getNormalizedReferenceName()
Due to the complexity of some of our internal type systems, sometimes we have different types constructed by the same constructor. |
|
FunctionType |
getOwnerFunction()
Gets the owner of this if it's a function prototype. |
|
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. |
|
ObjectType.Property |
getOwnSlot(String name)
Like getSlot but does not recurse into parent scopes. |
|
JSType |
getParameterType()
Gets the declared default element type. |
|
ObjectType |
getParentScope()
Returns the scope enclosing this one or null if none. |
|
BooleanLiteralSet |
getPossibleToBooleanOutcomes()
Computes the set of possible outcomes of the ToBoolean predicate
for this type. |
|
abstract int |
getPropertiesCount()
Gets the number of properties of this object. |
|
Set<String> |
getPropertyNames()
Returns a list of properties defined or inferred on this type and any of its supertypes. |
|
Node |
getPropertyNode(String propertyName)
Gets the node corresponding to the definition of the specified property. |
|
abstract JSType |
getPropertyType(String propertyName)
Gets the property type of the property whose name is given. |
|
abstract String |
getReferenceName()
Gets the reference name for this object. |
|
Node |
getRootNode()
Returns the root node associated with this scope. |
|
abstract ObjectType.Property |
getSlot(String name)
Returns any defined slot within this scope for this name. |
|
ObjectType |
getTypeOfThis()
Returns the expected type of this in the current scope. |
|
boolean |
hasCachedValues()
Returns true if any cached values have been set for this type. |
|
boolean |
hasOwnProperty(String propertyName)
Checks whether the property whose name is given is present directly on the object. |
|
abstract boolean |
hasProperty(String propertyName)
Checks whether the property whose name is given is present on the object. |
|
boolean |
hasReferenceName()
Returns true if the object is named. |
|
boolean |
isFunctionPrototypeType()
Whether this is the prototype of a function. |
|
boolean |
isNativeObjectType()
Whether this is a built-in object. |
|
boolean |
isObject()
Tests whether this type is an Object , or any subtype thereof. |
|
boolean |
isPropertyInExterns(String propertyName)
Checks whether the property was defined in the externs. |
|
abstract boolean |
isPropertyTypeDeclared(String propertyName)
Checks whether the property's type is declared. |
|
abstract boolean |
isPropertyTypeInferred(String propertyName)
Checks whether the property's type is inferred. |
|
boolean |
isUnknownType()
We treat this as the unknown type if any of its implicit prototype properties is unknown. |
|
boolean |
removeProperty(String propertyName)
Removes the declared or inferred property from this ObjectType. |
|
void |
setJSDocInfo(JSDocInfo info)
Sets the docInfo for this type from the given JSDocInfo . |
|
void |
setPropertyJSDocInfo(String propertyName,
JSDocInfo info)
Sets the docInfo for the specified property from the JSDocInfo on its definition. |
|
TernaryValue |
testForEquality(JSType that)
Compares this and that . |
|
|
visit(Visitor<T> visitor)
Visit this type with the given visitor. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public Node getRootNode()
StaticScope
getRootNode
in interface StaticScope<JSType>
public ObjectType getParentScope()
StaticScope
getParentScope
in interface StaticScope<JSType>
public abstract ObjectType.Property getSlot(String name)
StaticScope
getSlot
in interface StaticScope<JSType>
name
- The name of the variable slot to look up.
null
if no
definition exists.public ObjectType.Property getOwnSlot(String name)
StaticScope
getSlot
but does not recurse into parent scopes.
getOwnSlot
in interface StaticScope<JSType>
public ObjectType getTypeOfThis()
StaticScope
this
in the current scope.
getTypeOfThis
in interface StaticScope<JSType>
public JSType getParameterType()
ParameterizedType
public JSType getIndexType()
IndexedType
public JSDocInfo getJSDocInfo()
getJSDocInfo
in class JSType
public void setJSDocInfo(JSDocInfo info)
JSDocInfo
. The JSDocInfo
may be null
.
public abstract String getReferenceName()
null
if this is an anonymous
objectpublic String getNormalizedReferenceName()
public String getDisplayName()
JSType
getDisplayName
in class JSType
public static String createDelegateSuffix(String suffix)
getNormalizedReferenceName()
public boolean hasReferenceName()
public TernaryValue testForEquality(JSType that)
JSType
this
and that
.
testForEquality
in class JSType
TernaryValue.TRUE
if the comparison of values of
this
type and that
always succeed (such as
undefined
compared to null
)TernaryValue.FALSE
if the comparison of values of
this
type and that
always fails (such as
undefined
compared to number
)TernaryValue.UNKNOWN
if the comparison can succeed or
fail depending on the concrete valuespublic abstract FunctionType getConstructor()
null
if it is a native
object (constructed natively v.s. by instantiation of a function)public abstract ObjectType getImplicitPrototype()
[[Prototype]]
property).
public final boolean defineDeclaredProperty(String propertyName, JSType type, Node propertyNode)
propertyName
- the property's nametype
- the typepropertyNode
- the node corresponding to the declaration of property
which might later be accessed using getPropertyNode
.public final boolean defineInferredProperty(String propertyName, JSType type, Node propertyNode)
propertyName
- the property's nametype
- the typepropertyNode
- the node corresponding to the inferred definition of
property that might later be accessed using getPropertyNode
.public boolean removeProperty(String propertyName)
propertyName
- the property's name
public Node getPropertyNode(String propertyName)
propertyName
- the name of the property
Node
corresponding to the property or null.public JSDocInfo getOwnPropertyJSDocInfo(String propertyName)
public void setPropertyJSDocInfo(String propertyName, JSDocInfo info)
JSDocInfo
on its definition.
info
- JSDocInfo
for the property definition. May be
null
.public JSType findPropertyType(String propertyName)
JSType
getPropertyType(java.lang.String)
, returns null if the property
is not found.
findPropertyType
in class JSType
null
if the current type cannot
have properties, or if the type is not found.public abstract JSType getPropertyType(String propertyName)
UnknownType
. This method never
returns null
.public abstract boolean hasProperty(String propertyName)
public boolean hasOwnProperty(String propertyName)
public Set<String> getOwnPropertyNames()
public abstract boolean isPropertyTypeInferred(String propertyName)
public abstract boolean isPropertyTypeDeclared(String propertyName)
public boolean isPropertyInExterns(String propertyName)
public abstract int getPropertiesCount()
public Set<String> getPropertyNames()
public <T> T visit(Visitor<T> visitor)
JSType
visit
in class JSType
Visitor
public BooleanLiteralSet getPossibleToBooleanOutcomes()
JSType
ToBoolean
predicate
for this type. The ToBoolean
predicate is defined by the ECMA-262
standard, 3rd edition. Its behavior for simple types can be
summarized by the following table:
type | result |
---|---|
undefined | {false} |
null | {false} |
boolean | {true, false} |
number | {true, false} |
string | {true, false} |
Object | {true} |
getPossibleToBooleanOutcomes
in class JSType
public boolean isUnknownType()
isUnknownType
in class JSType
public boolean isObject()
JSType
Object
, or any subtype thereof.
isObject
in class JSType
this <: Object
public boolean hasCachedValues()
public void clearCachedValues()
public boolean isNativeObjectType()
public static ObjectType cast(JSType type)
public final boolean isFunctionPrototypeType()
JSType
isFunctionPrototypeType
in class JSType
public FunctionType getOwnerFunction()
public Iterable<ObjectType> getCtorImplementedInterfaces()
public Iterable<ObjectType> getCtorExtendedInterfaces()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |