public 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.
JSType.TypePair
templateTypeMap
Modifier and Type | Method and Description |
---|---|
JSType |
getReferencedType()
Returns the type to which this refers (which is unknown if unresolved).
|
String |
getReferenceName()
Gets the reference name for this object.
|
int |
hashCode() |
boolean |
hasReferenceName()
Returns true if the object is named.
|
boolean |
isNominalType()
Whether this type is a nominal type (a named instance object or
a named enum).
|
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, findPropertyType, getConstructor, getCtorImplementedInterfaces, getImplicitPrototype, getJSDocInfo, getOwnerFunction, getTemplateTypeMap, getTemplateTypes, getTypeOfThis, hasAnyTemplateTypesInternal, isAllType, isCheckedUnknownType, isConstructor, isDict, isInstanceType, isInterface, isNativeObjectType, isNoObjectType, isNoResolvedType, isNoType, isNullable, isOrdinaryFunction, isStruct, isStructuralType, isSubtype, isSubtype, isUnknownType, matchConstraint, matchesNumberContext, matchesObjectContext, matchesStringContext, removeProperty, setJSDocInfo, setPropertyJSDocInfo, testForEquality, toDebugHashCodeString, toMaybeEnumElementType, toMaybeEnumType, toMaybeFunctionType, toMaybeRecordType, toMaybeTemplateType, toMaybeTemplatizedType, toMaybeUnionType, visitReferenceType
cast, clearCachedValues, createDelegateSuffix, defineDeclaredProperty, defineInferredProperty, defineSynthesizedProperty, getCtorExtendedInterfaces, getDisplayName, getNormalizedReferenceName, getOwnPropertyJSDocInfo, getOwnPropertyNames, getOwnSlot, getParentScope, getPossibleToBooleanOutcomes, getPropertiesCount, getPropertyNames, getPropertyNode, getPropertyType, getPropertyTypeMap, getRootNode, getSlot, hasCachedValues, hasOwnProperty, hasProperty, isFunctionPrototypeType, isObject, isPropertyInExterns, isPropertyTypeDeclared, isPropertyTypeInferred, setPropertyNode
autobox, autoboxesTo, canCastTo, canTestForEqualityWith, canTestForShallowEqualityWith, dereference, differsFrom, equals, extendTemplateTypeMap, getGreatestSubtype, getLeastSupertype, getRestrictedTypeGivenToBooleanOutcome, getTypesUnderEquality, getTypesUnderInequality, getTypesUnderShallowEquality, getTypesUnderShallowInequality, hasAnyTemplateTypes, hasDisplayName, isArrayType, isBooleanObjectType, isBooleanValueType, isBottom, isDateType, isEmptyType, isEnumElementType, isEnumType, isEquivalent, isEquivalentTo, isEquivalentTo, isExplicitlyVoidable, isFunctionType, isGlobalThisType, isNamedType, isNominalConstructor, isNullType, isNumber, isNumberObjectType, isNumberValueType, isRecordType, isRegexpType, isResolved, isString, isStringObjectType, isStringValueType, isStructuralInterface, isSubtypeOf, isSubtypeWithoutStructuralTyping, isTemplateType, isTemplatizedType, isUnionType, isVoidable, isVoidType, matchesInt32Context, matchesUint32Context, resolve, restrictByNotNullOrUndefined, toAnnotationString, toMaybeFunctionType, toMaybeObjectType, toNonNullAnnotationString, toObjectType, toString, unboxesTo
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isBottom, isEquivalentTo, isFunctionType, isSubtypeOf, restrictByNotNullOrUndefined, toMaybeObjectType
public JSType getReferencedType()
public String getReferenceName()
ObjectType
getReferenceName
in class ProxyObjectType
null
if this is an anonymous
objectpublic boolean hasReferenceName()
ObjectType
hasReferenceName
in class ProxyObjectType
public NamedType toMaybeNamedType()
toMaybeNamedType
in class JSType
public boolean isNominalType()
JSType
isNominalType
in class ProxyObjectType
public int hashCode()
hashCode
in class ProxyObjectType
public 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 JSType
public <T> T visit(Visitor<T> visitor)
JSType
visit
in class ProxyObjectType
Visitor
Copyright © 2009–2023 Google. All rights reserved.