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 FunctionTypegetConstructor()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.ObjectTypegetImplicitPrototype()Gets the implicit prototype (a.k.a.FunctionTypegetOwnerFunction()java.lang.StringgetReferenceName()Gets the reference name for this object.intgetTemplateParamCount()Return the number of template parameters declared for this type.booleanisAnonymous()booleanisNativeObjectType()Whether this is a built-in object.voidmatchConstraint(JSType constraint)Modify this type so that it matches the specified type.booleanmatchesNumberContext()This predicate is used to test whether a given type can appear in a numeric context, such as an operand of a multiply operator.booleanmatchesObjectContext()This predicate is used to test whether a given type can appear in anObjectcontext, such as the expression in a with statement.booleanmatchesStringContext()This predicate is used to test whether a given type can appear in aStringcontext, such as an operand of a string concat (+) operator.booleanmatchesSymbolContext()This predicate is used to test whether a given type can appear in asymbolcontext such as property access.voidmatchRecordTypeConstraint(ObjectType constraintObj)booleanremoveProperty(java.lang.String name)Removes the declared or inferred property from this ObjectType.voidsetPropertyJSDocInfo(java.lang.String propertyName, JSDocInfo info)Sets the docInfo for the specified property from theJSDocInfoon its definition.voidsetPropertyNode(java.lang.String propertyName, Node defSite)Sets the node where the property was defined.JSTypeunboxesTo()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, 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, isNominalConstructorOrInterface, 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:ObjectTypeRemoves the declared or inferred property from this ObjectType.- Overrides:
removePropertyin 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:ObjectTypeSets the docInfo for the specified property from theJSDocInfoon its definition.- Overrides:
setPropertyJSDocInfoin classObjectTypeinfo-JSDocInfofor the property definition. May benull.
-
setPropertyNode
public void setPropertyNode(java.lang.String propertyName, Node defSite)Description copied from class:ObjectTypeSets the node where the property was defined.- Overrides:
setPropertyNodein classObjectType
-
matchesNumberContext
public boolean matchesNumberContext()
Description copied from class:JSTypeThis predicate is used to test whether a given type can appear in a numeric context, such as an operand of a multiply operator.- Overrides:
matchesNumberContextin classJSType
-
matchesStringContext
public boolean matchesStringContext()
Description copied from class:JSTypeThis predicate is used to test whether a given type can appear in aStringcontext, 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:
matchesStringContextin classJSType
-
matchesSymbolContext
public boolean matchesSymbolContext()
Description copied from class:JSTypeThis predicate is used to test whether a given type can appear in asymbolcontext such as property access.- Overrides:
matchesSymbolContextin classJSType
-
unboxesTo
public final JSType unboxesTo()
Description copied from class:JSTypeTurn an object type to its corresponding scalar type.
-
matchesObjectContext
public boolean matchesObjectContext()
Description copied from class:JSTypeThis predicate is used to test whether a given type can appear in anObjectcontext, 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:
matchesObjectContextin classJSType
-
getConstructor
public FunctionType getConstructor()
Description copied from class:ObjectTypeGets this object's constructor.- Specified by:
getConstructorin classObjectType- Returns:
- this object's constructor or
nullif it is a native object (constructed natively v.s. by instantiation of a function)
-
getImplicitPrototype
public ObjectType getImplicitPrototype()
Description copied from class:ObjectTypeGets the implicit prototype (a.k.a. the[[Prototype]]property).- Specified by:
getImplicitPrototypein classObjectType
-
getTemplateParamCount
public final int getTemplateParamCount()
Description copied from class:JSTypeReturn 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:
getTemplateParamCountin classJSType
-
getReferenceName
public java.lang.String getReferenceName()
Description copied from class:ObjectTypeGets 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:
getReferenceNamein classObjectType- Returns:
- the object's name or
nullif this is an anonymous object
-
isAnonymous
public boolean isAnonymous()
-
isNativeObjectType
public boolean isNativeObjectType()
Whether this is a built-in object.- Overrides:
isNativeObjectTypein classObjectType
-
getOwnerFunction
public FunctionType getOwnerFunction()
- Overrides:
getOwnerFunctionin classObjectType
-
getCtorImplementedInterfaces
public java.lang.Iterable<ObjectType> getCtorImplementedInterfaces()
Description copied from class:ObjectTypeGets the interfaces implemented by the ctor associated with this type. Intended to be overridden by subclasses.- Overrides:
getCtorImplementedInterfacesin classObjectType
-
getCtorExtendedInterfaces
public java.lang.Iterable<ObjectType> getCtorExtendedInterfaces()
Description copied from class:ObjectTypeGets the interfaces extended by the interface associated with this type. Intended to be overridden by subclasses.- Overrides:
getCtorExtendedInterfacesin classObjectType
-
matchConstraint
public void matchConstraint(JSType constraint)
Description copied from class:JSTypeModify 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:
matchConstraintin classJSType
-
matchRecordTypeConstraint
public void matchRecordTypeConstraint(ObjectType constraintObj)
-
-