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() {
return fileName;
}

View File

@ -94,6 +94,7 @@ public class ANTLRStringStream implements CharStream {
markDepth = 0;
}
@Override
public void consume() {
//System.out.println("prev p="+p+", c="+(char)data[p]);
if ( p < n ) {
@ -111,6 +112,7 @@ public class ANTLRStringStream implements CharStream {
}
}
@Override
public int LA(int i) {
if ( i==0 ) {
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
* be returned from LA(1).
*/
@Override
public int index() {
return p;
}
@Override
public int size() {
return n;
}
@Override
public int mark() {
if ( markers==null ) {
markers = new ArrayList<CharStreamState>();
@ -181,6 +186,7 @@ public class ANTLRStringStream implements CharStream {
rewind(lastMarker);
}
@Override
public void release(int marker) {
// unwind any other markers made after m and release m
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
* update line and charPositionInLine. If we seek backwards, just set p
*/
@Override
public void seek(int index) {
if ( index<=p ) {
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) {
if ( stop >= n ) stop = n-1;
int count = stop - start + 1;
@ -228,6 +236,7 @@ public class ANTLRStringStream implements CharStream {
this.charPositionInLine = pos;
}
@Override
public String getSourceName() {
return name;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -78,6 +78,7 @@ public class ASTIterator<T> implements Iterator<T> {
nodes.clear();
}
@Override
public boolean hasNext() {
if ( firstTime ) return root!=null;
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?
}
@Override
public T next() {
if ( firstTime ) { // initial condition
firstTime = false;
@ -132,5 +134,6 @@ public class ASTIterator<T> implements Iterator<T> {
return nodes.remove();
}
@Override
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
* sense for you.
*/
@Override
T get(int i);
/** 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
* for both parser and tree grammars. :)
*/
@Override
T LT(int k);
/** 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) {
}
@Override
public BaseAST getChild(int i) {
if ( children==null || i>=children.size() ) {
return null;
@ -76,6 +77,7 @@ public abstract class BaseAST implements AST {
return Trees.getFirstChildWithType(this, type);
}
@Override
public int getChildCount() {
if ( children==null ) return 0;
return children.size();
@ -157,6 +159,7 @@ public abstract class BaseAST implements AST {
return childIndex;
}
@Override
public AST getParent() {
return parent;
}
@ -211,6 +214,7 @@ public abstract class BaseAST implements AST {
return new ArrayList<BaseAST>();
}
@Override
public boolean isNil() {
return false;
}
@ -275,6 +279,7 @@ public abstract class BaseAST implements AST {
/** Don't use standard tree printing mechanism since ASTs can have nil
* root nodes.
*/
@Override
public String toStringTree() {
return Trees.toStringTree(this, null);
// 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 int uniqueNodeID = 1;
@Override
public List<T> createElementList() {
return new ElementList<T>(this);
}
// END v4 stuff
@Override
public T nil() {
return create(null);
}
@Override
public boolean isNil(T tree) {
return ((AST)tree).isNil();
}
@Override
public T dupTree(T tree) {
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
* ASTs.
*/
@Override
public void addChild(T t, T child) {
if ( t!=null && child!=null ) {
((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
* efficiency.
*/
@Override
public T becomeRoot(T newRoot, T oldRoot) {
//System.out.println("becomeroot new "+newRoot.toString()+" old "+oldRoot);
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 */
@Override
public T rulePostProcessing(T root) {
//System.out.println("rulePostProcessing: "+((AST)root).toStringTree());
if ( root!=null && root.isNil() ) {
@ -159,10 +166,12 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
return root;
}
@Override
public T becomeRoot(Token newRoot, T oldRoot) {
return becomeRoot(create(newRoot), oldRoot);
}
@Override
public T create(int tokenType, Token fromToken) {
WritableToken tok = createToken(fromToken);
//((ClassicToken)fromToken).setType(tokenType);
@ -170,6 +179,7 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
return create(tok);
}
@Override
public T create(int tokenType, Token fromToken, String text) {
if (fromToken == null) return create(tokenType, text);
WritableToken tok = createToken(fromToken);
@ -178,43 +188,53 @@ public abstract class BaseASTAdaptor<T extends BaseAST> implements ASTAdaptor<T>
return create(tok);
}
@Override
public T create(int tokenType, String text) {
Token fromToken = createToken(tokenType, text);
return create(fromToken);
}
@Override
public int getType(T t) {
return t.getType();
}
@Override
public void setType(T t, int type) {
throw new UnsupportedOperationException("don't know enough about AST node");
}
@Override
public String getText(T t) {
return t.getText();
}
@Override
public void setText(T t, String text) {
throw new UnsupportedOperationException("don't know enough about AST node");
}
@Override
public T getChild(T t, int i) {
return (T)t.getChild(i);
}
@Override
public void setChild(T t, int i, T child) {
t.setChild(i, child);
}
@Override
public T deleteChild(T t, int i) {
return (T)t.deleteChild(i);
}
@Override
public int getChildCount(T t) {
return ((BaseAST)t).getChildCount();
}
@Override
public int getUniqueID(T node) {
if ( treeToUniqueIDMap==null ) {
treeToUniqueIDMap = new HashMap();

View File

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

View File

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