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.SubtypingMode, JSType.TypePairTypeI.Nullability, TypeI.TypeInferencetemplateTypeMap| Modifier and Type | Method and Description |
|---|---|
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 explicitly declared by the programmer.
|
boolean |
defineInferredProperty(String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is inferred.
|
boolean |
defineSynthesizedProperty(String propertyName,
JSType type,
Node propertyNode)
Defines a property whose type is on a synthesized object.
|
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.
|
TypeI |
getEnumeratedTypeOfEnumObject()
If this type is an enum object, returns the declared type of the elements.
|
abstract ObjectType |
getImplicitPrototype()
Gets the implicit prototype (a.k.a.
|
JSDocInfo |
getJSDocInfo()
Gets the docInfo for this type.
|
JSType |
getLegacyResolvedType()
Only called on instances of NamedType.
|
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()
If this type represents the object in a function's prototype property, return that function.
|
Node |
getOwnPropertyDefSite(String propertyName) |
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.
|
Property |
getOwnSlot(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.
|
Node |
getPropertyDefSite(String propertyName) |
JSDocInfo |
getPropertyJSDocInfo(String propertyName) |
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.
|
JSType |
getPropertyType(String propertyName)
Gets the property type of the property whose name is given.
|
Map<String,JSType> |
getPropertyTypeMap()
get the map of properties to types covered in an object type
|
ObjectType |
getPrototypeObject()
Returns the __proto__ object of this object type, NOT the ".prototype" property.
|
ObjectType |
getRawType()
If this type is not generic, return as is.
|
abstract String |
getReferenceName()
Gets the reference name for this object.
|
Node |
getRootNode() |
Property |
getSlot(String name)
Default getSlot implementation.
|
FunctionTypeI |
getSuperClassConstructor() |
com.google.common.collect.ImmutableList<JSType> |
getTemplateTypes()
Gets the declared default element type.
|
ObjectType |
getTopDefiningInterface(String propertyName)
Given an interface and a property, finds a top-most super interface
that has the property defined (including this interface).
|
JSType |
getTypeOfThis() |
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.
|
boolean |
hasProperty(String propertyName)
Checks whether the property is present on the object.
|
boolean |
hasReferenceName() |
ObjectTypeI |
instantiateGenericsWithUnknown()
When this type represents an instance of a generic class/interface Foo, return an instance
of Foo with type parameters mapped to the unknown type.
|
boolean |
isAmbiguousObject()
Returns true if this object is an anonymous object or function type (i.e.
|
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.
|
boolean |
isPropertyTypeDeclared(String propertyName)
Checks whether the property's type is declared.
|
boolean |
isPropertyTypeInferred(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.
|
ObjectType |
normalizeObjectForCheckAccessControls()
Works around the OTI distinction between prototype-object types and other objects.
|
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. |
void |
setPropertyNode(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.
|
autobox, autoboxAndGetObject, autoboxesTo, canBeCalled, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, collapseUnion, containsArray, dereference, differsFrom, equals, extendTemplateTypeMap, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getGreatestSubtypeWithProperty, getLeastSupertype, getRestrictedTypeGivenToBooleanOutcome, getTemplateTypeMap, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isBottom, isBoxableScalar, isCheckedUnknownType, isConstructor, isDateType, isDict, isEmptyType, isEnumElement, isEnumElementType, isEnumObject, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExplicitlyVoidable, isFullyInstantiated, isFunctionType, isGenericObjectType, isGlobalThisType, isInstanceofObject, isInstanceType, isInterface, isLegacyNamedType, isLiteralObject, isNamedType, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isOrdinaryFunction, isPartiallyInstantiated, isPrototypeObject, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStruct, isStructuralInterface, isSubtype, isSubtype, isSubtype, isSubtypeOf, isSubtypeWithoutStructuralTyping, isTemplateType, isTemplatizedType, isTop, isTypeVariable, isUnionType, isUnresolved, isUnresolvedOrResolvedUnknown, isVoidable, isVoidType, matchConstraint, matchesInt32Context, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesUint32Context, meetWith, resolve, restrictByNotNullOrUndefined, setValidator, toAnnotationString, toDebugHashCodeString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toObjectType, toString, typeInference, unboxesToclone, finalize, getClass, notify, notifyAll, wait, wait, waitisInstanceType, isLegacyNamedTypeautobox, autoboxAndGetObject, containsArray, getEnumeratedTypeOfEnumElement, getGreatestSubtypeWithProperty, getTypeParameters, getUnionMembers, isBooleanValueType, isBottom, isBoxableScalar, isConstructor, isEnumElement, isEnumObject, isEquivalentTo, isFullyInstantiated, isFunctionType, isGenericObjectType, isInstanceofObject, isInterface, isLiteralObject, isNullable, isNullType, isNumberValueType, isObjectType, isPartiallyInstantiated, isPrototypeObject, isRecordType, isSomeUnknownType, isStringValueType, isStructuralInterface, isSubtypeOf, isSubtypeWithoutStructuralTyping, isTop, isTypeVariable, isUnionType, isUnresolved, isUnresolvedOrResolvedUnknown, isVoidable, isVoidType, meetWith, restrictByNotNullOrUndefined, toAnnotationString, toMaybeFunctionType, toMaybeObjectType, typeInferencepublic Node getRootNode()
public final ObjectType getParentScope()
public Property getSlot(String name)
public JSType getTypeOfThis()
public com.google.common.collect.ImmutableList<JSType> getTemplateTypes()
getTemplateTypes in interface ObjectTypeITemplatizedTypepublic JSDocInfo getJSDocInfo()
getJSDocInfo in interface TypeIgetJSDocInfo in class JSTypepublic void setJSDocInfo(JSDocInfo info)
@Nullable public abstract String getReferenceName()
null if this is an anonymous
object@Nullable public String getNormalizedReferenceName()
public String getDisplayName()
JSTypegetDisplayName in interface TypeIgetDisplayName in class JSTypepublic static String createDelegateSuffix(String suffix)
getNormalizedReferenceName()public boolean hasReferenceName()
public final boolean isAmbiguousObject()
ObjectTypeIisAmbiguousObject in interface ObjectTypeIpublic ObjectType getRawType()
ObjectTypeIgetRawType in interface ObjectTypeIpublic ObjectTypeI instantiateGenericsWithUnknown()
ObjectTypeIinstantiateGenericsWithUnknown in interface ObjectTypeIpublic 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()
getConstructor in interface ObjectTypeInull if it is a native
object (constructed natively v.s. by instantiation of a function)public FunctionTypeI getSuperClassConstructor()
getSuperClassConstructor in interface ObjectTypeIpublic ObjectType getTopDefiningInterface(String propertyName)
ObjectTypeIgetTopDefiningInterface in interface ObjectTypeIpublic abstract ObjectType getImplicitPrototype()
[[Prototype]] property).public final ObjectType getPrototypeObject()
ObjectTypeIgetPrototypeObject in interface ObjectTypeIpublic 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 defineSynthesizedProperty(String propertyName, JSType type, Node propertyNode)
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 namepublic Node getPropertyNode(String propertyName)
propertyName - the name of the propertyNode corresponding to the property or null.public Node getPropertyDefSite(String propertyName)
getPropertyDefSite in interface ObjectTypeIpublic JSDocInfo getPropertyJSDocInfo(String propertyName)
getPropertyJSDocInfo in interface ObjectTypeIpublic JSDocInfo getOwnPropertyJSDocInfo(String propertyName)
getOwnPropertyJSDocInfo in interface ObjectTypeIpublic Node getOwnPropertyDefSite(String propertyName)
getOwnPropertyDefSite in interface ObjectTypeIpublic void setPropertyJSDocInfo(String propertyName, JSDocInfo info)
JSDocInfo on its definition.info - JSDocInfo for the property definition. May be
null.public void setPropertyNode(String propertyName, Node defSite)
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 JSType getPropertyType(String propertyName)
getPropertyType in interface ObjectTypeIUnknownType. This method never
returns null.public boolean hasProperty(String propertyName)
JSTypehasProperty in interface ObjectTypeIhasProperty in class JSTypepropertyName - The property name.public boolean hasOwnProperty(String propertyName)
hasOwnProperty in interface ObjectTypeIpublic Set<String> getOwnPropertyNames()
getOwnPropertyNames in interface ObjectTypeIpublic boolean isPropertyTypeInferred(String propertyName)
public boolean isPropertyTypeDeclared(String propertyName)
public boolean isStructuralType()
isStructuralType in class JSTypepublic boolean isPropertyInExterns(String propertyName)
public int getPropertiesCount()
public Set<String> getPropertyNames()
getPropertyNames in interface ObjectTypeIpublic <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 interface TypeIisUnknownType in class JSTypepublic boolean isObject()
JSTypeObject, or any subtype thereof.public boolean hasCachedValues()
public void clearCachedValues()
public boolean isNativeObjectType()
public JSType getLegacyResolvedType()
ObjectTypeIgetLegacyResolvedType in interface ObjectTypeIpublic static ObjectType cast(JSType type)
public final boolean isFunctionPrototypeType()
JSTypeisFunctionPrototypeType in class JSTypepublic FunctionType getOwnerFunction()
ObjectTypeIgetOwnerFunction in interface ObjectTypeIpublic ObjectType normalizeObjectForCheckAccessControls()
ObjectTypeInormalizeObjectForCheckAccessControls in interface ObjectTypeIpublic Iterable<ObjectType> getCtorImplementedInterfaces()
public Iterable<ObjectType> getCtorExtendedInterfaces()
public Map<String,JSType> getPropertyTypeMap()
public TypeI getEnumeratedTypeOfEnumObject()
ObjectTypeIgetEnumeratedTypeOfEnumObject in interface ObjectTypeICopyright © 2009-2017 Google. All Rights Reserved.