|
|||||||||
| 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 |
|---|
| 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,
boolean inExterns,
Node propertyNode)
Defines a property whose type is synthesized (i.e. |
|
boolean |
defineInferredProperty(String propertyName,
JSType type,
boolean inExterns,
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> |
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. |
|
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. |
|
JSType |
getParameterType()
Gets the declared default element type. |
|
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. |
|
boolean |
hasCachedValues()
Returns true if any cached valeus 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 |
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. |
|
void |
setJSDocInfo(JSDocInfo info)
Sets the docInfo for this type from the given JSDocInfo. |
|
void |
setPropertyJSDocInfo(String propertyName,
JSDocInfo info,
boolean inExterns)
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, toString, wait, wait, wait |
| Method Detail |
|---|
public JSType getParameterType()
ParameterizedTypepublic JSType getIndexType()
IndexedTypepublic JSDocInfo getJSDocInfo()
getJSDocInfo in class JSTypepublic 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 JSTypepublic static String createDelegateSuffix(String suffix)
getNormalizedReferenceName()public boolean hasReferenceName()
public TernaryValue testForEquality(JSType that)
JSTypethis and that.
testForEquality in class JSTypeTernaryValue.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,
boolean inExterns,
Node propertyNode)
propertyName - the property's nametype - the typeinExterns - 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.propertyNode - the node corresponding to the declaration of property
which might later be accessed using getPropertyNode.
public final boolean defineInferredProperty(String propertyName,
JSType type,
boolean inExterns,
Node propertyNode)
propertyName - the property's nametype - the typeinExterns - 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.propertyNode - the node corresponding to the inferred definition of
property that might later be accessed using getPropertyNode.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,
boolean inExterns)
JSDocInfo on its definition.
info - 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 JSType findPropertyType(String propertyName)
JSTypegetPropertyType(java.lang.String), returns null if the property
is not found.
findPropertyType in class JSTypenull 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 JSTypeVisitorpublic BooleanLiteralSet getPossibleToBooleanOutcomes()
JSTypeToBoolean 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 JSTypepublic boolean isUnknownType()
isUnknownType in class JSTypepublic boolean isObject()
JSTypeObject, or any subtype thereof.
isObject in class JSTypethis <: Objectpublic boolean hasCachedValues()
public void clearCachedValues()
public boolean isNativeObjectType()
public static ObjectType cast(JSType type)
public Iterable<ObjectType> getCtorImplementedInterfaces()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||