shift setParent up one level

This commit is contained in:
Terence Parr 2017-02-27 12:13:12 -08:00
parent ec428d1124
commit 39ba47554a
3 changed files with 24 additions and 11 deletions

View File

@ -163,6 +163,12 @@ public class RuleContext implements RuleNode {
*/
public void setAltNumber(int altNumber) { }
/** @since 4.7. {@see ParseTree#setParent} comment */
@Override
public void setParent(RuleContext parent) {
this.parent = parent;
}
@Override
public ParseTree getChild(int i) {
return null;

View File

@ -24,6 +24,24 @@ public interface ParseTree extends SyntaxTree {
@Override
ParseTree getChild(int i);
/** Set the parent for this node.
*
* This is not backward compatible as it changes
* the interface but no one was able to create custom
* nodes anyway so I'm adding as it improves internal
* code quality.
*
* One could argue for a restructuring of
* the class/interface hierarchy so that
* setParent, addChild are moved up to Tree
* but that's a major change. So I'll do the
* minimal change, which is to add this method.
*
* @since 4.7
*/
void setParent(RuleContext parent);
/** The {@link ParseTreeVisitor} needs a double dispatch method. */
<T> T accept(ParseTreeVisitor<? extends T> visitor);

View File

@ -11,15 +11,4 @@ import org.antlr.v4.runtime.Token;
public interface TerminalNode extends ParseTree {
Token getSymbol();
/** Set the parent for this leaf node.
*
* Technically, this is not backward compatible as it changes
* the interface but no one was able to create custom
* TerminalNodes anyway so I'm adding as it improves internal
* code quality.
*
* @since 4.7
*/
void setParent(RuleContext parent);
}