static class FieldCleanupPass.QualifiedNameSearchTraversal extends NodeTraversal.AbstractShallowCallback
Once a candidate field is found, ask the JSTypeRegistry
for all
JSTypes that have a field with the same name, and check if the field on
that type is defined in the file the compiler is cleaning up. If so, remove
the field, and update the JSTypeRegistry
to no longer associate the
type with the field.
This algorithm was chosen for simplicity and is less than optimally efficient in two ways:
1) All types with a matching field name are iterated over (when only types that extend or implement the JSType indicated by the containing object in the found Qualified Name need to be checked).
2) All Qualified Names are checked, even those which are not L-Values or single declarations of an Type Expression. In general field should only be declared as part of an assignment ('ns.Type.a = 3;') or stand alone name declaration ('ns.Type.a;').
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
srcName |
private JSTypeRegistry |
typeRegistry |
Constructor and Description |
---|
QualifiedNameSearchTraversal(JSTypeRegistry typeRegistry,
java.lang.String srcName) |
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
getFieldName(Node n) |
private void |
removeProperty(ObjectType type,
java.lang.String propName)
Removes a given property from a type and updates type-registry.
|
void |
visit(NodeTraversal t,
Node n,
Node p)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
private final JSTypeRegistry typeRegistry
private final java.lang.String srcName
public QualifiedNameSearchTraversal(JSTypeRegistry typeRegistry, java.lang.String srcName)
public void visit(NodeTraversal t, Node n, Node p)
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).
private void removeProperty(ObjectType type, java.lang.String propName)
type
- the object type to be updated, should not be nullpropName
- the property to removeprivate static java.lang.String getFieldName(Node n)