if (match(node) != null) {
if (scope.isOuter()) {
mq.addMessage(
RewriterMessageType.THIS_IN_GLOBAL_CONTEXT,
node.getFilePosition());
return new NullLiteral(node.getFilePosition());
}
}
return NONE;
}
},
new Rule() {
@Override
@RuleDescription(
name="argumentsReference",
synopsis="Disallow arguments in the global scope.",
reason="The declaration cannot be rewritten.",
matches="arguments",
substitutes="arguments")
public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
if (match(node) != null) {
if (scope.isOuter()) {
mq.addMessage(
RewriterMessageType.ARGUMENTS_IN_GLOBAL_CONTEXT,
node.getFilePosition());
return new NullLiteral(node.getFilePosition());
}
}
return NONE;
}
},
new Rule() {
@Override
@RuleDescription(
name="rename",
synopsis="",
reason="",
matches="/* Reference */ @r",
substitutes="@r")
public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
if (node instanceof Reference) {
Reference r = (Reference) node;
if (!isSynthetic(r)) {
FilePosition pos = r.getFilePosition();
String rname = r.getIdentifierName();
NameContext<String, ?> context = contexts.get(scope);
NameContext.VarInfo<String, ?> vi = context.lookup(rname);
if (vi != null) {
return new Reference(new Identifier(pos, vi.newName));
} else {
mq.addMessage(
RewriterMessageType.FREE_VARIABLE, pos,
MessagePart.Factory.valueOf(rname));
return new NullLiteral(pos);
}
}
}
return NONE;
}