public abstract class ObjectType extends JSType implements ObjectTypeI
/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.JSType.EqCache, JSType.ImplCache, JSType.MatchStatus, JSType.TypePair
Modifier and Type | Field and Description |
---|---|
private JSDocInfo |
docInfo |
private boolean |
unknown |
private boolean |
visited |
ALPHA, registry, templateTypeMap
Constructor and Description |
---|
ObjectType(JSTypeRegistry registry) |
ObjectType(JSTypeRegistry registry,
TemplateTypeMap templateTypeMap) |
Modifier and Type | Method and Description |
---|---|
static ObjectType |
cast(JSType type)
A null-safe version of JSType#toObjectType.
|
(package private) boolean |
checkStructuralEquivalenceHelper(ObjectType otherObject,
EquivalenceMethod eqMethod,
JSType.EqCache eqCache)
Check for structural equivalence with
that . |
void |
clearCachedValues()
Clear cached values.
|
(package private) void |
collectPropertyNames(java.util.Set<java.lang.String> props)
Adds any properties defined on this type or its supertypes to the set.
|
static java.lang.String |
createDelegateSuffix(java.lang.String suffix)
Creates a suffix for a proxy delegate.
|
boolean |
defineDeclaredProperty(java.lang.String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is explicitly declared by the programmer.
|
boolean |
defineInferredProperty(java.lang.String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is inferred.
|
(package private) abstract boolean |
defineProperty(java.lang.String propertyName,
JSType type,
boolean inferred,
Node propertyNode)
Defines a property.
|
boolean |
defineSynthesizedProperty(java.lang.String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is on a synthesized object.
|
(package private) boolean |
detectImplicitPrototypeCycle()
Detects a cycle in the implicit prototype chain.
|
(package private) boolean |
detectInheritanceCycle()
Detects cycles in either the implicit prototype chain, or the implemented/extended
interfaces.
|
JSType |
findPropertyType(java.lang.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.
|
java.lang.Iterable<ObjectType> |
getCtorExtendedInterfaces()
Gets the interfaces extended by the interface associated with this type.
|
java.lang.Iterable<ObjectType> |
getCtorImplementedInterfaces()
Gets the interfaces implemented by the ctor associated with this type.
|
java.lang.String |
getDisplayName()
Returns a user meaningful label for the JSType instance.
|
abstract ObjectType |
getImplicitPrototype()
Gets the implicit prototype (a.k.a.
|
JSDocInfo |
getJSDocInfo()
Gets the docInfo for this type.
|
java.lang.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(java.lang.String propertyName)
Gets the docInfo on the specified property on this type.
|
java.util.Set<java.lang.String> |
getOwnPropertyNames()
Returns the names of all the properties directly on this type.
|
Property |
getOwnSlot(java.lang.String name) |
ObjectType |
getParentScope() |
BooleanLiteralSet |
getPossibleToBooleanOutcomes()
Computes the set of possible outcomes of the
ToBoolean predicate
for this type. |
int |
getPropertiesCount()
Gets the number of properties of this object.
|
(package private) PropertyMap |
getPropertyMap()
Returns the property map that manages the set of properties for an object.
|
java.util.Set<java.lang.String> |
getPropertyNames()
Returns a list of properties defined or inferred on this type and any of
its supertypes.
|
Node |
getPropertyNode(java.lang.String propertyName)
Gets the node corresponding to the definition of the specified property.
|
JSType |
getPropertyType(java.lang.String propertyName)
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 an object type
|
abstract java.lang.String |
getReferenceName()
Gets the reference name for this object.
|
Node |
getRootNode() |
Property |
getSlot(java.lang.String name)
Default getSlot implementation.
|
com.google.common.collect.ImmutableList<JSType> |
getTemplateTypes()
Gets the declared default element type.
|
JSType |
getTypeOfThis() |
boolean |
hasCachedValues()
Returns true if any cached values have been set for this type.
|
(package private) boolean |
hasOwnDeclaredProperty(java.lang.String name)
Whether the given property is declared on this object.
|
boolean |
hasOwnProperty(java.lang.String propertyName)
Checks whether the property whose name is given is present directly on
the object.
|
boolean |
hasProperty(java.lang.String propertyName)
Checks whether the property is present on the object.
|
boolean |
hasReferenceName()
Returns true if the object is named.
|
boolean |
isFunctionPrototypeType()
Whether this is the prototype of a function.
|
(package private) boolean |
isImplicitPrototype(ObjectType prototype)
Checks that the prototype is an implicit prototype of this object.
|
boolean |
isNativeObjectType()
Whether this is a built-in object.
|
boolean |
isObject()
Tests whether this type is an
Object , or any subtype thereof. |
boolean |
isPropertyInExterns(java.lang.String propertyName)
Checks whether the property was defined in the externs.
|
boolean |
isPropertyTypeDeclared(java.lang.String propertyName)
Checks whether the property's type is declared.
|
boolean |
isPropertyTypeInferred(java.lang.String propertyName)
Checks whether the property's type is inferred.
|
(package private) boolean |
isStructuralSubtype(ObjectType superType,
JSType.ImplCache implicitImplCache)
Determine if
this is a an implicit subtype of superType . |
private static boolean |
isStructuralSubtypeHelper(ObjectType typeA,
ObjectType typeB,
JSType.ImplCache implicitImplCache) |
boolean |
isStructuralType() |
boolean |
isUnknownType()
We treat this as the unknown type if any of its implicit prototype
properties is unknown.
|
boolean |
removeProperty(java.lang.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 . |
(package private) void |
setOwnerFunction(FunctionType type)
Sets the owner function.
|
void |
setPropertyJSDocInfo(java.lang.String propertyName,
JSDocInfo info)
Sets the docInfo for the specified property from the
JSDocInfo on its definition. |
void |
setPropertyNode(java.lang.String propertyName,
Node defSite)
Sets the node where the property was defined.
|
TernaryValue |
testForEquality(JSType that)
Compares
this and that . |
(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.
|
autobox, autoboxesTo, canBeCalled, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, checkEquivalenceHelper, checkEquivalenceHelper, collapseUnion, dereference, differsFrom, equals, extendTemplateTypeMap, filterNoResolvedType, getGreatestSubtype, getGreatestSubtype, getLeastSupertype, getLeastSupertype, getNativeType, getRestrictedTypeGivenToBooleanOutcome, getTemplateTypeMap, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, hasAnyTemplateTypes, hasAnyTemplateTypesInternal, hasDisplayName, hashCode, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isBottom, isCheckedUnknownType, isConstructor, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExemptFromTemplateTypeInvariance, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isInstanceType, isInterface, isNamedType, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isOrdinaryFunction, isRecordType, isRegexpType, isResolved, isString, isStringObjectType, isStringValueType, isStruct, isStructuralInterface, isSubtype, isSubtype, isSubtypeHelper, isSubtypeOf, isSubtypeWithoutStructuralTyping, isTemplateType, isTemplatizedType, isTheObjectType, isUnionType, isVoidable, isVoidType, matchConstraint, matchesInt32Context, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesUint32Context, resolve, resolveInternal, restrictByNotNullOrUndefined, safeResolve, setResolvedTypeInternal, setValidator, testForEqualityHelper, toAnnotationString, toDebugHashCodeString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toNonNullAnnotationString, toObjectType, toString, toStringHelper, unboxesTo
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isBottom, isConstructor, isEquivalentTo, isFunctionType, isInterface, isSubtypeOf, restrictByNotNullOrUndefined, toMaybeFunctionType, toMaybeObjectType
private boolean visited
private JSDocInfo docInfo
private boolean unknown
ObjectType(JSTypeRegistry registry)
ObjectType(JSTypeRegistry registry, TemplateTypeMap templateTypeMap)
public Node getRootNode()
public ObjectType getParentScope()
PropertyMap getPropertyMap()
public Property getSlot(java.lang.String name)
public Property getOwnSlot(java.lang.String name)
public JSType getTypeOfThis()
public com.google.common.collect.ImmutableList<JSType> getTemplateTypes()
TemplatizedType
public JSDocInfo getJSDocInfo()
getJSDocInfo
in class JSType
public void setJSDocInfo(JSDocInfo info)
final boolean detectImplicitPrototypeCycle()
getImplicitPrototype()
method and must therefore be
invoked only after the object is sufficiently initialized to respond to
calls to this method.final boolean detectInheritanceCycle()
public abstract java.lang.String getReferenceName()
null
if this is an anonymous
objectpublic java.lang.String getNormalizedReferenceName()
public java.lang.String getDisplayName()
JSType
getDisplayName
in class JSType
public static java.lang.String createDelegateSuffix(java.lang.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()
getConstructor
in interface ObjectTypeI
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(java.lang.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 defineSynthesizedProperty(java.lang.String propertyName, JSType type, Node propertyNode)
public final boolean defineInferredProperty(java.lang.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
.abstract boolean defineProperty(java.lang.String propertyName, JSType type, boolean inferred, Node propertyNode)
For clarity, callers should prefer defineDeclaredProperty(java.lang.String, com.google.javascript.rhino.jstype.JSType, com.google.javascript.rhino.Node)
and
defineInferredProperty(java.lang.String, com.google.javascript.rhino.jstype.JSType, com.google.javascript.rhino.Node)
.
propertyName
- 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.public boolean removeProperty(java.lang.String propertyName)
propertyName
- the property's namepublic Node getPropertyNode(java.lang.String propertyName)
propertyName
- the name of the propertyNode
corresponding to the property or null.public JSDocInfo getOwnPropertyJSDocInfo(java.lang.String propertyName)
public void setPropertyJSDocInfo(java.lang.String propertyName, JSDocInfo info)
JSDocInfo
on its definition.info
- JSDocInfo
for the property definition. May be
null
.public void setPropertyNode(java.lang.String propertyName, Node defSite)
public JSType findPropertyType(java.lang.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 JSType getPropertyType(java.lang.String propertyName)
UnknownType
. This method never
returns null
.public boolean hasProperty(java.lang.String propertyName)
JSType
hasProperty
in class JSType
propertyName
- The property name.public boolean hasOwnProperty(java.lang.String propertyName)
public java.util.Set<java.lang.String> getOwnPropertyNames()
public boolean isPropertyTypeInferred(java.lang.String propertyName)
public boolean isPropertyTypeDeclared(java.lang.String propertyName)
public boolean isStructuralType()
isStructuralType
in class JSType
final boolean hasOwnDeclaredProperty(java.lang.String name)
public boolean isPropertyInExterns(java.lang.String propertyName)
public int getPropertiesCount()
boolean checkStructuralEquivalenceHelper(ObjectType otherObject, EquivalenceMethod eqMethod, JSType.EqCache eqCache)
that
.
(e.g. two @record types with the same prototype properties)private static boolean isStructuralSubtypeHelper(ObjectType typeA, ObjectType typeB, JSType.ImplCache implicitImplCache)
boolean isStructuralSubtype(ObjectType superType, JSType.ImplCache implicitImplCache)
this
is a an implicit subtype of superType
.public java.util.Set<java.lang.String> getPropertyNames()
final void collectPropertyNames(java.util.Set<java.lang.String> props)
public <T> T visit(Visitor<T> visitor)
JSType
<T> T visit(RelationshipVisitor<T> visitor, JSType that)
JSType
visit
in class JSType
RelationshipVisitor
final boolean isImplicitPrototype(ObjectType prototype)
prototype
- any prototype based objecttrue
if prototype
is equal
to any
object in this object's implicit prototype chain.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 interface TypeI
isUnknownType
in class JSType
public boolean isObject()
JSType
Object
, or any subtype thereof.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()
void setOwnerFunction(FunctionType type)
public java.lang.Iterable<ObjectType> getCtorImplementedInterfaces()
public java.lang.Iterable<ObjectType> getCtorExtendedInterfaces()
public java.util.Map<java.lang.String,JSType> getPropertyTypeMap()