Class NamedType
- java.lang.Object
-
- com.google.javascript.rhino.jstype.JSType
-
- com.google.javascript.rhino.jstype.ObjectType
-
- com.google.javascript.rhino.jstype.ProxyObjectType
-
- com.google.javascript.rhino.jstype.NamedType
-
public final class NamedType extends ProxyObjectType
ANamedType
is a named reference to some other type. This provides a convenient mechanism for implementing forward references to types; aNamedType
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, whereasObjectType
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 namedJSTypeRegistry
type, or toFunctionType
orEnumType
.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JSType
getReferencedType()
Returns the type to which this refers (which is unknown if unresolved).java.lang.String
getReferenceName()
Gets the reference name for this object.com.google.common.collect.ImmutableList<JSType>
getTemplateTypes()
Gets the declared default element type.boolean
isNominalType()
Whether this type is a nominal type (a named instance object or a named enum).boolean
isObject()
Tests whether this type is anObject
, or any subtype thereof.boolean
setValidator(com.google.common.base.Predicate<JSType> validator)
Certain types have constraints on them at resolution-time.NamedType
toMaybeNamedType()
<T> T
visit(Visitor<T> visitor)
Visit 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, removeProperty, setJSDocInfo, setPropertyJSDocInfo, testForEquality, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, visitReferenceType
-
Methods inherited from class com.google.javascript.rhino.jstype.ObjectType
cast, clearCachedValues, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, findClosestDefinition, getClosestDefiningType, getDisplayName, getEnumeratedTypeOfEnumObject, getImplicitPrototypeChain, getNormalizedReferenceName, getOwnPropertyDefSite, getOwnPropertyJSDocInfo, getOwnPropertyKind, getOwnPropertyNames, getOwnSlot, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyDefSite, getPropertyJSDocInfo, getPropertyNames, getPropertyNode, getPropertyType, getPropertyTypeMap, getRawType, getSlot, getSuperClassConstructor, hasCachedValues, hasOwnDeclaredProperty, hasOwnProperty, hasReferenceName, isFunctionPrototypeType, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, setPropertyNode
-
Methods inherited from class com.google.javascript.rhino.jstype.JSType
areSimilar, assertFunctionType, assertObjectType, autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, containsReferenceAncestor, dereference, differsFrom, equals, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getLeastSupertype, getPropertyKind, getRestrictedTypeGivenOutcome, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, isArrayType, isBigIntObjectType, isBigIntOrNumber, isBigIntValueType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isDateType, isEmptyType, isEnumElementType, isEnumType, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isLiteralObject, isNamedType, isNominalConstructorOrInterface, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isOnlyBigInt, isRawTypeOfTemplatizedType, 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 Detail
-
getTemplateTypes
public com.google.common.collect.ImmutableList<JSType> getTemplateTypes()
Description copied from class:ObjectType
Gets the declared default element type.- Overrides:
getTemplateTypes
in classProxyObjectType
- See Also:
TemplatizedType
-
getReferencedType
public JSType getReferencedType()
Returns the type to which this refers (which is unknown if unresolved).
-
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)
- Overrides:
getReferenceName
in classProxyObjectType
- Returns:
- the object's name or
null
if this is an anonymous object
-
toMaybeNamedType
public NamedType toMaybeNamedType()
- Overrides:
toMaybeNamedType
in classJSType
-
isNominalType
public boolean isNominalType()
Description copied from class:JSType
Whether this type is a nominal type (a named instance object or a named enum).- Overrides:
isNominalType
in classProxyObjectType
-
setValidator
public boolean setValidator(com.google.common.base.Predicate<JSType> validator)
Description copied from class:JSType
Certain types have constraints on them at resolution-time. For example, a type in an@extends
annotation must be an object. Clients should inject a validator that emits a warning if the type does not validate, and return false.- Overrides:
setValidator
in classProxyObjectType
-
isObject
public boolean isObject()
Description copied from class:JSType
Tests whether this type is anObject
, or any subtype thereof.- Overrides:
isObject
in classObjectType
- Returns:
this <: Object
-
visit
public <T> T visit(Visitor<T> visitor)
Description copied from class:JSType
Visit this type with the given visitor.- Overrides:
visit
in classProxyObjectType
- Returns:
- the value returned by the visitor
- See Also:
Visitor
-
-