v4: Specify @Override

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9341]
This commit is contained in:
sharwell 2011-11-17 16:58:10 -08:00
parent 0d41d48d6e
commit 3526198105
18 changed files with 89 additions and 0 deletions

View File

@ -73,6 +73,7 @@ public class ANTLRFileStream extends ANTLRStringStream {
} }
} }
@Override
public String getSourceName() { public String getSourceName() {
return fileName; return fileName;
} }

View File

@ -94,6 +94,7 @@ public class ANTLRStringStream implements CharStream {
markDepth = 0; markDepth = 0;
} }
@Override
public void consume() { public void consume() {
//System.out.println("prev p="+p+", c="+(char)data[p]); //System.out.println("prev p="+p+", c="+(char)data[p]);
if ( p < n ) { if ( p < n ) {
@ -111,6 +112,7 @@ public class ANTLRStringStream implements CharStream {
} }
} }
@Override
public int LA(int i) { public int LA(int i) {
if ( i==0 ) { if ( i==0 ) {
return 0; // undefined return 0; // undefined
@ -139,14 +141,17 @@ public class ANTLRStringStream implements CharStream {
* last symbol has been read. The index is the index of char to * last symbol has been read. The index is the index of char to
* be returned from LA(1). * be returned from LA(1).
*/ */
@Override
public int index() { public int index() {
return p; return p;
} }
@Override
public int size() { public int size() {
return n; return n;
} }
@Override
public int mark() { public int mark() {
if ( markers==null ) { if ( markers==null ) {
markers = new ArrayList<CharStreamState>(); markers = new ArrayList<CharStreamState>();
@ -181,6 +186,7 @@ public class ANTLRStringStream implements CharStream {
rewind(lastMarker); rewind(lastMarker);
} }
@Override
public void release(int marker) { public void release(int marker) {
// unwind any other markers made after m and release m // unwind any other markers made after m and release m
markDepth = marker; markDepth = marker;
@ -191,6 +197,7 @@ public class ANTLRStringStream implements CharStream {
/** consume() ahead until p==index; can't just set p=index as we must /** consume() ahead until p==index; can't just set p=index as we must
* update line and charPositionInLine. If we seek backwards, just set p * update line and charPositionInLine. If we seek backwards, just set p
*/ */
@Override
public void seek(int index) { public void seek(int index) {
if ( index<=p ) { if ( index<=p ) {
p = index; // just jump; don't update stream state (line, ...) p = index; // just jump; don't update stream state (line, ...)
@ -202,6 +209,7 @@ public class ANTLRStringStream implements CharStream {
} }
} }
@Override
public String substring(int start, int stop) { public String substring(int start, int stop) {
if ( stop >= n ) stop = n-1; if ( stop >= n ) stop = n-1;
int count = stop - start + 1; int count = stop - start + 1;
@ -228,6 +236,7 @@ public class ANTLRStringStream implements CharStream {
this.charPositionInLine = pos; this.charPositionInLine = pos;
} }
@Override
public String getSourceName() { public String getSourceName() {
return name; return name;
} }

View File

@ -73,18 +73,22 @@ public class BufferedTokenStream implements TokenStream {
this.tokenSource = tokenSource; this.tokenSource = tokenSource;
} }
@Override
public TokenSource getTokenSource() { return tokenSource; } public TokenSource getTokenSource() { return tokenSource; }
@Override
public int index() { return p; } public int index() { return p; }
// public int range() { return range; } // public int range() { return range; }
@Override
public int mark() { public int mark() {
if ( p == -1 ) setup(); if ( p == -1 ) setup();
lastMarker = index(); lastMarker = index();
return lastMarker; return lastMarker;
} }
@Override
public void release(int marker) { public void release(int marker) {
// no resources to release // no resources to release
} }
@ -102,8 +106,10 @@ public class BufferedTokenStream implements TokenStream {
lastMarker = 0; lastMarker = 0;
} }
@Override
public void seek(int index) { p = index; } public void seek(int index) { p = index; }
@Override
public int size() { return tokens.size(); } public int size() { return tokens.size(); }
/** Move the input pointer to the next incoming token. The stream /** Move the input pointer to the next incoming token. The stream
@ -113,6 +119,7 @@ public class BufferedTokenStream implements TokenStream {
* *
* Walk past any token not on the channel the parser is listening to. * Walk past any token not on the channel the parser is listening to.
*/ */
@Override
public void consume() { public void consume() {
if ( p == -1 ) setup(); if ( p == -1 ) setup();
p++; p++;
@ -137,6 +144,7 @@ public class BufferedTokenStream implements TokenStream {
} }
} }
@Override
public Token get(int i) { public Token get(int i) {
if ( i < 0 || i >= tokens.size() ) { if ( i < 0 || i >= tokens.size() ) {
throw new NoSuchElementException("token index "+i+" out of range 0.."+(tokens.size()-1)); throw new NoSuchElementException("token index "+i+" out of range 0.."+(tokens.size()-1));
@ -158,6 +166,7 @@ public class BufferedTokenStream implements TokenStream {
return subset; return subset;
} }
@Override
public int LA(int i) { return LT(i).getType(); } public int LA(int i) { return LT(i).getType(); }
protected Token LB(int k) { protected Token LB(int k) {
@ -165,6 +174,7 @@ public class BufferedTokenStream implements TokenStream {
return tokens.get(p-k); return tokens.get(p-k);
} }
@Override
public Token LT(int k) { public Token LT(int k) {
if ( p == -1 ) setup(); if ( p == -1 ) setup();
if ( k==0 ) return null; if ( k==0 ) return null;
@ -225,6 +235,7 @@ public class BufferedTokenStream implements TokenStream {
return getTokens(start,stop, s); return getTokens(start,stop, s);
} }
@Override
public String getSourceName() { return tokenSource.getSourceName(); } public String getSourceName() { return tokenSource.getSourceName(); }
/** Grab *all* tokens from stream and return string */ /** Grab *all* tokens from stream and return string */
@ -234,6 +245,7 @@ public class BufferedTokenStream implements TokenStream {
return toString(0, tokens.size()-1); return toString(0, tokens.size()-1);
} }
@Override
public String toString(int start, int stop) { public String toString(int start, int stop) {
if ( start<0 || stop<0 ) return ""; if ( start<0 || stop<0 ) return "";
if ( p == -1 ) setup(); if ( p == -1 ) setup();
@ -247,6 +259,7 @@ public class BufferedTokenStream implements TokenStream {
return buf.toString(); return buf.toString();
} }
@Override
public String toString(Token start, Token stop) { public String toString(Token start, Token stop) {
if ( start!=null && stop!=null ) { if ( start!=null && stop!=null ) {
return toString(start.getTokenIndex(), stop.getTokenIndex()); return toString(start.getTokenIndex(), stop.getTokenIndex());

View File

@ -88,14 +88,17 @@ public class CommonToken implements WritableToken, Serializable {
} }
} }
@Override
public int getType() { public int getType() {
return type; return type;
} }
@Override
public void setLine(int line) { public void setLine(int line) {
this.line = line; this.line = line;
} }
@Override
public String getText() { public String getText() {
if ( text!=null ) { if ( text!=null ) {
return text; return text;
@ -118,34 +121,42 @@ public class CommonToken implements WritableToken, Serializable {
* that start/stop indexes are not valid. It means that that input * that start/stop indexes are not valid. It means that that input
* was converted to a new string in the token object. * was converted to a new string in the token object.
*/ */
@Override
public void setText(String text) { public void setText(String text) {
this.text = text; this.text = text;
} }
@Override
public int getLine() { public int getLine() {
return line; return line;
} }
@Override
public int getCharPositionInLine() { public int getCharPositionInLine() {
return charPositionInLine; return charPositionInLine;
} }
@Override
public void setCharPositionInLine(int charPositionInLine) { public void setCharPositionInLine(int charPositionInLine) {
this.charPositionInLine = charPositionInLine; this.charPositionInLine = charPositionInLine;
} }
@Override
public int getChannel() { public int getChannel() {
return channel; return channel;
} }
@Override
public void setChannel(int channel) { public void setChannel(int channel) {
this.channel = channel; this.channel = channel;
} }
@Override
public void setType(int type) { public void setType(int type) {
this.type = type; this.type = type;
} }
@Override
public int getStartIndex() { public int getStartIndex() {
return start; return start;
} }
@ -154,6 +165,7 @@ public class CommonToken implements WritableToken, Serializable {
this.start = start; this.start = start;
} }
@Override
public int getStopIndex() { public int getStopIndex() {
return stop; return stop;
} }
@ -162,14 +174,17 @@ public class CommonToken implements WritableToken, Serializable {
this.stop = stop; this.stop = stop;
} }
@Override
public int getTokenIndex() { public int getTokenIndex() {
return index; return index;
} }
@Override
public void setTokenIndex(int index) { public void setTokenIndex(int index) {
this.index = index; this.index = index;
} }
@Override
public TokenSource getTokenSource() { public TokenSource getTokenSource() {
return source; return source;
} }

View File

@ -62,6 +62,7 @@ public class CommonTokenStream extends BufferedTokenStream {
} }
/** Always leave p on an on-channel token. */ /** Always leave p on an on-channel token. */
@Override
public void consume() { public void consume() {
if ( p == -1 ) setup(); if ( p == -1 ) setup();
p++; p++;
@ -72,6 +73,7 @@ public class CommonTokenStream extends BufferedTokenStream {
} }
} }
@Override
protected Token LB(int k) { protected Token LB(int k) {
if ( k==0 || (p-k)<0 ) return null; if ( k==0 || (p-k)<0 ) return null;
@ -87,6 +89,7 @@ public class CommonTokenStream extends BufferedTokenStream {
return tokens.get(i); return tokens.get(i);
} }
@Override
public Token LT(int k) { public Token LT(int k) {
//System.out.println("enter LT("+k+")"); //System.out.println("enter LT("+k+")");
if ( p == -1 ) setup(); if ( p == -1 ) setup();
@ -123,6 +126,7 @@ public class CommonTokenStream extends BufferedTokenStream {
return i; return i;
} }
@Override
protected void setup() { protected void setup() {
p = 0; p = 0;
sync(0); sync(0);
@ -147,6 +151,7 @@ public class CommonTokenStream extends BufferedTokenStream {
} }
/** Reset this token stream by setting its token source. */ /** Reset this token stream by setting its token source. */
@Override
public void setTokenSource(TokenSource tokenSource) { public void setTokenSource(TokenSource tokenSource) {
super.setTokenSource(tokenSource); super.setTokenSource(tokenSource);
channel = Token.DEFAULT_CHANNEL; channel = Token.DEFAULT_CHANNEL;

View File

@ -45,6 +45,7 @@ public class AtomTransition extends Transition {
super(target); super(target);
} }
@Override
public IntervalSet label() { return IntervalSet.of(label); } public IntervalSet label() { return IntervalSet.of(label); }
public String toString() { public String toString() {

View File

@ -32,6 +32,7 @@ package org.antlr.v4.runtime.atn;
public class EpsilonTransition extends Transition { public class EpsilonTransition extends Transition {
public EpsilonTransition(ATNState target) { super(target); } public EpsilonTransition(ATNState target) { super(target); }
@Override
public boolean isEpsilon() { return true; } public boolean isEpsilon() { return true; }
public String toString() { public String toString() {

View File

@ -50,6 +50,7 @@ public class PredicateTransition extends Transition {
this.predIndex = predIndex; this.predIndex = predIndex;
} }
@Override
public boolean isEpsilon() { return true; } public boolean isEpsilon() { return true; }
public String toString() { public String toString() {

View File

@ -50,5 +50,6 @@ public class RuleTransition extends Transition {
super(ruleStart); super(ruleStart);
} }
@Override
public boolean isEpsilon() { return true; } public boolean isEpsilon() { return true; }
} }

View File

@ -46,6 +46,7 @@ public class SetTransition extends Transition {
super(target); super(target);
} }
@Override
public IntervalSet label() { return set; } public IntervalSet label() { return set; }
public String toString() { public String toString() {

View File

@ -83,6 +83,7 @@ public class GraphicsSupport {
if (factories.length > 0) { if (factories.length > 0) {
PrintService service = factories[0].getPrintService(out); PrintService service = factories[0].getPrintService(out);
SimpleDoc doc = new SimpleDoc(new Printable() { SimpleDoc doc = new SimpleDoc(new Printable() {
@Override
public int print(Graphics g, PageFormat pf, int page) { public int print(Graphics g, PageFormat pf, int page) {
if (page >= 1) return Printable.NO_SUCH_PAGE; if (page >= 1) return Printable.NO_SUCH_PAGE;
else { else {

View File

@ -51,8 +51,10 @@ public interface AST extends SyntaxTree {
int getCharPositionInLine(); int getCharPositionInLine();
/** Redefined from Tree interface so we can narrow the return type */ /** Redefined from Tree interface so we can narrow the return type */
@Override
AST getParent(); AST getParent();
/** Redefined from Tree interface so we can narrow the return type */ /** Redefined from Tree interface so we can narrow the return type */
@Override
Token getPayload(); Token getPayload();
} }

View File

@ -78,6 +78,7 @@ public class ASTIterator<T> implements Iterator<T> {
nodes.clear(); nodes.clear();
} }
@Override
public boolean hasNext() { public boolean hasNext() {
if ( firstTime ) return root!=null; if ( firstTime ) return root!=null;
if ( nodes!=null && nodes.size()>0 ) return true; if ( nodes!=null && nodes.size()>0 ) return true;
@ -86,6 +87,7 @@ public class ASTIterator<T> implements Iterator<T> {
return adaptor.getParent(tree)!=null; // back at root? return adaptor.getParent(tree)!=null; // back at root?
} }
@Override
public T next() { public T next() {
if ( firstTime ) { // initial condition if ( firstTime ) { // initial condition
firstTime = false; firstTime = false;
@ -132,5 +134,6 @@ public class ASTIterator<T> implements Iterator<T> {
return nodes.remove(); return nodes.remove();
} }
@Override
public void remove() { throw new UnsupportedOperationException(); } public void remove() { throw new UnsupportedOperationException(); }
} }

View File

@ -37,6 +37,7 @@ public interface ASTNodeStream<T> extends ObjectStream<T> {
* If you don't want to buffer up nodes, then this method makes no * If you don't want to buffer up nodes, then this method makes no
* sense for you. * sense for you.
*/ */
@Override
T get(int i); T get(int i);
/** Get tree node at current input pointer + i ahead where i=1 is next node. /** Get tree node at current input pointer + i ahead where i=1 is next node.
@ -50,6 +51,7 @@ public interface ASTNodeStream<T> extends ObjectStream<T> {
* returns a tree node instead of a token. Makes code gen identical * returns a tree node instead of a token. Makes code gen identical
* for both parser and tree grammars. :) * for both parser and tree grammars. :)
*/ */
@Override
T LT(int k); T LT(int k);
/** Where is this stream pulling nodes from? This is not the name, but /** Where is this stream pulling nodes from? This is not the name, but

View File

@ -60,6 +60,7 @@ public abstract class BaseAST implements AST {
public BaseAST(AST node) { public BaseAST(AST node) {
} }
@Override
public BaseAST getChild(int i) { public BaseAST getChild(int i) {
if ( children==null || i>=children.size() ) { if ( children==null || i>=children.size() ) {
return null; return null;
@ -76,6 +77,7 @@ public abstract class BaseAST implements AST {
return Trees.getFirstChildWithType(this, type); return Trees.getFirstChildWithType(this, type);
} }
@Override
public int getChildCount() { public int getChildCount() {
if ( children==null ) return 0; if ( children==null ) return 0;
return children.size(); return children.size();
@ -157,6 +159,7 @@ public abstract class BaseAST implements AST {
return childIndex; return childIndex;
} }
@Override
public AST getParent() { public AST getParent() {
return parent; return parent;
} }
@ -211,6 +214,7 @@ public abstract class BaseAST implements AST {
return new ArrayList<BaseAST>(); return new ArrayList<BaseAST>();
} }
@Override
public boolean isNil() { public boolean isNil() {
return false; return false;
} }
@ -275,6 +279,7 @@ public abstract class BaseAST implements AST {
/** Don't use standard tree printing mechanism since ASTs can have nil /** Don't use standard tree printing mechanism since ASTs can have nil
* root nodes. * root nodes.
*/ */
@Override
public String toStringTree() { public String toStringTree() {
return Trees.toStringTree(this, null); return Trees.toStringTree(this, null);
// if ( children==null || children.size()==0 ) { // if ( children==null || children.size()==0 ) {

View File

@ -43,20 +43,24 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
protected Map<BaseAST, Integer> treeToUniqueIDMap; protected Map<BaseAST, Integer> treeToUniqueIDMap;
protected int uniqueNodeID = 1; protected int uniqueNodeID = 1;
@Override
public List<T> createElementList() { public List<T> createElementList() {
return new ElementList<T>(this); return new ElementList<T>(this);
} }
// END v4 stuff // END v4 stuff
@Override
public T nil() { public T nil() {
return create(null); return create(null);
} }
@Override
public boolean isNil(T tree) { public boolean isNil(T tree) {
return ((AST)tree).isNil(); return ((AST)tree).isNil();
} }
@Override
public T dupTree(T tree) { public T dupTree(T tree) {
return dupTree(tree, null); return dupTree(tree, null);
} }
@ -89,6 +93,7 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
* make sure that this is consistent with have the user will build * make sure that this is consistent with have the user will build
* ASTs. * ASTs.
*/ */
@Override
public void addChild(T t, T child) { public void addChild(T t, T child) {
if ( t!=null && child!=null ) { if ( t!=null && child!=null ) {
((BaseAST)t).addChild((BaseAST) child); ((BaseAST)t).addChild((BaseAST) child);
@ -121,6 +126,7 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
* constructing these nodes so we should have this control for * constructing these nodes so we should have this control for
* efficiency. * efficiency.
*/ */
@Override
public T becomeRoot(T newRoot, T oldRoot) { public T becomeRoot(T newRoot, T oldRoot) {
//System.out.println("becomeroot new "+newRoot.toString()+" old "+oldRoot); //System.out.println("becomeroot new "+newRoot.toString()+" old "+oldRoot);
if ( oldRoot==null ) { if ( oldRoot==null ) {
@ -143,6 +149,7 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
} }
/** Transform ^(nil x) to x and nil to null */ /** Transform ^(nil x) to x and nil to null */
@Override
public T rulePostProcessing(T root) { public T rulePostProcessing(T root) {
//System.out.println("rulePostProcessing: "+((AST)root).toStringTree()); //System.out.println("rulePostProcessing: "+((AST)root).toStringTree());
if ( root!=null && root.isNil() ) { if ( root!=null && root.isNil() ) {
@ -159,10 +166,12 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
return root; return root;
} }
@Override
public T becomeRoot(Token newRoot, T oldRoot) { public T becomeRoot(Token newRoot, T oldRoot) {
return becomeRoot(create(newRoot), oldRoot); return becomeRoot(create(newRoot), oldRoot);
} }
@Override
public T create(int tokenType, Token fromToken) { public T create(int tokenType, Token fromToken) {
WritableToken tok = createToken(fromToken); WritableToken tok = createToken(fromToken);
//((ClassicToken)fromToken).setType(tokenType); //((ClassicToken)fromToken).setType(tokenType);
@ -170,6 +179,7 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
return create(tok); return create(tok);
} }
@Override
public T create(int tokenType, Token fromToken, String text) { public T create(int tokenType, Token fromToken, String text) {
if (fromToken == null) return create(tokenType, text); if (fromToken == null) return create(tokenType, text);
WritableToken tok = createToken(fromToken); WritableToken tok = createToken(fromToken);
@ -178,43 +188,53 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
return create(tok); return create(tok);
} }
@Override
public T create(int tokenType, String text) { public T create(int tokenType, String text) {
Token fromToken = createToken(tokenType, text); Token fromToken = createToken(tokenType, text);
return create(fromToken); return create(fromToken);
} }
@Override
public int getType(T t) { public int getType(T t) {
return t.getType(); return t.getType();
} }
@Override
public void setType(T t, int type) { public void setType(T t, int type) {
throw new UnsupportedOperationException("don't know enough about AST node"); throw new UnsupportedOperationException("don't know enough about AST node");
} }
@Override
public String getText(T t) { public String getText(T t) {
return t.getText(); return t.getText();
} }
@Override
public void setText(T t, String text) { public void setText(T t, String text) {
throw new UnsupportedOperationException("don't know enough about AST node"); throw new UnsupportedOperationException("don't know enough about AST node");
} }
@Override
public T getChild(T t, int i) { public T getChild(T t, int i) {
return (T)t.getChild(i); return (T)t.getChild(i);
} }
@Override
public void setChild(T t, int i, T child) { public void setChild(T t, int i, T child) {
t.setChild(i, child); t.setChild(i, child);
} }
@Override
public T deleteChild(T t, int i) { public T deleteChild(T t, int i) {
return (T)t.deleteChild(i); return (T)t.deleteChild(i);
} }
@Override
public int getChildCount(T t) { public int getChildCount(T t) {
return ((BaseAST)t).getChildCount(); return ((BaseAST)t).getChildCount();
} }
@Override
public int getUniqueID(T node) { public int getUniqueID(T node) {
if ( treeToUniqueIDMap==null ) { if ( treeToUniqueIDMap==null ) {
treeToUniqueIDMap = new HashMap(); treeToUniqueIDMap = new HashMap();

View File

@ -59,14 +59,17 @@ public class CommonAST extends BaseAST {
return token; return token;
} }
@Override
public Token getPayload() { public Token getPayload() {
return getToken(); return getToken();
} }
@Override
public Interval getSourceInterval() { public Interval getSourceInterval() {
return new Interval(getTokenStartIndex(), getTokenStopIndex()); return new Interval(getTokenStartIndex(), getTokenStopIndex());
} }
@Override
public boolean isNil() { public boolean isNil() {
return token==null; return token==null;
} }
@ -81,6 +84,7 @@ public class CommonAST extends BaseAST {
return (CommonAST)super.getParent(); return (CommonAST)super.getParent();
} }
@Override
public int getType() { public int getType() {
if ( token==null ) { if ( token==null ) {
return Token.INVALID_TYPE; return Token.INVALID_TYPE;
@ -88,6 +92,7 @@ public class CommonAST extends BaseAST {
return token.getType(); return token.getType();
} }
@Override
public String getText() { public String getText() {
if ( token==null ) { if ( token==null ) {
return null; return null;
@ -95,6 +100,7 @@ public class CommonAST extends BaseAST {
return token.getText(); return token.getText();
} }
@Override
public int getLine() { public int getLine() {
if ( token==null || token.getLine()==0 ) { if ( token==null || token.getLine()==0 ) {
if ( getChildCount()>0 ) { if ( getChildCount()>0 ) {
@ -105,6 +111,7 @@ public class CommonAST extends BaseAST {
return token.getLine(); return token.getLine();
} }
@Override
public int getCharPositionInLine() { public int getCharPositionInLine() {
if ( token==null || token.getCharPositionInLine()==-1 ) { if ( token==null || token.getCharPositionInLine()==-1 ) {
if ( getChildCount()>0 ) { if ( getChildCount()>0 ) {

View File

@ -40,6 +40,7 @@ public class RewriteCardinalityException extends RuntimeException {
this.elementDescription = elementDescription; this.elementDescription = elementDescription;
} }
@Override
public String getMessage() { public String getMessage() {
if ( elementDescription!=null ) { if ( elementDescription!=null ) {
return elementDescription; return elementDescription;