Class NamedType
NamedType is a named reference to some other type. This provides
a convenient mechanism for implementing forward references to types; a
NamedType can be used as a placeholder until its reference is
resolved. It is also useful for representing type names in JsDoc type
annotations, some of which may never be resolved (as they may refer to
types in host systems not yet supported by JSCompiler, such as the JVM.)
An important distinction: NamedType is a type name reference,
whereas ObjectType is a named type object, such as an Enum name.
The Enum itself is typically used only in a dot operator to name one of its
constants, or in a declaration, where its name will appear in a
NamedType.
A NamedType is not currently a full-fledged typedef, because it
cannot resolve to any JavaScript type. It can only resolve to a named
JSTypeRegistry type, or to FunctionType or
EnumType.
If full typedefs are to be supported, then each method on each type class
needs to be reviewed to make sure that everything works correctly through
typedefs. Alternatively, we would need to walk through the parse tree and
unroll each reference to a NamedType to its resolved type before
applying the rest of the analysis.
TODO(user): Revisit all of this logic.
The existing typing logic is hacky. Unresolved types should get processed in a more consistent way, but with the Rhino merge coming, there will be much that has to be changed.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.javascript.rhino.jstype.JSType
JSType.HasPropertyKind, JSType.Nullability, JSType.SubtypingMode, JSType.TypePair, JSType.WithSourceRef -
Field Summary
Fields inherited from class com.google.javascript.rhino.jstype.JSType
templateTypeMap -
Method Summary
Modifier and TypeMethodDescriptionReturns the type to which this refers (which is unknown if unresolved).Gets the reference name for this object.com.google.common.collect.ImmutableList<JSType> Gets the declared default element type.booleanWhether this type is a nominal type (a named instance object or a named enum).booleanisObject()Tests whether this type is anObject, or any subtype thereof.booleansetValidator(com.google.common.base.Predicate<JSType> validator) Certain types have constraints on them at resolution-time.<T> TVisit this type with the given visitor.Methods inherited from class com.google.javascript.rhino.jstype.ProxyObjectType
canBeCalled, collapseUnion, findPropertyTypeWithoutConsideringTemplateTypes, getConstructor, getCtorExtendedInterfaces, getCtorImplementedInterfaces, getImplicitPrototype, getJSDocInfo, getOwnerFunction, getPropertyKind, getTemplateParamCount, getTemplateTypeMap, getTypeOfThis, hasAnyTemplateTypesInternal, isAllType, isCheckedUnknownType, isConstructor, isDict, isInstanceType, isInterface, isNativeObjectType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isOrdinaryFunction, isStruct, isStructuralType, isUnknownType, isVoidable, loosenTypecheckingDueToForwardReferencedSupertype, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesSymbolContext, setJSDocInfo, setPropertyJSDocInfo, testForEquality, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeKnownSymbolType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, visitReferenceTypeMethods inherited from class com.google.javascript.rhino.jstype.ObjectType
cast, clearCachedValues, createDelegateSuffix, defineDeclaredProperty, defineDeclaredProperty, defineInferredProperty, defineInferredProperty, defineSynthesizedProperty, findClosestDefinition, findClosestDefinition, getAllKeys, getClosestDefiningType, getDisplayName, getEnumeratedTypeOfEnumObject, getImplicitPrototypeChain, getNormalizedReferenceName, getOwnPropertyDefSite, getOwnPropertyDefSite, getOwnPropertyJSDocInfo, getOwnPropertyJSDocInfo, getOwnPropertyKeys, getOwnPropertyKind, getOwnPropertyKind, getOwnPropertyKnownSymbols, getOwnPropertyNames, getOwnSlot, getOwnSlot, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyDefSite, getPropertyDefSite, getPropertyJSDocInfo, getPropertyJSDocInfo, getPropertyNames, getPropertyNode, getPropertyNode, getPropertyType, getPropertyType, getPropertyTypeMap, getRawType, getSlot, getSlot, getSuperClassConstructor, hasCachedValues, hasOwnDeclaredProperty, hasOwnDeclaredProperty, hasOwnProperty, hasOwnProperty, hasReferenceName, isFunctionPrototypeType, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeDeclared, isPropertyTypeInferred, isPropertyTypeInferred, setPropertyJSDocInfo, setPropertyNode, setPropertyNodeMethods inherited from class com.google.javascript.rhino.jstype.JSType
areSimilar, assertFunctionType, assertObjectType, autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, containsReferenceAncestor, dereference, differsFrom, equals, findPropertyType, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getLeastSupertype, getPropertyKind, getPropertyKind, getPropertyKind, getRestrictedTypeGivenOutcome, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, hasProperty, isArrayType, isBigIntObjectType, isBigIntOrNumber, isBigIntValueType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isDateType, isEmptyType, isEnumElementType, isEnumType, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isKnownSymbolValueType, isLiteralObject, isNamedType, isNominalConstructorOrInterface, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isOnlyBigInt, isRawTypeOfTemplatizedType, isReadonlyArrayType, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStructuralInterface, isSubtype, isSubtype, isSubtypeOf, isSubtypeOf, isSubtypeWithoutStructuralTyping, isSuccessfullyResolved, isSymbol, isSymbolObjectType, isSymbolValueType, isTemplateType, isTemplatizedType, isUnionType, isUnsuccessfullyResolved, isVoidType, mergeSupertypeTemplateTypes, resolve, restrictByNotNull, restrictByNotNullOrUndefined, restrictByNotUndefined, toAnnotationString, toMaybeFunctionType, toMaybeObjectType, toObjectType, toString
-
Method Details
-
getTemplateTypes
Description copied from class:ObjectTypeGets the declared default element type.- Overrides:
getTemplateTypesin classProxyObjectType- See Also:
-
getReferencedType
Returns the type to which this refers (which is unknown if unresolved). -
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)- Overrides:
getReferenceNamein classProxyObjectType- Returns:
- the object's name or
nullif this is an anonymous object
-
toMaybeNamedType
- Overrides:
toMaybeNamedTypein 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 classProxyObjectType
-
setValidator
Description copied from class:JSTypeCertain types have constraints on them at resolution-time. For example, a type in an@extendsannotation must be an object. Clients should inject a validator that emits a warning if the type does not validate, and return false.- Overrides:
setValidatorin classProxyObjectType
-
isObject
public boolean isObject()Description copied from class:JSTypeTests whether this type is anObject, or any subtype thereof.- Overrides:
isObjectin classObjectType- Returns:
this <: Object
-
visit
Description copied from class:JSTypeVisit this type with the given visitor.- Overrides:
visitin classProxyObjectType- Returns:
- the value returned by the visitor
- See Also:
-