From cb09dd6d0971e22f03ac1ccf8a1304237efb8ed7 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 6 Aug 2012 15:01:00 -0500 Subject: [PATCH] Move RuleNode, TerminalNode, ErrorNode, TerminalNodeImpl, and ErrorNodeImpl to top-level types --- .../antlr/v4/runtime/ParserRuleContext.java | 4 + .../src/org/antlr/v4/runtime/RuleContext.java | 3 +- .../org/antlr/v4/runtime/tree/ErrorNode.java | 35 ++++++++ .../antlr/v4/runtime/tree/ErrorNodeImpl.java | 52 +++++++++++ .../org/antlr/v4/runtime/tree/ParseTree.java | 87 ------------------ .../v4/runtime/tree/ParseTreeListener.java | 4 +- .../v4/runtime/tree/ParseTreeVisitor.java | 6 +- .../v4/runtime/tree/ParseTreeWalker.java | 14 +-- .../org/antlr/v4/runtime/tree/RuleNode.java | 36 ++++++++ .../antlr/v4/runtime/tree/TerminalNode.java | 36 ++++++++ .../v4/runtime/tree/TerminalNodeImpl.java | 90 +++++++++++++++++++ .../src/org/antlr/v4/runtime/tree/Trees.java | 10 +-- .../tree/gui/TreePostScriptGenerator.java | 4 +- .../antlr/v4/runtime/tree/gui/TreeViewer.java | 6 +- .../v4/tool/templates/codegen/Java/Java.stg | 7 +- 15 files changed, 281 insertions(+), 113 deletions(-) create mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNode.java create mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNodeImpl.java create mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/RuleNode.java create mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNode.java create mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNodeImpl.java diff --git a/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java b/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java index 0c1fdaa24..8147b6b52 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ParserRuleContext.java @@ -33,8 +33,12 @@ import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.Nullable; +import org.antlr.v4.runtime.tree.ErrorNode; +import org.antlr.v4.runtime.tree.ErrorNodeImpl; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeListener; +import org.antlr.v4.runtime.tree.TerminalNode; +import org.antlr.v4.runtime.tree.TerminalNodeImpl; import java.util.ArrayList; import java.util.Collections; diff --git a/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java b/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java index 372c4579a..f3b963ff4 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java @@ -32,6 +32,7 @@ import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.Nullable; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeVisitor; +import org.antlr.v4.runtime.tree.RuleNode; import org.antlr.v4.runtime.tree.Trees; import org.antlr.v4.runtime.tree.gui.TreeViewer; @@ -58,7 +59,7 @@ import java.io.IOException; * * @see ParserRuleContext */ -public class RuleContext implements ParseTree.RuleNode { +public class RuleContext implements RuleNode { /** What context invoked this rule? */ public RuleContext parent; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNode.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNode.java new file mode 100644 index 000000000..c7143468c --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNode.java @@ -0,0 +1,35 @@ +/* + [The "BSD license"] + Copyright (c) 2011 Terence Parr + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.antlr.v4.runtime.tree; + +import org.antlr.v4.runtime.Token; + +public interface ErrorNode extends TerminalNode { +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNodeImpl.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNodeImpl.java new file mode 100644 index 000000000..2d7d70609 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ErrorNodeImpl.java @@ -0,0 +1,52 @@ +/* + [The "BSD license"] + Copyright (c) 2011 Terence Parr + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.antlr.v4.runtime.tree; + +import org.antlr.v4.runtime.Token; + +/** Represents a token that was consumed during resynchronization + * rather than during a valid match operation. For example, + * we will create this kind of a node during single token insertion + * and deletion as well as during "consume until error recovery set" + * upon no viable alternative exceptions. + */ +public class ErrorNodeImpl extends + TerminalNodeImpl + implements ErrorNode +{ + public ErrorNodeImpl(Symbol token) { + super(token); + } + + @Override + public T accept(ParseTreeVisitor visitor) { + return visitor.visitErrorNode(this); + } +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTree.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTree.java index d8dea305d..3827a5778 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTree.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTree.java @@ -42,93 +42,6 @@ import org.antlr.v4.runtime.misc.Interval; * The payload is either a token or a context object. */ public interface ParseTree extends SyntaxTree { - public interface RuleNode extends ParseTree { - RuleContext getRuleContext(); - } - - public interface TerminalNode extends ParseTree { - Symbol getSymbol(); - } - - public static class TerminalNodeImpl implements TerminalNode { - public Symbol symbol; - public ParseTree parent; - /** Which ATN node matched this token? */ - public int s; - public TerminalNodeImpl(Symbol symbol) { this.symbol = symbol; } - - @Override - public ParseTree getChild(int i) {return null;} - - @Override - public Symbol getSymbol() {return symbol;} - - @Override - public ParseTree getParent() { return parent; } - - @Override - public Symbol getPayload() { return symbol; } - - @Override - public Interval getSourceInterval() { - if ( symbol ==null ) return Interval.INVALID; - - return new Interval(symbol.getStartIndex(), symbol.getStopIndex()); - } - - @Override - public int getChildCount() { return 0; } - - @Override - public T accept(ParseTreeVisitor visitor) { - return visitor.visitTerminal(this); - } - - @Override - public String getText() { return symbol.getText(); } - - @Override - public String toStringTree(Parser parser) { - return toString(); - } - - public boolean isErrorNode() { return this instanceof ErrorNode; } - - @Override - public String toString() { - if ( symbol.getType() == Token.EOF ) return ""; - return symbol.getText(); - } - - @Override - public String toStringTree() { - return toString(); - } - } - - public interface ErrorNode extends TerminalNode { - } - - /** Represents a token that was consumed during resynchronization - * rather than during a valid match operation. For example, - * we will create this kind of a node during single token insertion - * and deletion as well as during "consume until error recovery set" - * upon no viable alternative exceptions. - */ - public static class ErrorNodeImpl extends - TerminalNodeImpl - implements ErrorNode - { - public ErrorNodeImpl(Symbol token) { - super(token); - } - - @Override - public T accept(ParseTreeVisitor visitor) { - return visitor.visitErrorNode(this); - } - } - // the following methods narrow the return type; they are not additional methods @Override ParseTree getParent(); diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeListener.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeListener.java index 592de1485..b46ec1506 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeListener.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeListener.java @@ -33,8 +33,8 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; public interface ParseTreeListener { - void visitTerminal(ParseTree.TerminalNode node); - void visitErrorNode(ParseTree.ErrorNode node); + void visitTerminal(TerminalNode node); + void visitErrorNode(ErrorNode node); void enterEveryRule(ParserRuleContext ctx); void exitEveryRule(ParserRuleContext ctx); } diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeVisitor.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeVisitor.java index d5e5a47c7..508bc4825 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeVisitor.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeVisitor.java @@ -17,7 +17,7 @@ public class ParseTreeVisitor { * care about some nodes. The {@link ParserRuleContext#accept} method * walks all children by default; i.e., calls this method. */ - public T visitChildren(ParseTree.RuleNode node) { + public T visitChildren(RuleNode node) { T result = null; int n = node.getChildCount(); for (int i=0; i { return result; } - public T visitTerminal(ParseTree.TerminalNode node) { return null; } - public T visitErrorNode(ParseTree.ErrorNode node) { return null; } + public T visitTerminal(TerminalNode node) { return null; } + public T visitErrorNode(ErrorNode node) { return null; } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java index 8b5e20aa8..da9e27ce6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java @@ -37,15 +37,15 @@ public class ParseTreeWalker { @SuppressWarnings("unchecked") public void walk(ParseTreeListener listener, ParseTree t) { - if ( t instanceof ParseTree.ErrorNodeImpl) { - listener.visitErrorNode((ParseTree.ErrorNode)t); + if ( t instanceof ErrorNodeImpl) { + listener.visitErrorNode((ErrorNode)t); return; } - else if ( t instanceof ParseTree.TerminalNode) { - listener.visitTerminal((ParseTree.TerminalNode)t); + else if ( t instanceof TerminalNode) { + listener.visitTerminal((TerminalNode)t); return; } - ParseTree.RuleNode r = (ParseTree.RuleNode)t; + RuleNode r = (RuleNode)t; enterRule(listener, r); int n = r.getChildCount(); for (int i = 0; i void enterRule(ParseTreeListener listener, ParseTree.RuleNode r) { + protected void enterRule(ParseTreeListener listener, RuleNode r) { @SuppressWarnings("unchecked") ParserRuleContext ctx = (ParserRuleContext)r.getRuleContext(); listener.enterEveryRule(ctx); ctx.enterRule(listener); } - protected void exitRule(ParseTreeListener listener, ParseTree.RuleNode r) { + protected void exitRule(ParseTreeListener listener, RuleNode r) { @SuppressWarnings("unchecked") ParserRuleContext ctx = (ParserRuleContext)r.getRuleContext(); ctx.exitRule(listener); diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/RuleNode.java b/runtime/Java/src/org/antlr/v4/runtime/tree/RuleNode.java new file mode 100644 index 000000000..50b903b8a --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/RuleNode.java @@ -0,0 +1,36 @@ +/* + [The "BSD license"] + Copyright (c) 2011 Terence Parr + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.antlr.v4.runtime.tree; + +import org.antlr.v4.runtime.RuleContext; + +public interface RuleNode extends ParseTree { + RuleContext getRuleContext(); +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNode.java b/runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNode.java new file mode 100644 index 000000000..df4e409b2 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNode.java @@ -0,0 +1,36 @@ +/* + [The "BSD license"] + Copyright (c) 2011 Terence Parr + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.antlr.v4.runtime.tree; + +import org.antlr.v4.runtime.Token; + +public interface TerminalNode extends ParseTree { + Symbol getSymbol(); +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNodeImpl.java b/runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNodeImpl.java new file mode 100644 index 000000000..3af112b5e --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/TerminalNodeImpl.java @@ -0,0 +1,90 @@ +/* + [The "BSD license"] + Copyright (c) 2011 Terence Parr + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.antlr.v4.runtime.tree; + +import org.antlr.v4.runtime.Parser; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.misc.Interval; + +public class TerminalNodeImpl implements TerminalNode { + public Symbol symbol; + public ParseTree parent; + /** Which ATN node matched this token? */ + public int s; + public TerminalNodeImpl(Symbol symbol) { this.symbol = symbol; } + + @Override + public ParseTree getChild(int i) {return null;} + + @Override + public Symbol getSymbol() {return symbol;} + + @Override + public ParseTree getParent() { return parent; } + + @Override + public Symbol getPayload() { return symbol; } + + @Override + public Interval getSourceInterval() { + if ( symbol ==null ) return Interval.INVALID; + + return new Interval(symbol.getStartIndex(), symbol.getStopIndex()); + } + + @Override + public int getChildCount() { return 0; } + + @Override + public T accept(ParseTreeVisitor visitor) { + return visitor.visitTerminal(this); + } + + @Override + public String getText() { return symbol.getText(); } + + @Override + public String toStringTree(Parser parser) { + return toString(); + } + + public boolean isErrorNode() { return this instanceof ErrorNode; } + + @Override + public String toString() { + if ( symbol.getType() == Token.EOF ) return ""; + return symbol.getText(); + } + + @Override + public String toStringTree() { + return toString(); + } +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java b/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java index f576eed06..580ff209b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java @@ -97,16 +97,16 @@ public class Trees { public static String getNodeText(Tree t, Parser recog) { if ( recog!=null ) { - if ( t instanceof ParseTree.RuleNode ) { - int ruleIndex = ((ParseTree.RuleNode)t).getRuleContext().getRuleIndex(); + if ( t instanceof RuleNode ) { + int ruleIndex = ((RuleNode)t).getRuleContext().getRuleIndex(); String ruleName = recog.getRuleNames()[ruleIndex]; return ruleName; } - else if ( t instanceof ParseTree.ErrorNodeImpl) { + else if ( t instanceof ErrorNodeImpl) { return t.toString(); } - else if ( t instanceof ParseTree.TerminalNode) { - Object symbol = ((ParseTree.TerminalNode)t).getSymbol(); + else if ( t instanceof TerminalNode) { + Object symbol = ((TerminalNode)t).getSymbol(); if (symbol instanceof Token) { String s = ((Token)symbol).getText(); return s; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreePostScriptGenerator.java b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreePostScriptGenerator.java index 1a96d8ab9..80c54cfca 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreePostScriptGenerator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreePostScriptGenerator.java @@ -36,7 +36,7 @@ import org.abego.treelayout.TreeLayout; import org.abego.treelayout.util.DefaultConfiguration; import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.misc.Utils; -import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.Tree; import java.awt.*; @@ -129,7 +129,7 @@ public class TreePostScriptGenerator { // for debugging, turn this on to see boundingbox of nodes //doc.rect(box.x, box.y, box.width, box.height); // make error nodes from parse tree red by default - if ( t instanceof ParseTree.ErrorNode ) { + if ( t instanceof ErrorNode ) { doc.highlight(box.x, box.y, box.width, box.height); } double x = box.x+nodeWidthPadding; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java index 7a8adc447..419fe14f6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java @@ -36,7 +36,7 @@ import org.abego.treelayout.util.DefaultConfiguration; import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.misc.GraphicsSupport; import org.antlr.v4.runtime.misc.Utils; -import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.Tree; import org.antlr.v4.runtime.tree.Trees; @@ -186,10 +186,10 @@ public class TreeViewer extends JComponent { Rectangle2D.Double box = getBoundsOfNode(tree); // draw the box in the background if ( isHighlighted(tree) || boxColor!=null || - tree instanceof ParseTree.ErrorNode ) + tree instanceof ErrorNode ) { if ( isHighlighted(tree) ) g.setColor(highlightedBoxColor); - else if ( tree instanceof ParseTree.ErrorNode ) g.setColor(LIGHT_RED); + else if ( tree instanceof ErrorNode ) g.setColor(LIGHT_RED); else g.setColor(boxColor); g.fillRoundRect((int) box.x, (int) box.y, (int) box.width - 1, (int) box.height - 1, arcSize, arcSize); diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 28e3f69a0..6173825e6 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -44,7 +44,8 @@ BaseListenerFile(file, header) ::= << import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.TerminalNode; +import org.antlr.v4.runtime.tree.ErrorNode; public class BaseListener implements Listener { BaseListener implements Listene @Override public void enterEveryRule(ParserRuleContext\<\> ctx) { } @Override public void exitEveryRule(ParserRuleContext\<\> ctx) { } - @Override public void visitTerminal(ParseTree.TerminalNode\<\> node) { } - @Override public void visitErrorNode(ParseTree.ErrorNode\<\> node) { } + @Override public void visitTerminal(TerminalNode\<\> node) { } + @Override public void visitErrorNode(ErrorNode\<\> node) { } } >>