public final class NamedType extends ProxyObjectType
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.
ObjectType.PropertyOptionalityJSType.HasPropertyKind, JSType.Nullability, JSType.SubtypingMode, JSType.TypePairtemplateTypeMap| Modifier and Type | Method and 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 an
Object, 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.
|
canBeCalled, collapseUnion, findPropertyTypeWithoutConsideringTemplateTypes, getConstructor, getCtorExtendedInterfaces, getCtorImplementedInterfaces, getImplicitPrototype, getJSDocInfo, getOwnerFunction, getPropertyKind, getTemplateTypeMap, getTypeOfThis, hasAnyTemplateTypesInternal, isAllType, isCheckedUnknownType, isConstructor, isDict, isInstanceType, isInterface, isNativeObjectType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isOrdinaryFunction, isStruct, isStructuralType, isSubtype, isSubtype, isUnknownType, isVoidable, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, matchesSymbolContext, removeProperty, setJSDocInfo, setPropertyJSDocInfo, testForEquality, toDebugHashCodeString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, visitReferenceTypecast, 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, getTopMostDefiningType, hasCachedValues, hasOwnProperty, hasReferenceName, instantiateGenericsWithUnknown, isAmbiguousObject, isFunctionPrototypeType, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, isStructuralSubtypeHelper, setPropertyNodeassertFunctionType, assertObjectType, autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, dereference, differsFrom, equals, findPropertyType, getEnumeratedTypeOfEnumElement, getGreatestSubtype, getGreatestSubtypeWithProperty, getInstantiatedTypeArgument, getLeastSupertype, getPropertyKind, getRestrictedTypeGivenToBooleanOutcome, getTypeParameters, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, getUnionMembers, hasAnyTemplateTypes, hasDisplayName, hashCode, hasProperty, isArrayType, isBooleanObjectType, isBooleanValueType, isBoxableScalar, isDateType, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExplicitlyVoidable, isFullyInstantiated, isFunctionType, isGenericObjectType, isGlobalThisType, isLiteralObject, isNamedType, isNominalConstructor, isNullType, isNumber, isNumberObjectType, isNumberValueType, isObjectType, isPartiallyInstantiated, isRecordType, isRegexpType, isResolved, isSomeUnknownType, isString, isStringObjectType, isStringValueType, isStructuralInterface, isSubtype, isSubtypeOf, isSubtypeWithoutStructuralTyping, isSuccessfullyResolved, isSymbol, isSymbolObjectType, isSymbolValueType, isTemplateType, isTemplatizedType, isTypeVariable, isUnionType, isUnresolved, isUnresolvedOrResolvedUnknown, isUnsuccessfullyResolved, isVoidType, meetWith, prependTemplateTypeMap, resolve, restrictByNotNullOrUndefined, restrictByNotUndefined, toAnnotationString, toMaybeFunctionType, toMaybeObjectType, toObjectType, toString, unboxesTopublic com.google.common.collect.ImmutableList<JSType> getTemplateTypes()
ObjectTypegetTemplateTypes in class ProxyObjectTypeTemplatizedTypepublic JSType getReferencedType()
public java.lang.String getReferenceName()
ObjectTypeReturning 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(StringBuilder, boolean)
getReferenceName in class ProxyObjectTypenull if this is an anonymous objectpublic NamedType toMaybeNamedType()
toMaybeNamedType in class JSTypepublic boolean isNominalType()
JSTypeisNominalType in class ProxyObjectTypepublic boolean setValidator(com.google.common.base.Predicate<JSType> validator)
JSType@extends annotation must be an
object. Clients should inject a validator that emits a warning
if the type does not validate, and return false.setValidator in class ProxyObjectTypepublic boolean isObject()
JSTypeObject, or any subtype thereof.isObject in class ObjectTypethis <: Objectpublic <T> T visit(Visitor<T> visitor)
JSTypevisit in class ProxyObjectTypeVisitorCopyright © 2009-2019 Google. All Rights Reserved.