private abstract class TypedScopeCreator.AbstractScopeBuilder extends java.lang.Object implements NodeTraversal.Callback, TypedScope.TypeResolver
Modifier and Type | Field and Description |
---|---|
private java.util.List<TypedScopeCreator.DeferredSetType> |
deferredSetTypes |
private InputId |
inputId
The InputId of the current node.
|
private java.util.List<Node> |
lentObjectLiterals
Object literals with a @lends annotation aren't analyzed until we
reach the root of the statement they're defined in.
|
private java.util.List<Node> |
nonExternFunctions
Functions that we found in the global scope and not in externs.
|
(package private) TypedScope |
scope
The scope that we're building.
|
private java.lang.String |
sourceName
The current source file that we're in.
|
private java.util.List<TypedScopeCreator.StubDeclaration> |
stubDeclarations
Type-less stubs.
|
Modifier | Constructor and Description |
---|---|
private |
AbstractScopeBuilder(TypedScope scope) |
Modifier and Type | Method and Description |
---|---|
private void |
applyDelegateRelationship(CodingConvention.DelegateRelationship delegateRelationship)
Apply special properties that only apply to delegates.
|
(package private) void |
assertDefinitionNode(Node n,
int type)
Asserts that it's OK to define this node's name.
|
private void |
attachLiteralTypes(Node n) |
private void |
checkForCallingConventionDefiningCalls(Node n,
java.util.Map<java.lang.String,java.lang.String> delegateCallingConventions)
Look for calls that set a delegate method's calling convention.
|
private void |
checkForClassDefiningCalls(Node n)
Look for class-defining calls.
|
private EnumType |
createEnumTypeFromNodes(Node rValue,
java.lang.String name,
JSDocInfo info)
Creates a new enum type, based on the given nodes.
|
private FunctionType |
createFunctionTypeFromNodes(Node rValue,
java.lang.String name,
JSDocInfo info,
Node lvalueNode)
Creates a new function type, based on the given nodes.
|
(package private) void |
defineCatch(Node n)
Defines a catch parameter.
|
(package private) void |
defineFunctionLiteral(Node n)
Defines a function literal.
|
private void |
defineName(Node name,
Node var,
JSDocInfo info)
Defines a variable based on the
Token.NAME node passed. |
private void |
defineObjectLiteral(Node objectLit) |
private void |
defineSlot(Node name,
Node parent,
JSType type)
Defines a typed variable.
|
(package private) void |
defineSlot(Node n,
Node parent,
JSType type,
boolean inferred)
Defines a typed variable.
|
(package private) void |
defineSlot(Node n,
Node parent,
java.lang.String variableName,
JSType type,
boolean inferred)
Defines a symbol in the current scope.
|
(package private) void |
defineVar(Node n)
Defines a VAR initialization.
|
private FunctionType |
findOverriddenFunction(ObjectType ownerType,
java.lang.String propName,
TemplateTypeMap typeMap)
Find the function that's being overridden on this type, if any.
|
private void |
finishConstructorDefinition(Node n,
java.lang.String variableName,
FunctionType fnType,
TypedScope scopeToDeclareIn,
CompilerInput input,
TypedVar newVar) |
private JSType |
getDeclaredRValueType(Node lValue,
Node rValue)
Check for common idioms of a typed R-value assigned to a const L-value.
|
(package private) JSType |
getDeclaredType(JSDocInfo info,
Node lValue,
Node rValue)
Look for a type declaration on a property assignment
(in an ASSIGN or an object literal key).
|
private JSType |
getDeclaredTypeInAnnotation(Node node,
JSDocInfo info)
Returns the type specified in a JSDoc annotation near a GETPROP or NAME.
|
private ObjectType |
getObjectSlot(java.lang.String slotName)
Find the ObjectType associated with the given slot.
|
private ObjectType |
getPrototypeOwnerType(ObjectType ownerType) |
private TypedScope |
getQnameRootScope(Node n)
Return the scope for the name of the given node.
|
private boolean |
isGoogAbstractMethod(Node n)
We have to special-case goog.abstractMethod in createFunctionTypeFromNodes,
because some people use it (incorrectly) for interfaces:
/* @interface * /
var example.MyInterface = goog.abstractMethod;
|
private boolean |
isQnameRootedInGlobalScope(Node n)
Check if the given node is a property of a name in the global scope.
|
private boolean |
isQualifiedNameInferred(java.lang.String qName,
Node n,
JSDocInfo info,
Node rhsValue,
JSType valueType)
Determines whether a qualified name is inferred.
|
private JSType |
lookupQualifiedName(Node n) |
(package private) void |
maybeDeclareQualifiedName(NodeTraversal t,
JSDocInfo info,
Node n,
Node parent,
Node rhsValue)
Declare the symbol for a qualified name in the global scope.
|
(package private) void |
processObjectLitProperties(Node objLit,
ObjectType objLitType,
boolean declareOnOwner)
Process an object literal and all the types on it.
|
(package private) void |
resolveStubDeclarations()
Resolve any stub declarations to unknown types if we could not
find types for them during traversal.
|
void |
resolveTypes() |
(package private) void |
setDeferredType(Node node,
JSType type) |
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed.
|
private boolean |
shouldUseFunctionLiteralType(FunctionType type,
JSDocInfo info,
Node lValue)
If a variable is assigned a function literal in the global scope,
make that a declared type (even if there's no doc info).
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
final TypedScope scope
private final java.util.List<TypedScopeCreator.DeferredSetType> deferredSetTypes
private final java.util.List<Node> nonExternFunctions
private java.util.List<Node> lentObjectLiterals
private final java.util.List<TypedScopeCreator.StubDeclaration> stubDeclarations
private java.lang.String sourceName
private InputId inputId
private AbstractScopeBuilder(TypedScope scope)
public void resolveTypes()
resolveTypes
in interface TypedScope.TypeResolver
public final boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed. If children are
traversed, they will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)
in postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
private void attachLiteralTypes(Node n)
private void defineObjectLiteral(Node objectLit)
void processObjectLitProperties(Node objLit, ObjectType objLitType, boolean declareOnOwner)
objLit
- The OBJECTLIT node.objLitType
- The type of the OBJECTLIT node. This might be a named
type, because of the lends annotation.declareOnOwner
- If true, declare properties on the objLitType as
well. If false, the caller should take care of this.private JSType getDeclaredTypeInAnnotation(Node node, JSDocInfo info)
@type
tag or from
the @return
and @param
tags.void assertDefinitionNode(Node n, int type)
void defineCatch(Node n)
void defineVar(Node n)
void defineFunctionLiteral(Node n)
private void defineName(Node name, Node var, JSDocInfo info)
Token.NAME
node passed.name
- The Token.NAME
node.var
- The parent of the name
node, which must be a
Token.VAR
node.info
- the JSDocInfo
information relating to this
name
node.private boolean shouldUseFunctionLiteralType(FunctionType type, JSDocInfo info, Node lValue)
private FunctionType createFunctionTypeFromNodes(@Nullable Node rValue, @Nullable java.lang.String name, @Nullable JSDocInfo info, @Nullable Node lvalueNode)
rValue
- The function node.name
- the function's nameinfo
- the JSDocInfo
attached to the function definitionlvalueNode
- The node where this function is being
assigned. For example, A.prototype.foo = ...
would be used to
determine that this function is a method of A.prototype. May be
null to indicate that this is not being assigned to a qualified name.private boolean isGoogAbstractMethod(Node n)
private ObjectType getPrototypeOwnerType(ObjectType ownerType)
private FunctionType findOverriddenFunction(ObjectType ownerType, java.lang.String propName, TemplateTypeMap typeMap)
private EnumType createEnumTypeFromNodes(Node rValue, java.lang.String name, JSDocInfo info)
rValue
- The node of the enum.name
- The enum's nameinfo
- The JSDocInfo
attached to the enum definition.private void defineSlot(Node name, Node parent, JSType type)
null
if its type is inferred.name
- the defining node. It must be a Token.NAME
.parent
- the name
's parent.type
- the variable's type. It may be null
, in which case
the variable's type will be inferred.void defineSlot(Node n, Node parent, JSType type, boolean inferred)
JSTypeNative.UNKNOWN_TYPE
if its type is
inferred.
Slots may be any variable or any qualified name in the global scope.n
- the defining NAME or GETPROP node.parent
- the n
's parent.type
- the variable's type. It may be null
if
inferred
is true
.void defineSlot(Node n, Node parent, java.lang.String variableName, JSType type, boolean inferred)
n
- the defining NAME or GETPROP or object literal key node.parent
- the n
's parent.variableName
- The name that this should be known by.type
- the variable's type. It may be null
if
inferred
is true
.inferred
- Whether the type is inferred or declared.private void finishConstructorDefinition(Node n, java.lang.String variableName, FunctionType fnType, TypedScope scopeToDeclareIn, CompilerInput input, TypedVar newVar)
private boolean isQnameRootedInGlobalScope(Node n)
private TypedScope getQnameRootScope(Node n)
JSType getDeclaredType(JSDocInfo info, Node lValue, @Nullable Node rValue)
info
- The doc info for this property.lValue
- The l-value node.rValue
- The node that n
is being initialized to,
or null
if this is a stub declaration.private JSType getDeclaredRValueType(Node lValue, Node rValue)
private void checkForCallingConventionDefiningCalls(Node n, java.util.Map<java.lang.String,java.lang.String> delegateCallingConventions)
private void checkForClassDefiningCalls(Node n)
private void applyDelegateRelationship(CodingConvention.DelegateRelationship delegateRelationship)
void maybeDeclareQualifiedName(NodeTraversal t, JSDocInfo info, Node n, Node parent, Node rhsValue)
info
- The doc info for this property.n
- A top-level GETPROP node (it should not be contained inside
another GETPROP).parent
- The parent of n
.rhsValue
- The node that n
is being initialized to,
or null
if this is a stub declaration.private boolean isQualifiedNameInferred(java.lang.String qName, Node n, JSDocInfo info, Node rhsValue, JSType valueType)
private ObjectType getObjectSlot(java.lang.String slotName)
slotName
- The name of the slot to find the type in.void resolveStubDeclarations()