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>,Serializable
- See Also:
-
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
Modifier and TypeMethodDescriptionbooleanThis predicate is used to test whether a given type can be used as the 'function' in a function call.Gets the least supertype of this that's not a union.findPropertyType(String propertyName) Coerces this type to an Object type, then gets the type of the property whose name is given.Gets this object's constructor.Gets the interfaces implemented by the ctor associated with this type.Gets the implicit prototype (a.k.a.Gets the docInfo for this type.Gets the owner of this if it's a function prototype.Gets the reference name for this object.Returns the template type map associated with this type.com.google.common.collect.ImmutableList<JSType> Gets the declared default element type.Returns the expected type ofthisin the current scope.booleaninthashCode()booleanReturns true if the object is named.booleanbooleanbooleanWhether this type is aFunctionTypethat is a constructor or a named type that points to such a type.booleanisDict()Returns true iffthiscan be adict.booleanWhether this type is an Instance object of some constructor.booleanWhether this type is aFunctionTypethat is an interface or a named type that points to such a type.booleanWhether this is a built-in object.booleanWhether this type is a nominal type (a named instance object or a named enum).booleanbooleanbooleanisNoType()booleanTests whether this type is nullable.booleanWhether this type is aFunctionTypethat is an ordinary function or a named type that points to such a type.booleanisStruct()Returns true iffthiscan be astruct.booleanChecks whetherthisis a subtype ofthat.booleanWe 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.booleanThis predicate is used to test whether a given type can appear in a numeric context, such as an operand of a multiply operator.booleanThis predicate is used to test whether a given type can appear in anObjectcontext, such as the expression in a with statement.booleanThis predicate is used to test whether a given type can appear in aStringcontext, such as an operand of a string concat (+) operator.booleanremoveProperty(String name) Removes the declared or inferred property from this ObjectType.voidsetJSDocInfo(JSDocInfo info) Sets the docInfo for this type from the givenJSDocInfo.voidsetPropertyJSDocInfo(String propertyName, JSDocInfo info) Sets the docInfo for the specified property from theJSDocInfoon its definition.testForEquality(JSType that) Comparesthisandthat.A hash code function for diagnosing complicated issues around type-identity.Downcasts this to an EnumElementType, or returns null if this is not an EnumElementType.Downcasts this to an EnumType, or returns null if this is not an EnumType.Downcasts this to a FunctionType, or returns null if this is not a function.Downcasts this to a TemplateType, or returns null if this is not a function.Downcasts this to a TemplatizedType, or returns null if this is not a function.Downcasts this to a UnionType, or returns null if this is not a UnionType.<T> TVisit 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, isPropertyTypeInferredMethods 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 Details
-
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
Description copied from class:JSTypeDowncasts this to a TemplateType, or returns null if this is not a function. -
hasAnyTemplateTypesInternal
public boolean hasAnyTemplateTypesInternal() -
visit
Description copied from class:JSTypeVisit this type with the given visitor.- Returns:
- the value returned by the visitor
- See Also:
-
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.
-
isNoType
public boolean isNoType() -
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
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
-
isAllType
public boolean isAllType() -
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
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
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 invalid input: '<'= x invalid input: '<'= 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
Description copied from class:JSTypeDowncasts this to an EnumElementType, or returns null if this is not an EnumElementType.- Overrides:
toMaybeEnumElementTypein classJSType
-
testForEquality
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
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
Description copied from class:ObjectTypeGets the owner of this if it's a function prototype.- Overrides:
getOwnerFunctionin classObjectType
-
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
-
hashCode
public int hashCode() -
getImplicitPrototype
Description copied from class:ObjectTypeGets the implicit prototype (a.k.a. the[[Prototype]]property).- Specified by:
getImplicitPrototypein classObjectType
-
removeProperty
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
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
Description copied from class:ObjectTypeGets the docInfo for this type.- Overrides:
getJSDocInfoin classObjectType
-
setJSDocInfo
Description copied from class:ObjectType- Overrides:
setJSDocInfoin classObjectType
-
setPropertyJSDocInfo
Description copied from class:ObjectTypeSets the docInfo for the specified property from theJSDocInfoon its definition.- Overrides:
setPropertyJSDocInfoin classObjectType- Parameters:
info-JSDocInfofor the property definition. May benull.
-
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
Description copied from class:ObjectTypeGets the declared default element type.- Overrides:
getTemplateTypesin classObjectType- See Also:
-
toDebugHashCodeString
Description copied from class:JSTypeA hash code function for diagnosing complicated issues around type-identity.- Overrides:
toDebugHashCodeStringin classJSType
-
getTypeOfThis
Description copied from interface:StaticScopeReturns the expected type ofthisin the current scope.- Specified by:
getTypeOfThisin interfaceStaticScope<JSType>- Overrides:
getTypeOfThisin classObjectType
-
collapseUnion
Description copied from class:JSTypeGets the least supertype of this that's not a union.- Overrides:
collapseUnionin classJSType
-
matchConstraint
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- Parameters:
constraint-
-
toMaybeTemplatizedType
Description copied from class:JSTypeDowncasts this to a TemplatizedType, or returns null if this is not a function.- Overrides:
toMaybeTemplatizedTypein classJSType
-
getTemplateTypeMap
Description copied from class:JSTypeReturns the template type map associated with this type.- Overrides:
getTemplateTypeMapin classJSType
-