public class JSTypeRegistry
extends java.lang.Object
implements java.io.Serializable
This class is not thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
JSTypeRegistry.PropDefinitionKind
A tristate value returned from canPropertyBeDefined.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
OBJECT_ELEMENT_TEMPLATE
Deprecated.
|
| Constructor and Description |
|---|
JSTypeRegistry(ErrorReporter reporter) |
JSTypeRegistry(ErrorReporter reporter,
java.util.Set<java.lang.String> forwardDeclaredTypes)
Constructs a new type registry populated with the built-in types.
|
| Modifier and Type | Method and Description |
|---|---|
JSType |
buildRecordTypeFromObject(ObjectType objType) |
JSTypeRegistry.PropDefinitionKind |
canPropertyBeDefined(JSType type,
java.lang.String propertyName)
Returns whether the given property can possibly be set on the given type.
|
ObjectType |
createAnonymousObjectType(JSDocInfo info)
Create an anonymous object type.
|
FunctionType |
createConstructorType(java.lang.String name,
Node source,
Node parameters,
JSType returnType,
com.google.common.collect.ImmutableList<TemplateType> templateKeys,
boolean isAbstract)
Creates a constructor function type.
|
EnumType |
createEnumType(java.lang.String name,
Node source,
JSType elementsType)
Creates an enum type.
|
FunctionType |
createFunctionType(JSType returnType,
JSType... parameterTypes)
Creates a function type.
|
FunctionType |
createFunctionType(JSType returnType,
Node parameters) |
JSType |
createFunctionTypeWithInstanceType(ObjectType instanceType,
JSType returnType,
java.util.List<JSType> parameterTypes)
Creates a function type in which
this refers to an object instance. |
FunctionType |
createFunctionTypeWithNewReturnType(FunctionType existingFunctionType,
JSType returnType)
Creates a new function type based on an existing function type but
with a new return type.
|
FunctionType |
createFunctionTypeWithVarArgs(JSType returnType,
JSType... parameterTypes)
Creates a function type.
|
java.lang.String |
createGetterPropName(java.lang.String originalPropName) |
FunctionType |
createInterfaceType(java.lang.String name,
Node source,
com.google.common.collect.ImmutableList<TemplateType> templateKeys,
boolean struct)
Creates an interface function type.
|
NamedType |
createNamedType(StaticTypedScope scope,
java.lang.String reference,
java.lang.String sourceName,
int lineno,
int charno)
Creates a named type.
|
JSType |
createNullableType(JSType type)
Creates a type representing nullable values of the given type.
|
ObjectType |
createObjectType(java.lang.String name,
ObjectType implicitPrototype)
Create an object type.
|
JSType |
createOptionalNullableType(JSType type)
Creates a nullable and undefine-able value of the given type.
|
Node |
createOptionalParameters(JSType... parameterTypes)
Creates a tree hierarchy representing a typed parameter list in which
every parameter is optional.
|
JSType |
createOptionalType(JSType type)
Creates a type representing optional values of the given type.
|
Node |
createParameters(JSType... parameterTypes)
Creates a tree hierarchy representing a typed argument list.
|
Node |
createParametersWithVarArgs(JSType... parameterTypes)
Creates a tree hierarchy representing a typed argument list.
|
JSType |
createRecordType(java.util.Map<java.lang.String,? extends JSType> props) |
StaticTypedScope |
createScopeWithTemplates(StaticTypedScope scope,
java.lang.Iterable<TemplateType> templates)
Returns a new scope that includes the given template names for type resolution
purposes.
|
java.lang.String |
createSetterPropName(java.lang.String originalPropName) |
TemplateType |
createTemplateType(java.lang.String name) |
TemplateType |
createTemplateType(java.lang.String name,
JSType bound) |
TemplateType |
createTemplateTypeWithTransformation(java.lang.String name,
Node expr) |
TemplatizedType |
createTemplatizedType(ObjectType baseType,
com.google.common.collect.ImmutableList<JSType> templatizedTypes)
Creates a templatized instance of the specified type.
|
TemplatizedType |
createTemplatizedType(ObjectType baseType,
JSType... templatizedTypes)
Creates a templatized instance of the specified type.
|
TemplatizedType |
createTemplatizedType(ObjectType baseType,
java.util.Map<TemplateType,JSType> templatizedTypes)
Creates a templatized instance of the specified type.
|
JSType |
createTypeFromCommentNode(Node n) |
JSType |
createTypeFromCommentNode(Node n,
java.lang.String sourceName,
StaticTypedScope scope)
Creates a JSType from the nodes representing a type.
|
JSType |
createUnionType(JSType... variants)
Creates a union type whose variants are the arguments.
|
JSType |
createUnionType(JSTypeNative... variants)
Creates a union type whose variants are the built-in types specified
by the arguments.
|
JSType |
createUnionType(java.util.List<? extends JSType> variants) |
boolean |
declareType(StaticScope scope,
java.lang.String name,
JSType type)
Records declared global type names.
|
boolean |
declareTypeForExactScope(StaticScope scope,
java.lang.String name,
JSType type)
Records declared global type names.
|
JSType |
evaluateTypeExpression(JSTypeExpression expr,
StaticTypedScope scope) |
JSType |
evaluateTypeExpressionInGlobalScope(JSTypeExpression expr) |
TemplateType |
getAsyncIterableTemplate()
Returns the template variable for the AsyncIterable interface.
|
TemplateType |
getAsyncIteratorValueTemplate()
Returns the template variable for the AsyncIterator interface.
|
java.util.Collection<FunctionType> |
getDirectImplementors(ObjectType interfaceInstance)
Returns a collection of types that directly implement
interfaceInstance. |
java.lang.Iterable<ObjectType> |
getEachReferenceTypeWithProperty(java.lang.String propertyName)
Returns each reference type that has a property
propertyName
defined on it. |
TemplateTypeMap |
getEmptyTemplateTypeMap() |
ErrorReporter |
getErrorReporter() |
TemplateType |
getGeneratorValueTemplate()
Return the value template variable for the Generator interface.
|
JSType |
getGlobalType(java.lang.String jsTypeName) |
JSType |
getGreatestSubtypeWithProperty(JSType type,
java.lang.String propertyName)
Gets the greatest subtype of the
type that has a property propertyName defined
on it. |
TemplateType |
getIterableTemplate() |
TemplateType |
getIteratorValueTemplate()
Return the value template variable for the Iterator interface.
|
TemplateType |
getIThenableTemplate() |
FunctionType |
getNativeFunctionType(JSTypeNative typeId) |
ObjectType |
getNativeObjectType(JSTypeNative typeId) |
JSType |
getNativeType(JSTypeNative typeId) |
TemplateType |
getObjectElementKey() |
TemplateType |
getObjectIndexKey() |
java.lang.String |
getReadableTypeName(Node n)
The nice API for this method is a single argument; dereference is a detail.
|
java.lang.String |
getReadableTypeNameNoDeref(Node n) |
JSTypeResolver |
getResolver() |
JSType |
getType(StaticScope scope,
java.lang.String jsTypeName)
Looks up a native type by name.
|
JSType |
getType(StaticTypedScope scope,
java.lang.String jsTypeName,
java.lang.String sourceName,
int lineno,
int charno)
Looks up a type by name.
|
JSType |
getTypeForScope(StaticScope scope,
java.lang.String jsTypeName)
Looks up a native type by name.
|
void |
identifyNonNullableName(StaticScope scope,
java.lang.String name)
Identifies the name of a typedef or enum before we actually declare it.
|
boolean |
isForwardDeclaredType(java.lang.String name)
Whether this is a forward-declared type name.
|
boolean |
isNonNullableName(StaticScope scope,
java.lang.String name)
Identifies the name of a typedef or enum before we actually declare it.
|
com.google.common.collect.ImmutableList<TemplateType> |
maybeGetTemplateTypesOfBuiltin(java.lang.String fnName) |
void |
overwriteDeclaredType(StaticScope scope,
java.lang.String name,
JSType type)
Overrides a declared global type name.
|
void |
overwriteDeclaredType(java.lang.String name,
JSType type)
Overrides a declared global type name.
|
void |
registerClosureModule(java.lang.String moduleName,
Node definitionNode,
JSType type)
Ensures that a type annotation pointing to a Closure modules is correctly resolved.
|
void |
registerLegacyClosureModule(java.lang.String moduleName)
Ensures that a type annotation pointing to a Closure modules is correctly resolved.
|
void |
registerPropertyOnType(java.lang.String propertyName,
JSType type)
Tells the type system that
owner may have a property named
propertyName. |
void |
registerTemplateTypeNamesInScope(java.lang.Iterable<TemplateType> keys,
Node scopeRoot)
Registers template types on the given scope root.
|
void |
removeType(StaticScope scope,
java.lang.String name)
Removes a type by name.
|
void |
resetForTypeCheck()
Reset to run the TypeCheck pass.
|
void |
resetImplicitPrototype(JSType type,
ObjectType newImplicitProto)
Set the implicit prototype if it's possible to do so.
|
void |
restoreContents(java.io.ObjectInputStream in)
Restores the derived state.
|
void |
saveContents(java.io.ObjectOutputStream out)
Saves the derived state.
|
void |
unregisterPropertyOnType(java.lang.String propertyName,
JSType type)
Removes the index's reference to a property on the given type (if it is
currently registered).
|
@Deprecated public static final java.lang.String OBJECT_ELEMENT_TEMPLATE
public JSTypeRegistry(ErrorReporter reporter)
public JSTypeRegistry(ErrorReporter reporter, java.util.Set<java.lang.String> forwardDeclaredTypes)
public TemplateType getObjectElementKey()
public TemplateType getObjectIndexKey()
public TemplateType getIterableTemplate()
public TemplateType getIteratorValueTemplate()
public TemplateType getGeneratorValueTemplate()
public TemplateType getAsyncIterableTemplate()
public TemplateType getAsyncIteratorValueTemplate()
public TemplateType getIThenableTemplate()
public com.google.common.collect.ImmutableList<TemplateType> maybeGetTemplateTypesOfBuiltin(java.lang.String fnName)
public ErrorReporter getErrorReporter()
public void resetForTypeCheck()
public void removeType(StaticScope scope, java.lang.String name)
name - The name string.public void registerPropertyOnType(java.lang.String propertyName,
JSType type)
owner may have a property named
propertyName. This allows the registry to keep track of what
types a property is defined upon.
This is NOT the same as saying that owner must have a property
named type. ObjectType#hasProperty attempts to minimize false positives
("if we're not sure, then don't type check this property"). The type
registry, on the other hand, should attempt to minimize false negatives
("if this property is assigned anywhere in the program, it must
show up in the type registry").public void unregisterPropertyOnType(java.lang.String propertyName,
JSType type)
propertyName - the name of the property to unregistertype - the type to unregister the property on.public JSType getGreatestSubtypeWithProperty(JSType type, java.lang.String propertyName)
type that has a property propertyName defined
on it.
NOTE: Building the returned union here is an n^2 operation of relatively expensive subtype checks: for common properties named such as those on some generated classes this can be extremely expensive (programs with thousands of protos isn't uncommon resulting in millions of subtype relationship checks for each common property name). Currently, this is only used by "disambiguate properties" and there is should be removed.
public JSTypeRegistry.PropDefinitionKind canPropertyBeDefined(JSType type, java.lang.String propertyName)
public java.lang.Iterable<ObjectType> getEachReferenceTypeWithProperty(java.lang.String propertyName)
propertyName
defined on it.
Unlike most types in our type system, the collection of types returned
will not be collapsed. This means that if a type is defined on
Object and on Array, this method must return
[Object, Array]. It would not be correct to collapse them to
[Object].public java.util.Collection<FunctionType> getDirectImplementors(ObjectType interfaceInstance)
interfaceInstance. Subtypes of implementing types are not guaranteed to
be returned. interfaceInstance must be an ObjectType for the
instance of the interface.public boolean declareType(StaticScope scope, java.lang.String name, JSType type)
name - The name of the type to be recorded.type - The actual type being associated with the name.public boolean declareTypeForExactScope(StaticScope scope, java.lang.String name, JSType type)
name - The name of the type to be recorded.type - The actual type being associated with the name.public void overwriteDeclaredType(java.lang.String name,
JSType type)
public void overwriteDeclaredType(StaticScope scope, java.lang.String name, JSType type)
public boolean isForwardDeclaredType(java.lang.String name)
public java.lang.String getReadableTypeName(Node n)
public java.lang.String getReadableTypeNameNoDeref(Node n)
public java.lang.String createGetterPropName(java.lang.String originalPropName)
public java.lang.String createSetterPropName(java.lang.String originalPropName)
public JSType getTypeForScope(StaticScope scope, java.lang.String jsTypeName)
jsTypeName - The name string.null it cannot be foundpublic JSType getGlobalType(java.lang.String jsTypeName)
public JSType getType(StaticScope scope, java.lang.String jsTypeName)
jsTypeName - The name string.null it cannot be foundpublic JSType getType(StaticTypedScope scope, java.lang.String jsTypeName, java.lang.String sourceName, int lineno, int charno)
scope - A scope for doing type name resolution.jsTypeName - The name string.sourceName - The name of the source file where this reference appears.lineno - The line number of the reference.public JSType getNativeType(JSTypeNative typeId)
public ObjectType getNativeObjectType(JSTypeNative typeId)
public FunctionType getNativeFunctionType(JSTypeNative typeId)
public JSTypeResolver getResolver()
public JSType evaluateTypeExpressionInGlobalScope(JSTypeExpression expr)
public JSType createOptionalType(JSType type)
public JSType createNullableType(JSType type)
public JSType createOptionalNullableType(JSType type)
public JSType createUnionType(JSType... variants)
public JSType createUnionType(JSTypeNative... variants)
public EnumType createEnumType(java.lang.String name, Node source, JSType elementsType)
name - The human-readable name associated with the enum, or null if unknown.public FunctionType createFunctionType(JSType returnType, JSType... parameterTypes)
returnType - the function's return typeparameterTypes - the parameters' typespublic FunctionType createFunctionType(JSType returnType, Node parameters)
parameters - the function's parameters or null to indicate that the parameter
types are unknown.returnType - the function's return type or null to indicate that the return type
is unknown.public FunctionType createFunctionTypeWithVarArgs(JSType returnType, JSType... parameterTypes)
returnType - the function's return typeparameterTypes - the parameters' typespublic JSType createFunctionTypeWithInstanceType(ObjectType instanceType, JSType returnType, java.util.List<JSType> parameterTypes)
this refers to an object instance.instanceType - the type of thisreturnType - the function's return typeparameterTypes - the parameters' typespublic Node createParameters(JSType... parameterTypes)
parameterTypes - the parameter types.public Node createParametersWithVarArgs(JSType... parameterTypes)
parameterTypes - the parameter types. The last element of this array
is considered a variable length argument.public Node createOptionalParameters(JSType... parameterTypes)
public FunctionType createFunctionTypeWithNewReturnType(FunctionType existingFunctionType, JSType returnType)
existingFunctionType - the existing function type.returnType - the new return type.public JSType buildRecordTypeFromObject(ObjectType objType)
public JSType createRecordType(java.util.Map<java.lang.String,? extends JSType> props)
public ObjectType createObjectType(java.lang.String name, ObjectType implicitPrototype)
public ObjectType createAnonymousObjectType(JSDocInfo info)
info - Used to mark object literals as structs; can be nullpublic void resetImplicitPrototype(JSType type, ObjectType newImplicitProto)
public FunctionType createConstructorType(java.lang.String name, Node source, Node parameters, JSType returnType, @Nullable com.google.common.collect.ImmutableList<TemplateType> templateKeys, boolean isAbstract)
name - the function's name or null to indicate that the function is anonymous.source - the node defining this function. Its type (Node.getToken() ()}) must be
Token.FUNCTION.parameters - the function's parameters or null to indicate that the parameter
types are unknown.returnType - the function's return type or null to indicate that the return type
is unknown.templateKeys - the templatized types for the class.isAbstract - whether the function type represents an abstract classpublic FunctionType createInterfaceType(java.lang.String name, Node source, com.google.common.collect.ImmutableList<TemplateType> templateKeys, boolean struct)
name - the function's namesource - the node defining this function. Its type (Node.getToken()) must be
Token.FUNCTION.templateKeys - the templatized types for the interface.public TemplateType createTemplateType(java.lang.String name)
public TemplateType createTemplateType(java.lang.String name, JSType bound)
public TemplateType createTemplateTypeWithTransformation(java.lang.String name, Node expr)
public TemplateTypeMap getEmptyTemplateTypeMap()
public TemplatizedType createTemplatizedType(ObjectType baseType, com.google.common.collect.ImmutableList<JSType> templatizedTypes)
baseType - the type to be templatized.templatizedTypes - a list of the template JSTypes. Will be matched by list order to the
template keys on the base type.public TemplatizedType createTemplatizedType(ObjectType baseType, java.util.Map<TemplateType,JSType> templatizedTypes)
baseType - the type to be templatized.templatizedTypes - a map from TemplateType to corresponding JSType value. Any unfilled
TemplateTypes on the baseType that are *not* contained in this map will have UNKNOWN_TYPE
used as their value.public TemplatizedType createTemplatizedType(ObjectType baseType, JSType... templatizedTypes)
baseType - the type to be templatized.templatizedTypes - a list of the template JSTypes. Will be matched by list order to the
template keys on the base type.public NamedType createNamedType(StaticTypedScope scope, java.lang.String reference, java.lang.String sourceName, int lineno, int charno)
public void identifyNonNullableName(StaticScope scope, java.lang.String name)
public boolean isNonNullableName(StaticScope scope, java.lang.String name)
public JSType evaluateTypeExpression(JSTypeExpression expr, StaticTypedScope scope)
public JSType createTypeFromCommentNode(Node n, java.lang.String sourceName, StaticTypedScope scope)
n - The node with type info.sourceName - The source file name.scope - A scope for doing type name lookups.public void registerTemplateTypeNamesInScope(java.lang.Iterable<TemplateType> keys, Node scopeRoot)
public StaticTypedScope createScopeWithTemplates(StaticTypedScope scope, java.lang.Iterable<TemplateType> templates)
@GwtIncompatible(value="ObjectOutputStream")
public void saveContents(java.io.ObjectOutputStream out)
throws java.io.IOException
java.io.IOException@GwtIncompatible(value="ObjectInputStream")
public void restoreContents(java.io.ObjectInputStream in)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic void registerClosureModule(java.lang.String moduleName,
Node definitionNode,
JSType type)
public void registerLegacyClosureModule(java.lang.String moduleName)
Currently this is useful because module rewriting will prevent type resolution given a
Copyright © 2009-2020 Google. All Rights Reserved.