class DefinitionsRemover.Definition {
/**
* Variable or property name represented by this definition.
* For example, in the case of assignments this method would
* return the NAME, GETPROP or GETELEM expression that acts as the
* assignment left hand side.
*
* @return the L-Value associated with this definition.
* The node's type is always NAME, GETPROP or GETELEM.
*/
public abstract Node getLValue();
}
class DefinitionsRemover.IncompleteDefinition {
@Override
public Node getLValue() {
return lValue;
}
}
class DefinitionsRemover.FunctionDefinition {
@Override
public Node getLValue() {
return function.getFirstChild();
}
}
class DefinitionsRemover.AssignmentDefinition {
@Override
public Node getLValue() {
return assignment.getFirstChild();
}
}
class DefinitionsRemover.ObjectLiteralPropertyDefinition {
@Override
public Node getLValue() {
// TODO(user) revisit: object literal definitions are an example
// of definitions whose lhs doesn't correspond to a node that
// exists in the AST. We will have to change the return type of
// getLValue sooner or later in order to provide this added
// flexibility.
switch (name.getType()) {
case Token.SET:
case Token.GET:
case Token.STRING:
// TODO(johnlenz): return a GETELEM for quoted strings.
return new Node(Token.GETPROP,
new Node(Token.OBJECTLIT),
name.cloneNode());
case Token.NUMBER:
return new Node(Token.GETELEM,
new Node(Token.OBJECTLIT),
name.cloneNode());
default:
throw new IllegalStateException("unexpected");
}
}
}
class DefinitionsRemover.VarDefinition {
@Override
public Node getLValue() {
return name;
}
}
|