TerminalNodeImpl.getSourceInterval didn't fulfill the contract of SyntaxTree.getSourceInterval

This commit is contained in:
Sam Harwell 2012-09-22 20:08:12 -05:00
parent 62e005c841
commit 7ed6cdcc4b
2 changed files with 7 additions and 5 deletions

View File

@ -30,6 +30,7 @@
package org.antlr.v4.runtime.tree;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.NotNull;
/** A tree that knows about an interval in a token stream
* is some kind of syntax tree. Subinterfaces distinguish
@ -37,11 +38,11 @@ import org.antlr.v4.runtime.misc.Interval;
*/
public interface SyntaxTree extends Tree {
/** Return an interval indicating the index in the TokenStream of
* the 1st and last token associated with this subtree. If this
* the first and last token associated with this subtree. If this
* node is a leaf, then the interval represents a single token.
*
* If source interval is unknown, this does not return null.
* It returns Interval.INVALID.
* <p/>
* If source interval is unknown, this returns {@link Interval#INVALID}.
*/
@NotNull
Interval getSourceInterval();
}

View File

@ -56,7 +56,8 @@ public class TerminalNodeImpl<Symbol extends Token> implements TerminalNode<Symb
public Interval getSourceInterval() {
if ( symbol ==null ) return Interval.INVALID;
return new Interval(symbol.getStartIndex(), symbol.getStopIndex());
int tokenIndex = symbol.getTokenIndex();
return new Interval(tokenIndex, tokenIndex);
}
@Override