Class TemplateType
- java.lang.Object
-
- com.google.javascript.rhino.jstype.JSType
-
- com.google.javascript.rhino.jstype.ObjectType
-
- com.google.javascript.rhino.jstype.TemplateType
-
- All Implemented Interfaces:
StaticScope<JSType>,java.io.Serializable
public class TemplateType extends ObjectType
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.javascript.rhino.jstype.JSType
JSType.TypePair
-
-
Field Summary
-
Fields inherited from class com.google.javascript.rhino.jstype.JSType
EMPTY_TYPE_COMPONENT, ENUMDECL, NOT_A_CLASS, NOT_A_TYPE, NOT_ENUMDECL, templateTypeMap, UNKNOWN_NAME
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanBeCalled()This predicate is used to test whether a given type can be used as the 'function' in a function call.JSTypecollapseUnion()Gets the least supertype of this that's not a union.JSTypefindPropertyType(java.lang.String propertyName)Coerces this type to an Object type, then gets the type of the property whose name is given.FunctionTypegetConstructor()Gets this object's constructor.java.lang.Iterable<ObjectType>getCtorImplementedInterfaces()Gets the interfaces implemented by the ctor associated with this type.ObjectTypegetImplicitPrototype()Gets the implicit prototype (a.k.a.JSDocInfogetJSDocInfo()Gets the docInfo for this type.FunctionTypegetOwnerFunction()Gets the owner of this if it's a function prototype.java.lang.StringgetReferenceName()Gets the reference name for this object.TemplateTypeMapgetTemplateTypeMap()Returns the template type map associated with this type.com.google.common.collect.ImmutableList<JSType>getTemplateTypes()Gets the declared default element type.JSTypegetTypeOfThis()Returns the expected type ofthisin the current scope.booleanhasAnyTemplateTypesInternal()inthashCode()booleanhasReferenceName()Returns true if the object is named.booleanisAllType()booleanisCheckedUnknownType()booleanisConstructor()Whether this type is aFunctionTypethat is a constructor or a named type that points to such a type.booleanisDict()Returns true iffthiscan be adict.booleanisInstanceType()Whether this type is an Instance object of some constructor.booleanisInterface()Whether this type is aFunctionTypethat is an interface or a named type that points to such a type.booleanisNativeObjectType()Whether this is a built-in object.booleanisNominalType()Whether this type is a nominal type (a named instance object or a named enum).booleanisNoObjectType()booleanisNoResolvedType()booleanisNoType()booleanisNullable()Tests whether this type is nullable.booleanisOrdinaryFunction()Whether this type is aFunctionTypethat is an ordinary function or a named type that points to such a type.booleanisStruct()Returns true iffthiscan be astruct.booleanisSubtype(JSType that)Checks whetherthisis a subtype ofthat.booleanisUnknownType()We treat this as the unknown type if any of its implicit prototype properties is unknown.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.booleanremoveProperty(java.lang.String name)Removes the declared or inferred property from this ObjectType.voidsetJSDocInfo(JSDocInfo info)Sets the docInfo for this type from the givenJSDocInfo.voidsetPropertyJSDocInfo(java.lang.String propertyName, JSDocInfo info)Sets the docInfo for the specified property from theJSDocInfoon its definition.TernaryValuetestForEquality(JSType that)Comparesthisandthat.java.lang.StringtoDebugHashCodeString()A hash code function for diagnosing complicated issues around type-identity.EnumElementTypetoMaybeEnumElementType()Downcasts this to an EnumElementType, or returns null if this is not an EnumElementType.EnumTypetoMaybeEnumType()Downcasts this to an EnumType, or returns null if this is not an EnumType.FunctionTypetoMaybeFunctionType()Downcasts this to a FunctionType, or returns null if this is not a function.TemplateTypetoMaybeTemplateType()Downcasts this to a TemplateType, or returns null if this is not a function.TemplatizedTypetoMaybeTemplatizedType()Downcasts this to a TemplatizedType, or returns null if this is not a function.UnionTypetoMaybeUnionType()Downcasts this to a UnionType, or returns null if this is not a UnionType.<T> Tvisit(Visitor<T> visitor)Visit this type with the given visitor.-
Methods inherited from class com.google.javascript.rhino.jstype.ObjectType
cast, clearCachedValues, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, getCtorExtendedInterfaces, getDisplayName, getNormalizedReferenceName, getOwnPropertyJSDocInfo, getOwnPropertyNames, getOwnSlot, getParentScope, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyNames, getPropertyNode, getPropertyType, getRootNode, getSlot, hasCachedValues, hasOwnProperty, hasProperty, isFunctionPrototypeType, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred
-
Methods inherited from class com.google.javascript.rhino.jstype.JSType
autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, clearResolved, dereference, differsFrom, equals, forceResolve, getGreatestSubtype, getLeastSupertype, getRestrictedTypeGivenToBooleanOutcome, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, hasAnyTemplateTypes, hasDisplayName, isArrayType, isBooleanObjectType, isBooleanValueType, isDateType, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isFunctionType, isGlobalThisType, isInvariant, isNominalConstructor, isNullType, isNumber, isNumberObjectType, isNumberValueType, isRecordType, isRegexpType, isResolved, isString, isStringObjectType, isStringValueType, isTemplateType, isTemplatizedType, isUnionType, isVoidType, matchesInt32Context, matchesUint32Context, resolve, restrictByNotNullOrUndefined, setValidator, toAnnotationString, toMaybeFunctionType, toMaybeTemplateType, toMaybeTemplatizedType, toObjectType, toString, unboxesTo
-
-
-
-
Method Detail
-
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.- Returns:
- the object's name or
nullif this is an anonymous object
-
toMaybeTemplateType
public TemplateType toMaybeTemplateType()
Description copied from class:JSTypeDowncasts this to a TemplateType, or returns null if this is not a function.
-
hasAnyTemplateTypesInternal
public boolean hasAnyTemplateTypesInternal()
-
visit
public <T> T visit(Visitor<T> visitor)
Description copied from class:JSTypeVisit this type with the given visitor.- Returns:
- the value returned by the visitor
- See Also:
Visitor
-
hasReferenceName
public boolean hasReferenceName()
Description copied from class:ObjectTypeReturns true if the object is named.- Overrides:
hasReferenceNamein classObjectType- Returns:
- true if the object is named, false if it is anonymous
-
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
-
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
-
canBeCalled
public boolean canBeCalled()
Description copied from class:JSTypeThis predicate is used to test whether a given type can be used as the 'function' in a function call.- Overrides:
canBeCalledin classJSType- Returns:
trueif this type might be callable.
-
isNoObjectType
public boolean isNoObjectType()
- Overrides:
isNoObjectTypein classJSType
-
isNoResolvedType
public boolean isNoResolvedType()
- Overrides:
isNoResolvedTypein classJSType
-
isUnknownType
public boolean isUnknownType()
Description copied from class:ObjectTypeWe treat this as the unknown type if any of its implicit prototype properties is unknown.- Overrides:
isUnknownTypein classObjectType
-
isCheckedUnknownType
public boolean isCheckedUnknownType()
- Overrides:
isCheckedUnknownTypein classJSType
-
isNullable
public boolean isNullable()
Description copied from class:JSTypeTests whether this type is nullable.- Overrides:
isNullablein classJSType
-
toMaybeEnumType
public EnumType toMaybeEnumType()
Description copied from class:JSTypeDowncasts this to an EnumType, or returns null if this is not an EnumType.- Overrides:
toMaybeEnumTypein classJSType
-
isConstructor
public boolean isConstructor()
Description copied from class:JSTypeWhether this type is aFunctionTypethat is a constructor or a named type that points to such a type.- Overrides:
isConstructorin classJSType
-
isNominalType
public boolean isNominalType()
Description copied from class:JSTypeWhether this type is a nominal type (a named instance object or a named enum).- Overrides:
isNominalTypein classJSType
-
isInstanceType
public boolean isInstanceType()
Description copied from class:JSTypeWhether this type is an Instance object of some constructor. Does not necessarily mean this is anInstanceObjectType.- Overrides:
isInstanceTypein classJSType
-
isInterface
public boolean isInterface()
Description copied from class:JSTypeWhether this type is aFunctionTypethat is an interface or a named type that points to such a type.- Overrides:
isInterfacein classJSType
-
isOrdinaryFunction
public boolean isOrdinaryFunction()
Description copied from class:JSTypeWhether this type is aFunctionTypethat is an ordinary function or a named type that points to such a type.- Overrides:
isOrdinaryFunctionin classJSType
-
isStruct
public boolean isStruct()
Description copied from class:JSTypeReturns true iffthiscan be astruct. UnionType overrides the method, assumethisis not a union here.
-
isDict
public boolean isDict()
Description copied from class:JSTypeReturns true iffthiscan be adict. UnionType overrides the method, assumethisis not a union here.
-
isNativeObjectType
public boolean isNativeObjectType()
Description copied from class:ObjectTypeWhether this is a built-in object.- Overrides:
isNativeObjectTypein classObjectType
-
toMaybeUnionType
public UnionType toMaybeUnionType()
Description copied from class:JSTypeDowncasts this to a UnionType, or returns null if this is not a UnionType. Named in honor of Haskell's Maybe type constructor.- Overrides:
toMaybeUnionTypein classJSType
-
toMaybeFunctionType
public FunctionType toMaybeFunctionType()
Description copied from class:JSTypeDowncasts this to a FunctionType, or returns null if this is not a function. For the purposes of this function, we define a MaybeFunctionType as any type in the sub-lattice { x | LEAST_FUNCTION_TYPE <= x <= GREATEST_FUNCTION_TYPE } This definition excludes bottom types like NoType and NoObjectType. This definition is somewhat arbitrary and axiomatic, but this is the definition that makes the most sense for the most callers.- Overrides:
toMaybeFunctionTypein classJSType
-
toMaybeEnumElementType
public EnumElementType toMaybeEnumElementType()
Description copied from class:JSTypeDowncasts this to an EnumElementType, or returns null if this is not an EnumElementType.- Overrides:
toMaybeEnumElementTypein classJSType
-
testForEquality
public TernaryValue testForEquality(JSType that)
Description copied from class:JSTypeComparesthisandthat.- Overrides:
testForEqualityin classObjectType- Returns:
TernaryValue.TRUEif the comparison of values ofthistype andthatalways succeed (such asundefinedcompared tonull)TernaryValue.FALSEif the comparison of values ofthistype andthatalways fails (such asundefinedcompared tonumber)TernaryValue.UNKNOWNif the comparison can succeed or fail depending on the concrete values
-
isSubtype
public boolean isSubtype(JSType that)
Description copied from class:JSTypeChecks whetherthisis a subtype ofthat.Subtyping rules:
- (unknown) — every type is a subtype of the Unknown type.
- (no) — the No type is a subtype of every type.
- (no-object) — the NoObject type is a subtype of every object type (i.e. subtypes of the Object type).
- (ref) — a type is a subtype of itself.
- (union-l) — A union type is a subtype of a type U if all the
union type's constituents are a subtype of U. Formally
(T<sub>1</sub>, …, T<sub>n</sub>) <: Uif and onlyT<sub>k</sub> <: Ufor allk ∈ 1..n. - (union-r) — A type U is a subtype of a union type if it is a
subtype of one of the union type's constituents. Formally
U <: (T<sub>1</sub>, …, T<sub>n</sub>)if and only ifU <: T<sub>k</sub>for some indexk. - (objects) — an Object
O<sub>1</sub>is a subtype of an objectO<sub>2</sub>if it has more properties thanO<sub>2</sub>and all common properties are pairwise subtypes.
-
getOwnerFunction
public FunctionType getOwnerFunction()
Description copied from class:ObjectTypeGets the owner of this if it's a function prototype.- 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
-
getImplicitPrototype
public ObjectType getImplicitPrototype()
Description copied from class:ObjectTypeGets the implicit prototype (a.k.a. the[[Prototype]]property).- Specified by:
getImplicitPrototypein classObjectType
-
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.
-
findPropertyType
public JSType findPropertyType(java.lang.String propertyName)
Description copied from class:JSTypeCoerces this type to an Object type, then gets the type of the property whose name is given. UnlikeObjectType.getPropertyType(java.lang.String), returns null if the property is not found.- Overrides:
findPropertyTypein classObjectType- Returns:
- The property's type.
nullif the current type cannot have properties, or if the type is not found.
-
getJSDocInfo
public JSDocInfo getJSDocInfo()
Description copied from class:ObjectTypeGets the docInfo for this type.- Overrides:
getJSDocInfoin classObjectType
-
setJSDocInfo
public void setJSDocInfo(JSDocInfo info)
Description copied from class:ObjectType- Overrides:
setJSDocInfoin classObjectType
-
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.
-
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)
-
getTemplateTypes
public com.google.common.collect.ImmutableList<JSType> getTemplateTypes()
Description copied from class:ObjectTypeGets the declared default element type.- Overrides:
getTemplateTypesin classObjectType- See Also:
TemplatizedType
-
toDebugHashCodeString
public java.lang.String toDebugHashCodeString()
Description copied from class:JSTypeA hash code function for diagnosing complicated issues around type-identity.- Overrides:
toDebugHashCodeStringin classJSType
-
getTypeOfThis
public JSType getTypeOfThis()
Description copied from interface:StaticScopeReturns the expected type ofthisin the current scope.- Specified by:
getTypeOfThisin interfaceStaticScope<JSType>- Overrides:
getTypeOfThisin classObjectType
-
collapseUnion
public JSType collapseUnion()
Description copied from class:JSTypeGets the least supertype of this that's not a union.- Overrides:
collapseUnionin classJSType
-
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
-
toMaybeTemplatizedType
public TemplatizedType toMaybeTemplatizedType()
Description copied from class:JSTypeDowncasts this to a TemplatizedType, or returns null if this is not a function.- Overrides:
toMaybeTemplatizedTypein classJSType
-
getTemplateTypeMap
public TemplateTypeMap getTemplateTypeMap()
Description copied from class:JSTypeReturns the template type map associated with this type.- Overrides:
getTemplateTypeMapin classJSType
-
-