|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.javascript.rhino.jstype.JSTypeRegistry
public class JSTypeRegistry
The type registry is used to resolve named types.
This class is not thread-safe.
Nested Class Summary | |
---|---|
static class |
JSTypeRegistry.ResolveMode
The type registry has three modes, which control how type ASTs are converted to types in createFromTypeNodes(com.google.javascript.rhino.Node, java.lang.String, com.google.javascript.rhino.jstype.StaticScope . |
Constructor Summary | |
---|---|
JSTypeRegistry(ErrorReporter reporter)
Constructs a new type registry populated with the built-in types. |
|
JSTypeRegistry(ErrorReporter reporter,
boolean tolerateUndefinedValues)
Constructs a new type registry populated with the built-in types. |
Method Summary | |
---|---|
boolean |
canPropertyBeDefined(JSType type,
String propertyName)
Returns whether the given property can possibly be set on the given type. |
void |
clearNamedTypes()
Flushes out the current resolved and unresovled Named Types from the type registry. |
void |
clearTemplateTypeName()
Clears the template type name. |
ObjectType |
createAnonymousObjectType()
Create an anonymous object type. |
FunctionType |
createConstructorType(JSType returnType,
boolean lastVarArgs,
JSType... parameterTypes)
Creates a function type which can act as a constructor. |
FunctionType |
createConstructorType(JSType returnType,
JSType... parameterTypes)
Creates a function type which can act as a constructor. |
FunctionType |
createConstructorType(String name,
Node source,
Node parameters,
JSType returnType)
Creates a constructor function type. |
FunctionType |
createConstructorTypeWithVarArgs(JSType returnType,
JSType... parameterTypes)
Creates a function type which can act as a constructor. |
JSType |
createDefaultObjectUnion(JSType type)
Creates a type representing nullable values of the given type. |
EnumType |
createEnumType(String name,
Node source,
JSType elementsType)
Creates an enum type. |
JSType |
createFromTypeNodes(Node n,
String sourceName,
StaticScope<JSType> scope)
Creates a JSType from the nodes representing a type. |
FunctionType |
createFunctionType(JSType returnType,
boolean lastVarArgs,
JSType... parameterTypes)
Creates a function type. |
FunctionType |
createFunctionType(JSType returnType,
JSType... parameterTypes)
Creates a function type. |
FunctionType |
createFunctionType(JSType returnType,
List<JSType> parameterTypes)
Creates a function type. |
FunctionType |
createFunctionType(JSType returnType,
Node parameters)
|
JSType |
createFunctionType(ObjectType instanceType,
JSType returnType,
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 |
createFunctionTypeWithNewThisType(FunctionType existingFunctionType,
ObjectType thisType)
Creates a new function type based on an existing function type but with a new this type. |
FunctionType |
createFunctionTypeWithVarArgs(JSType returnType,
JSType... parameterTypes)
Creates a function type. |
FunctionType |
createFunctionTypeWithVarArgs(JSType returnType,
List<JSType> parameterTypes)
Creates a function type. |
JSType |
createFunctionTypeWithVarArgs(ObjectType instanceType,
JSType returnType,
List<JSType> parameterTypes)
Creates a function type in which this refers to an object instance. |
FunctionType |
createInterfaceType(String name,
Node source)
Creates an interface function type. |
JSType |
createNamedType(String reference,
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(ObjectType implicitPrototype)
Create an object type. |
ObjectType |
createObjectType(String name,
Node n,
ObjectType implicitPrototype)
Create an object type. |
JSType |
createOptionalNullableType(JSType type)
Creates a nullabel 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. |
com.google.javascript.rhino.jstype.ParameterizedType |
createParameterizedType(ObjectType objectType,
JSType parameterType)
Creates a parameterized type. |
Node |
createParameters(JSType... parameterTypes)
Creates a tree hierarchy representing a typed argument list. |
Node |
createParameters(List<JSType> parameterTypes)
Creates a tree hierarchy representing a typed argument list. |
Node |
createParametersWithVarArgs(JSType... parameterTypes)
Creates a tree hierarchy representing a typed argument list. |
Node |
createParametersWithVarArgs(List<JSType> parameterTypes)
Creates a tree hierarchy representing a typed argument list. |
com.google.javascript.rhino.jstype.RecordType |
createRecordType(Map<String,com.google.javascript.rhino.jstype.RecordTypeBuilder.RecordProperty> properties)
Creates a record 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 builtin types specified by the arguments. |
boolean |
declareType(String name,
JSType t)
Records declared global type names. |
void |
forwardDeclareType(String name)
Records a forward-declared type name. |
Collection<FunctionType> |
getDirectImplementors(ObjectType interfaceInstance)
Returns a collection of types that directly implement interfaceInstance . |
Iterable<ObjectType> |
getEachReferenceTypeWithProperty(String propertyName)
Returns each reference type that has a property propertyName
defined on it. |
ErrorReporter |
getErrorReporter()
|
JSType |
getGreatestSubtypeWithProperty(JSType type,
String propertyName)
Gets the greatest subtype of the type that has a property
propertyName defined on it. |
FunctionType |
getNativeFunctionType(JSTypeNative typeId)
|
ObjectType |
getNativeObjectType(JSTypeNative typeId)
|
JSType |
getNativeType(JSTypeNative typeId)
|
JSType |
getType(StaticScope<JSType> scope,
String jsTypeName,
String sourceName,
int lineno,
int charno)
Looks up a type by name. |
JSType |
getType(String jsTypeName)
Looks up a type by name. |
Iterable<JSType> |
getTypesWithProperty(String propertyName)
Returns each type that has a property propertyName defined on it. |
boolean |
hasNamespace(String name)
Determines whether the given JS package exists. |
void |
identifyNonNullableName(String name)
Identifies the name of a typedef or enum before we actually declare it. |
void |
incrementGeneration()
Increments the current generation. |
boolean |
isForwardDeclaredType(String name)
Whether this is a forward-declared type name. |
void |
overwriteDeclaredType(String name,
JSType t)
Overrides a declared global type name. |
void |
registerPropertyOnType(String propertyName,
JSType type)
Tells the type system that owner may have a property named
propertyName . |
void |
resetForTypeCheck()
Reset to run the TypeCheck pass. |
boolean |
resetImplicitPrototype(JSType type,
ObjectType newImplicitProto)
Set the implicit prototype if it's possible to do so. |
void |
resolveTypesInScope(StaticScope<JSType> scope)
Resolve all the unresolved types in the given scope. |
void |
setLastGeneration(boolean lastGeneration)
Sets whether this is the last generation. |
void |
setResolveMode(JSTypeRegistry.ResolveMode mode)
Set the current resolving mode of the type registry. |
void |
setTemplateTypeName(String name)
Sets the template type name. |
boolean |
shouldTolerateUndefinedValues()
|
void |
unregisterPropertyOnType(String propertyName,
JSType type)
Removes the index's reference to a property on the given type (if it is currently registered). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JSTypeRegistry(ErrorReporter reporter)
public JSTypeRegistry(ErrorReporter reporter, boolean tolerateUndefinedValues)
Method Detail |
---|
public void setResolveMode(JSTypeRegistry.ResolveMode mode)
JSTypeRegistry.ResolveMode
public ErrorReporter getErrorReporter()
public boolean shouldTolerateUndefinedValues()
public void resetForTypeCheck()
public void registerPropertyOnType(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(String propertyName, JSType type)
propertyName
- the name of the property to unregistertype
- the type to unregister the property on.public JSType getGreatestSubtypeWithProperty(JSType type, String propertyName)
type
that has a property
propertyName
defined on it.
public boolean canPropertyBeDefined(JSType type, String propertyName)
public Iterable<JSType> getTypesWithProperty(String propertyName)
propertyName
defined on it.
Like most types in our type system, the collection of types returned
will be collapsed. This means that if a type is defined on
Object
and on Array
, it would be reasonable for this
method to return either [Object, Array]
or just [Object]
.
public Iterable<ObjectType> getEachReferenceTypeWithProperty(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 void incrementGeneration()
public void setLastGeneration(boolean lastGeneration)
NamedType
warns about unresolved types.
public 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(String name, JSType t)
name
- The name of the type to be recorded.t
- The actual type being associated with the name.
public void overwriteDeclaredType(String name, JSType t)
public void forwardDeclareType(String name)
public boolean isForwardDeclaredType(String name)
public boolean hasNamespace(String name)
public JSType getType(String jsTypeName)
jsTypeName
- The name string.
null
it cannot be foundpublic JSType getNativeType(JSTypeNative typeId)
public ObjectType getNativeObjectType(JSTypeNative typeId)
public FunctionType getNativeFunctionType(JSTypeNative typeId)
public JSType getType(StaticScope<JSType> scope, String jsTypeName, 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 void clearNamedTypes()
public void resolveTypesInScope(StaticScope<JSType> scope)
public JSType createOptionalType(JSType type)
public JSType createDefaultObjectUnion(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(String name, Node source, JSType elementsType)
public FunctionType createFunctionType(JSType returnType, JSType... parameterTypes)
returnType
- the function's return typeparameterTypes
- the parameters' typespublic FunctionType createFunctionTypeWithVarArgs(JSType returnType, List<JSType> parameterTypes)
returnType
- the function's return typeparameterTypes
- the parameters' typespublic FunctionType createFunctionType(JSType returnType, List<JSType> parameterTypes)
returnType
- the function's return typeparameterTypes
- the parameters' typespublic FunctionType createFunctionTypeWithVarArgs(JSType returnType, JSType... parameterTypes)
returnType
- the function's return typeparameterTypes
- the parameters' typespublic FunctionType createConstructorType(JSType returnType, JSType... parameterTypes)
returnType
- the function's return typeparameterTypes
- the parameters' typespublic FunctionType createConstructorTypeWithVarArgs(JSType returnType, JSType... parameterTypes)
returnType
- the function's return typeparameterTypes
- the parameters' typespublic JSType createFunctionType(ObjectType instanceType, JSType returnType, List<JSType> parameterTypes)
this
refers to an object instance.
instanceType
- the type of this
returnType
- the function's return typeparameterTypes
- the parameters' typespublic JSType createFunctionTypeWithVarArgs(ObjectType instanceType, JSType returnType, List<JSType> parameterTypes)
this
refers to an object instance.
The last parameter type of the function is considered a variable length
argument.
instanceType
- the type of this
returnType
- the function's return typeparameterTypes
- the parameters' typespublic Node createParameters(List<JSType> parameterTypes)
parameterTypes
- the parameter types.
public Node createParametersWithVarArgs(List<JSType> parameterTypes)
parameterTypes
- the parameter types. The last element of this array
is considered a variable length argument.
public 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 createFunctionType(JSType returnType, boolean lastVarArgs, JSType... parameterTypes)
returnType
- the function's return typelastVarArgs
- whether the last parameter type should be considered as
an extensible var_args parameterparameterTypes
- the parameters' typespublic FunctionType createFunctionTypeWithNewReturnType(FunctionType existingFunctionType, JSType returnType)
existingFunctionType
- the existing function type.returnType
- the new return type.public FunctionType createFunctionTypeWithNewThisType(FunctionType existingFunctionType, ObjectType thisType)
this
type.
existingFunctionType
- the existing function type.thisType
- the new this type.public 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 createConstructorType(JSType returnType, boolean lastVarArgs, JSType... parameterTypes)
returnType
- the function's return typelastVarArgs
- whether the last parameter type should be considered as
an extensible var_args parameterparameterTypes
- the parameters' typespublic ObjectType createObjectType(ObjectType implicitPrototype)
public com.google.javascript.rhino.jstype.RecordType createRecordType(Map<String,com.google.javascript.rhino.jstype.RecordTypeBuilder.RecordProperty> properties)
public ObjectType createObjectType(String name, Node n, ObjectType implicitPrototype)
public ObjectType createAnonymousObjectType()
public boolean resetImplicitPrototype(JSType type, ObjectType newImplicitProto)
public FunctionType createConstructorType(String name, Node source, Node parameters, JSType returnType)
name
- the function's name or null
to indicate that the
function is anonymous.source
- the node defining this function. Its type
(Node.getType()
) 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.public FunctionType createInterfaceType(String name, Node source)
name
- the function's namesource
- the node defining this function. Its type
(Node.getType()
) must be Token.FUNCTION
.public com.google.javascript.rhino.jstype.ParameterizedType createParameterizedType(ObjectType objectType, JSType parameterType)
public JSType createNamedType(String reference, String sourceName, int lineno, int charno)
public void identifyNonNullableName(String name)
public JSType createFromTypeNodes(Node n, String sourceName, StaticScope<JSType> scope)
n
- The node with type info.sourceName
- The source file name.scope
- A scope for doing type name lookups.public void setTemplateTypeName(String name)
public void clearTemplateTypeName()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |