Class PrototypeObjectType
- java.lang.Object
-
- com.google.javascript.rhino.jstype.JSType
-
- com.google.javascript.rhino.jstype.ObjectType
-
- com.google.javascript.rhino.jstype.PrototypeObjectType
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
EnumType
,FunctionType
,RecordType
public class PrototypeObjectType extends ObjectType
The object type represents instances of JavaScript objects such asObject
,Date
,Function
.Objects in JavaScript are unordered collections of properties. Each property consists of a name, a value and a set of attributes.
Each instance has an implicit prototype property (
[[Prototype]]
) pointing to an object instance, which itself has an implicit property, thus forming a chain.A class begins life with no name. Later, a name may be provided once it can be inferred. Note that the name in this case is strictly for debugging purposes. Looking up type name references goes through the
JSTypeRegistry
.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.javascript.rhino.jstype.JSType
JSType.HasPropertyKind, JSType.Nullability, JSType.SubtypingMode, JSType.TypePair
-
-
Field Summary
-
Fields inherited from class com.google.javascript.rhino.jstype.JSType
templateTypeMap
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.ObjectType
getImplicitPrototype()
Gets the implicit prototype (a.k.a.FunctionType
getOwnerFunction()
java.lang.String
getReferenceName()
Gets the reference name for this object.int
getTemplateParamCount()
Return the number of template parameters declared for this type.boolean
isAnonymous()
boolean
isNativeObjectType()
Whether this is a built-in object.void
matchConstraint(JSType constraint)
Modify this type so that it matches the specified type.boolean
matchesNumberContext()
This predicate is used to test whether a given type can appear in a numeric context, such as an operand of a multiply operator.boolean
matchesObjectContext()
This predicate is used to test whether a given type can appear in anObject
context, such as the expression in a with statement.boolean
matchesStringContext()
This predicate is used to test whether a given type can appear in aString
context, such as an operand of a string concat (+) operator.boolean
matchesSymbolContext()
This predicate is used to test whether a given type can appear in asymbol
context such as property access.void
matchRecordTypeConstraint(ObjectType constraintObj)
boolean
removeProperty(java.lang.String name)
Removes the declared or inferred property from this ObjectType.void
setPropertyJSDocInfo(java.lang.String propertyName, JSDocInfo info)
Sets the docInfo for the specified property from theJSDocInfo
on its definition.void
setPropertyNode(java.lang.String propertyName, Node defSite)
Sets the node where the property was defined.JSType
unboxesTo()
Turn an object type to its corresponding scalar type.-
Methods inherited from class com.google.javascript.rhino.jstype.ObjectType
cast, clearCachedValues, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, findClosestDefinition, findPropertyTypeWithoutConsideringTemplateTypes, getClosestDefiningType, getDisplayName, getEnumeratedTypeOfEnumObject, getImplicitPrototypeChain, getJSDocInfo, getNormalizedReferenceName, getOwnPropertyDefSite, getOwnPropertyJSDocInfo, getOwnPropertyKind, getOwnPropertyNames, getOwnSlot, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyDefSite, getPropertyJSDocInfo, getPropertyKind, getPropertyNames, getPropertyNode, getPropertyType, getPropertyTypeMap, getRawType, getSlot, getSuperClassConstructor, getTemplateTypes, getTopMostDefiningType, getTypeOfThis, hasCachedValues, hasOwnProperty, hasReferenceName, isAmbiguousObject, isFunctionPrototypeType, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, isStructuralType, isUnknownType, setJSDocInfo, testForEquality, visit
-
Methods inherited from class com.google.javascript.rhino.jstype.JSType
areIdentical, assertFunctionType, assertObjectType, autobox, autoboxesTo, canBeCalled, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, collapseUnion, containsReferenceAncestor, dereference, differsFrom, equals, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getGreatestSubtypeWithProperty, getLeastSupertype, getPropertyKind, getRestrictedTypeGivenOutcome, getTemplateTypeMap, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, isAllType, isArrayType, isBigIntObjectType, isBigIntOrNumber, isBigIntValueType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isCheckedUnknownType, isConstructor, isDateType, isDict, isEmptyType, isEnumElementType, isEnumType, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isInstanceType, isInterface, isLiteralObject, isNamedType, isNominalConstructor, isNominalType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isOnlyBigInt, isOrdinaryFunction, isRawTypeOfTemplatizedType, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStruct, isStructuralInterface, isSubtype, isSubtype, isSubtypeOf, isSubtypeOf, isSubtypeWithoutStructuralTyping, isSuccessfullyResolved, isSymbol, isSymbolObjectType, isSymbolValueType, isTemplateType, isTemplatizedType, isUnionType, isUnresolved, isUnresolvedOrResolvedUnknown, isUnsuccessfullyResolved, isVoidable, isVoidType, loosenTypecheckingDueToForwardReferencedSupertype, mergeSupertypeTemplateTypes, resolve, restrictByNotNull, restrictByNotNullOrUndefined, restrictByNotUndefined, setValidator, toAnnotationString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeFunctionType, toMaybeNamedType, toMaybeObjectType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, toObjectType, toString
-
-
-
-
Method Detail
-
removeProperty
public boolean removeProperty(java.lang.String name)
Description copied from class:ObjectType
Removes the declared or inferred property from this ObjectType.- Overrides:
removeProperty
in classObjectType
- Parameters:
name
- the property's name- Returns:
- true if the property was removed successfully. False if the property did not exist, or could not be removed.
-
setPropertyJSDocInfo
public void setPropertyJSDocInfo(java.lang.String propertyName, JSDocInfo info)
Description copied from class:ObjectType
Sets the docInfo for the specified property from theJSDocInfo
on its definition.- Overrides:
setPropertyJSDocInfo
in classObjectType
info
-JSDocInfo
for the property definition. May benull
.
-
setPropertyNode
public void setPropertyNode(java.lang.String propertyName, Node defSite)
Description copied from class:ObjectType
Sets the node where the property was defined.- Overrides:
setPropertyNode
in classObjectType
-
matchesNumberContext
public boolean matchesNumberContext()
Description copied from class:JSType
This predicate is used to test whether a given type can appear in a numeric context, such as an operand of a multiply operator.- Overrides:
matchesNumberContext
in classJSType
-
matchesStringContext
public boolean matchesStringContext()
Description copied from class:JSType
This predicate is used to test whether a given type can appear in aString
context, such as an operand of a string concat (+) operator. All types have at least the potential for converting toString
. When we add externally defined types, such as a browser OM, we may choose to add types that do not automatically convert toString
.- Overrides:
matchesStringContext
in classJSType
-
matchesSymbolContext
public boolean matchesSymbolContext()
Description copied from class:JSType
This predicate is used to test whether a given type can appear in asymbol
context such as property access.- Overrides:
matchesSymbolContext
in classJSType
-
unboxesTo
public final JSType unboxesTo()
Description copied from class:JSType
Turn an object type to its corresponding scalar type.
-
matchesObjectContext
public boolean matchesObjectContext()
Description copied from class:JSType
This predicate is used to test whether a given type can appear in anObject
context, such as the expression in a with statement. Most types we will encounter, except notablynull
, have at least the potential for converting toObject
. Host defined objects can get peculiar.- Overrides:
matchesObjectContext
in classJSType
-
getConstructor
public FunctionType getConstructor()
Description copied from class:ObjectType
Gets this object's constructor.- Specified by:
getConstructor
in classObjectType
- Returns:
- this object's constructor or
null
if it is a native object (constructed natively v.s. by instantiation of a function)
-
getImplicitPrototype
public ObjectType getImplicitPrototype()
Description copied from class:ObjectType
Gets the implicit prototype (a.k.a. the[[Prototype]]
property).- Specified by:
getImplicitPrototype
in classObjectType
-
getTemplateParamCount
public final int getTemplateParamCount()
Description copied from class:JSType
Return the number of template parameters declared for this type.In general, this value corresponds to the number of `@template` declarations on the type definition. It does not include template parameters from superclasses or superinterfaces.
- Overrides:
getTemplateParamCount
in classJSType
-
getReferenceName
public java.lang.String getReferenceName()
Description copied from class:ObjectType
Gets the reference name for this object. This includes named types like constructors, prototypes, and enums. It notably does not include literal types like strings and booleans and structural types.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(TypeStringBuilder)
- Specified by:
getReferenceName
in classObjectType
- Returns:
- the object's name or
null
if this is an anonymous object
-
isAnonymous
public boolean isAnonymous()
-
isNativeObjectType
public boolean isNativeObjectType()
Whether this is a built-in object.- Overrides:
isNativeObjectType
in classObjectType
-
getOwnerFunction
public FunctionType getOwnerFunction()
- Overrides:
getOwnerFunction
in classObjectType
-
getCtorImplementedInterfaces
public java.lang.Iterable<ObjectType> getCtorImplementedInterfaces()
Description copied from class:ObjectType
Gets the interfaces implemented by the ctor associated with this type. Intended to be overridden by subclasses.- Overrides:
getCtorImplementedInterfaces
in classObjectType
-
getCtorExtendedInterfaces
public java.lang.Iterable<ObjectType> getCtorExtendedInterfaces()
Description copied from class:ObjectType
Gets the interfaces extended by the interface associated with this type. Intended to be overridden by subclasses.- Overrides:
getCtorExtendedInterfaces
in classObjectType
-
matchConstraint
public void matchConstraint(JSType constraint)
Description copied from class:JSType
Modify this type so that it matches the specified type. This is useful for reverse type-inference, where we want to infer that an object literal matches its constraint (much like how the java compiler does reverse-inference to figure out generics).- Overrides:
matchConstraint
in classJSType
-
matchRecordTypeConstraint
public void matchRecordTypeConstraint(ObjectType constraintObj)
-
-