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.TypePair
templateTypeMap
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.
|
abstract ObjectType |
getImplicitPrototype()
Gets the implicit prototype (a.k.a.
|
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.
|
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.
|
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
|
abstract String |
getReferenceName()
Gets the reference name for this object.
|
Node |
getRootNode() |
Property |
getSlot(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.
|
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()
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.
|
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.
|
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, autoboxesTo, canBeCalled, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, collapseUnion, dereference, differsFrom, equals, extendTemplateTypeMap, getGreatestSubtype, getLeastSupertype, getRestrictedTypeGivenToBooleanOutcome, getTemplateTypeMap, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, hasAnyTemplateTypes, hasDisplayName, hashCode, isAllType, isArrayType, isBooleanObjectType, isBooleanValueType, isBottom, isCheckedUnknownType, isConstructor, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, 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, isSubtypeOf, isSubtypeWithoutStructuralTyping, isTemplateType, isTemplatizedType, isUnionType, isVoidable, isVoidType, matchConstraint, matchesInt32Context, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesUint32Context, resolve, restrictByNotNullOrUndefined, setValidator, toAnnotationString, toDebugHashCodeString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toNonNullAnnotationString, toObjectType, toString, unboxesTo
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isBottom, isConstructor, isEquivalentTo, isFunctionType, isInterface, isSubtypeOf, restrictByNotNullOrUndefined, toMaybeFunctionType, toMaybeObjectType
public Node getRootNode()
public ObjectType getParentScope()
public Property getSlot(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)
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()
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(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 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 void setPropertyNode(String propertyName, Node defSite)
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 JSType getPropertyType(String propertyName)
UnknownType
. This method never
returns null
.public boolean hasProperty(String propertyName)
JSType
hasProperty
in class JSType
propertyName
- The property name.public boolean hasOwnProperty(String propertyName)
public Set<String> getOwnPropertyNames()
public boolean isPropertyTypeInferred(String propertyName)
public boolean isPropertyTypeDeclared(String propertyName)
public boolean isStructuralType()
isStructuralType
in class JSType
public boolean isPropertyInExterns(String propertyName)
public int getPropertiesCount()
public Set<String> getPropertyNames()
public <T> T visit(Visitor<T> visitor)
JSType
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()
public Iterable<ObjectType> getCtorImplementedInterfaces()
public Iterable<ObjectType> getCtorExtendedInterfaces()
Copyright © 2009–2023 Google. All rights reserved.