public abstract class ObjectType extends JSType implements java.io.Serializable
/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.HasPropertyKind, JSType.Nullability, JSType.SubtypingMode, JSType.TypePairtemplateTypeMap| Modifier and Type | Method and Description |
|---|---|
static ObjectType |
cast(JSType type)
A null-safe version of JSType#toObjectType.
|
void |
clearCachedValues()
Clear cached values.
|
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.
|
boolean |
defineSynthesizedProperty(java.lang.String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is on a synthesized object.
|
Property.OwnedProperty |
findClosestDefinition(java.lang.String propertyName)
Returns the closest definition of the property including this type itself.
|
protected JSType |
findPropertyTypeWithoutConsideringTemplateTypes(java.lang.String propertyName)
Looks up a property on this type, but without properly replacing any templates in the result.
|
ObjectType |
getClosestDefiningType(java.lang.String propertyName)
Returns the closest ancestor that defines the property including this type itself.
|
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.
|
JSType |
getEnumeratedTypeOfEnumObject() |
abstract ObjectType |
getImplicitPrototype()
Gets the implicit prototype (a.k.a.
|
java.lang.Iterable<ObjectType> |
getImplicitPrototypeChain()
Returns a lazy, dynamic
Iterable for the types forming the implicit prototype chain of
this type. |
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() |
Node |
getOwnPropertyDefSite(java.lang.String propertyName) |
JSDocInfo |
getOwnPropertyJSDocInfo(java.lang.String propertyName)
Gets the docInfo on the specified property on this type.
|
JSType.HasPropertyKind |
getOwnPropertyKind(java.lang.String propertyName)
Checks whether the property whose name is given is present directly on
the object.
|
java.util.Set<java.lang.String> |
getOwnPropertyNames()
Returns the names of all the properties directly on this type.
|
Property |
getOwnSlot(java.lang.String name) |
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.
|
Node |
getPropertyDefSite(java.lang.String propertyName) |
JSDocInfo |
getPropertyJSDocInfo(java.lang.String propertyName) |
JSType.HasPropertyKind |
getPropertyKind(java.lang.String propertyName,
boolean autobox)
Checks whether the property is present on the 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
|
ObjectType |
getRawType() |
abstract java.lang.String |
getReferenceName()
Gets the reference name for this object.
|
Property |
getSlot(java.lang.String name)
Default getSlot implementation.
|
FunctionType |
getSuperClassConstructor() |
com.google.common.collect.ImmutableList<JSType> |
getTemplateTypes()
Gets the declared default element type.
|
ObjectType |
getTopMostDefiningType(java.lang.String propertyName)
Returns the top most type that defines the property.
|
JSType |
getTypeOfThis() |
boolean |
hasCachedValues()
Returns true if any cached values have been set for this type.
|
boolean |
hasOwnProperty(java.lang.String propertyName)
Checks whether the property whose name is given is present directly on
the object.
|
boolean |
hasReferenceName()
INVARIANT:
hasReferenceName() is true if and only if getReferenceName() returns
a non-null string. |
boolean |
isAmbiguousObject() |
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(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.
|
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. |
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. |
<T> T |
visit(Visitor<T> visitor)
Visit this type with the given visitor.
|
assertFunctionType, assertObjectType, autobox, autoboxesTo, canBeCalled, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, collapseUnion, containsReferenceAncestor, dereference, differsFrom, equals, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getGreatestSubtypeWithProperty, getLeastSupertype, getPropertyKind, getRestrictedTypeGivenToBooleanOutcome, getTemplateParamCount, getTemplateTypeMap, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isCheckedUnknownType, isConstructor, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isInstanceType, isInterface, isLiteralObject, isNamedType, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isOrdinaryFunction, isRawTypeOfTemplatizedType, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStruct, isStructuralInterface, isSubtype, isSubtype, isSubtypeOf, isSubtypeOf, isSubtypeWithoutStructuralTyping, isSuccessfullyResolved, isSymbol, isSymbolObjectType, isSymbolValueType, isTemplateType, isTemplatizedType, isTypeVariable, isUnionType, isUnresolved, isUnresolvedOrResolvedUnknown, isUnsuccessfullyResolved, isVoidable, isVoidType, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesSymbolContext, mergeSupertypeTemplateTypes, resolve, restrictByNotNull, restrictByNotNullOrUndefined, restrictByNotUndefined, setValidator, toAnnotationString, toDebugHashCodeString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toObjectType, toString, unboxesTopublic Property getSlot(java.lang.String name)
public final Property getOwnSlot(java.lang.String name)
public JSType getTypeOfThis()
public com.google.common.collect.ImmutableList<JSType> getTemplateTypes()
TemplatizedTypepublic JSDocInfo getJSDocInfo()
getJSDocInfo in class JSTypepublic void setJSDocInfo(JSDocInfo info)
@Nullable public abstract java.lang.String getReferenceName()
Returning an empty string means something different than returning null. An empty string may
indicate an anonymous constructor, which we treat differently than a literal type without a
reference name. e.g. in InstanceObjectType.appendTo(StringBuilder, boolean)
null if this is an anonymous objectpublic final boolean hasReferenceName()
hasReferenceName() is true if and only if getReferenceName() returns
a non-null string.@Nullable public final java.lang.String getNormalizedReferenceName()
public java.lang.String getDisplayName()
JSTypegetDisplayName in class JSTypepublic static java.lang.String createDelegateSuffix(java.lang.String suffix)
getNormalizedReferenceName()public boolean isAmbiguousObject()
public final ObjectType getRawType()
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 FunctionType getSuperClassConstructor()
public final ObjectType getTopMostDefiningType(java.lang.String propertyName)
Note: if you are doing type validation, you are probably looking for the closest definition
of the property which could be resolved by getClosestDefiningType(java.lang.String).
public final ObjectType getClosestDefiningType(java.lang.String propertyName)
public final Property.OwnedProperty findClosestDefinition(java.lang.String propertyName)
public abstract ObjectType getImplicitPrototype()
[[Prototype]] property).public final java.lang.Iterable<ObjectType> getImplicitPrototypeChain()
Iterable for the types forming the implicit prototype chain of
this type.
The chain is iterated bottom to top; from the nearest ancestor to the most distant.
Iteration stops when the next ancestor would be a null reference.
The created Iterators will not reflect changes to the prototype chain of elements it
has already iterated past, but will reflect those of upcoming elements. Neither the Iterable nor its Iterator support mutation.
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.public boolean removeProperty(java.lang.String propertyName)
propertyName - the property's namepublic final Node getPropertyNode(java.lang.String propertyName)
propertyName - the name of the propertyNode corresponding to the property or null.public final Node getPropertyDefSite(java.lang.String propertyName)
public final JSDocInfo getPropertyJSDocInfo(java.lang.String propertyName)
public final JSDocInfo getOwnPropertyJSDocInfo(java.lang.String propertyName)
public final Node getOwnPropertyDefSite(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)
protected JSType findPropertyTypeWithoutConsideringTemplateTypes(java.lang.String propertyName)
JSTypeSubclasses can override this if they need more complicated logic for property lookup than just autoboxing to an object.
This is only for use by findPropertyType(JSType). Call that method instead if you
need to lookup a property on a random JSType
findPropertyTypeWithoutConsideringTemplateTypes in class JSTypepublic JSType getPropertyType(java.lang.String propertyName)
UnknownType. This method never
returns null.public JSType.HasPropertyKind getPropertyKind(java.lang.String propertyName, boolean autobox)
JSTypegetPropertyKind in class JSTypepropertyName - The property name.autobox - Whether to check for the presents on an autoboxed typepublic final JSType.HasPropertyKind getOwnPropertyKind(java.lang.String propertyName)
public final boolean hasOwnProperty(java.lang.String propertyName)
public java.util.Set<java.lang.String> getOwnPropertyNames()
public final boolean isPropertyTypeInferred(java.lang.String propertyName)
public final boolean isPropertyTypeDeclared(java.lang.String propertyName)
public boolean isStructuralType()
isStructuralType in class JSTypepublic final boolean isPropertyInExterns(java.lang.String propertyName)
public final int getPropertiesCount()
public final java.util.Set<java.lang.String> getPropertyNames()
public <T> T visit(Visitor<T> visitor)
JSTypepublic 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.public boolean hasCachedValues()
public void clearCachedValues()
public boolean isNativeObjectType()
isNativeObjectType in class JSTypepublic static ObjectType cast(JSType type)
public final boolean isFunctionPrototypeType()
JSTypeisFunctionPrototypeType in class JSTypepublic FunctionType getOwnerFunction()
public java.lang.Iterable<ObjectType> getCtorImplementedInterfaces()
public java.lang.Iterable<ObjectType> getCtorExtendedInterfaces()
public java.util.Map<java.lang.String,JSType> getPropertyTypeMap()
public JSType getEnumeratedTypeOfEnumObject()
Copyright © 2009-2019 Google. All Rights Reserved.