diff --git a/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java b/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java index c7951448a..88a842cae 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java @@ -225,5 +225,6 @@ public class ANTLRInputStream implements CharStream { return name; } + @Override public String toString() { return new String(data); } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java b/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java index 5e0b08d35..df54e9f3b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java @@ -234,6 +234,7 @@ public class BufferedTokenStream implements TokenStream { public String getSourceName() { return tokenSource.getSourceName(); } /** Grab *all* tokens from stream and return string */ + @Override public String toString() { if ( p == -1 ) setup(); fill(); diff --git a/runtime/Java/src/org/antlr/v4/runtime/CommonToken.java b/runtime/Java/src/org/antlr/v4/runtime/CommonToken.java index 7e591dcf5..a25349838 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/CommonToken.java +++ b/runtime/Java/src/org/antlr/v4/runtime/CommonToken.java @@ -195,6 +195,7 @@ public class CommonToken implements WritableToken, Serializable { return source != null ? source.getInputStream() : null; } + @Override public String toString() { String channelStr = ""; if ( channel>0 ) { diff --git a/runtime/Java/src/org/antlr/v4/runtime/TokenRewriteStream.java b/runtime/Java/src/org/antlr/v4/runtime/TokenRewriteStream.java index 372581317..37ee57cf6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/TokenRewriteStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/TokenRewriteStream.java @@ -353,6 +353,7 @@ public class TokenRewriteStream extends CommonTokenStream { return buf.toString(); } + @Override public String toString() { fill(); return toString(MIN_TOKEN_INDEX, size()-1); diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ActionTransition.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ActionTransition.java index 7ed571b58..9cd99ad52 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ActionTransition.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ActionTransition.java @@ -52,6 +52,7 @@ public class ActionTransition extends Transition { return true; // we are to be ignored by analysis 'cept for predicates } + @Override public String toString() { return "action_"+ruleIndex+":"+actionIndex; } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java index 749a0a0a1..6be33efe9 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -179,6 +179,7 @@ public class LexerATNSimulator extends ATNSimulator { } } + @Override public void reset() { dfaPrevAccept.reset(); atnPrevAccept.reset(); diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/FastQueue.java b/runtime/Java/src/org/antlr/v4/runtime/misc/FastQueue.java index 7c968fd79..d68fad6bd 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/FastQueue.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/FastQueue.java @@ -87,6 +87,7 @@ public class FastQueue { } /** Return string of current buffer contents; non-destructive */ + @Override public String toString() { StringBuilder buf = new StringBuilder(); int n = size(); diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntSet.java index 66e0abcef..cb3d2d10a 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/IntSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntSet.java @@ -62,6 +62,7 @@ public interface IntSet { boolean isNil(); + @Override boolean equals(Object obj); int getSingleElement(); @@ -73,5 +74,6 @@ public interface IntSet { List toList(); + @Override String toString(); } diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Interval.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Interval.java index 30c7e8d31..e7516df45 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Interval.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Interval.java @@ -64,6 +64,7 @@ public class Interval { return cache[a]; } + @Override public boolean equals(Object o) { if ( o==null ) { return false; @@ -139,6 +140,7 @@ public class Interval { return diff; } + @Override public String toString() { return a+".."+b; } diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/OrderedHashSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/OrderedHashSet.java index 8f3d95d9e..9eddf5f79 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/OrderedHashSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/OrderedHashSet.java @@ -124,6 +124,7 @@ public class OrderedHashSet extends LinkedHashSet { return elements.toArray(); } + @Override public String toString() { return elements.toString(); } diff --git a/tool/src/org/antlr/v4/automata/LexerATNFactory.java b/tool/src/org/antlr/v4/automata/LexerATNFactory.java index 68151aae2..4c7712db3 100644 --- a/tool/src/org/antlr/v4/automata/LexerATNFactory.java +++ b/tool/src/org/antlr/v4/automata/LexerATNFactory.java @@ -58,6 +58,7 @@ public class LexerATNFactory extends ParserATNFactory { codegenTemplates = gen.templates; } + @Override public ATN createATN() { // BUILD ALL START STATES (ONE PER MODE) Set modes = ((LexerGrammar) g).modes.keySet(); diff --git a/tool/src/org/antlr/v4/automata/ParserATNFactory.java b/tool/src/org/antlr/v4/automata/ParserATNFactory.java index f5abd4657..efc4921da 100644 --- a/tool/src/org/antlr/v4/automata/ParserATNFactory.java +++ b/tool/src/org/antlr/v4/automata/ParserATNFactory.java @@ -105,6 +105,7 @@ public class ParserATNFactory implements ATNFactory { public ParserATNFactory(@NotNull Grammar g) { this.g = g; atn = new ATN(); } + @Override public ATN createATN() { _createATN(g.rules.values()); atn.maxTokenType = g.getMaxTokenType(); @@ -133,6 +134,7 @@ public class ParserATNFactory implements ATNFactory { } } + @Override public void setCurrentRuleName(String name) { this.currentRule = g.getRule(name); } @@ -143,6 +145,7 @@ public class ParserATNFactory implements ATNFactory { } /* start->ruleblock->end */ + @Override public Handle rule(GrammarAST ruleAST, String name, Handle blk) { Rule r = g.getRule(name); RuleStartState start = atn.ruleToStartState[r.index]; @@ -157,6 +160,7 @@ public class ParserATNFactory implements ATNFactory { } /** From label A build Graph o-A->o */ + @Override public Handle tokenRef(TerminalAST node) { ATNState left = newState(node); ATNState right = newState(node); @@ -170,6 +174,7 @@ public class ParserATNFactory implements ATNFactory { * what an alt block looks like, must have extra state on left. * This handles ~A also, converted to ~{A} set. */ + @Override public Handle set(GrammarAST associatedAST, List terminals, boolean invert) { ATNState left = newState(associatedAST); ATNState right = newState(associatedAST); @@ -188,11 +193,13 @@ public class ParserATNFactory implements ATNFactory { return new Handle(left, right); } + @Override public Handle tree(GrammarAST node, List els) { throw new UnsupportedOperationException("^(...) not allowed in non-tree grammar"); } /** Not valid for non-lexers */ + @Override public Handle range(GrammarAST a, GrammarAST b) { throw new UnsupportedOperationException(); } @@ -209,6 +216,7 @@ public class ParserATNFactory implements ATNFactory { } /** For a non-lexer, just build a simple token reference atom. */ + @Override public Handle stringLiteral(TerminalAST stringLiteralAST) { return tokenRef(stringLiteralAST); } @@ -226,6 +234,7 @@ public class ParserATNFactory implements ATNFactory { * where (r) is the start of rule r and the trailing o is not linked * to from rule ref state directly (uses followState). */ + @Override public Handle ruleRef(GrammarAST node) { Handle h = _ruleRef(node); // Rule r = g.getRule(node.getText()); @@ -257,6 +266,7 @@ public class ParserATNFactory implements ATNFactory { } /** From an empty alternative build o-e->o */ + @Override public Handle epsilon(GrammarAST node) { ATNState left = newState(node); ATNState right = newState(node); @@ -269,6 +279,7 @@ public class ParserATNFactory implements ATNFactory { * predicate action. The pred is a pointer into the AST of * the SEMPRED token. */ + @Override public Handle sempred(PredAST pred) { //System.out.println("sempred: "+ pred); ATNState left = newState(pred); @@ -284,6 +295,7 @@ public class ParserATNFactory implements ATNFactory { * The action goes into ATN though it is ignored during prediction * if actionIndex < 0. Only forced are executed during prediction. */ + @Override public Handle action(ActionAST action) { //System.out.println("action: "+action); ATNState left = newState(action); @@ -320,6 +332,7 @@ public class ParserATNFactory implements ATNFactory { * * TODO: Set alt number (1..n) in the states? */ + @Override public Handle block(BlockAST blkAST, GrammarAST ebnfRoot, List alts) { if ( ebnfRoot==null ) { if ( alts.size()==1 ) { @@ -371,6 +384,7 @@ public class ParserATNFactory implements ATNFactory { } @NotNull + @Override public Handle alt(@NotNull List els) { return elemList(els); } @@ -415,6 +429,7 @@ public class ParserATNFactory implements ATNFactory { * or, if A is a block, just add an empty alt to the end of the block */ @NotNull + @Override public Handle optional(@NotNull GrammarAST optAST, @NotNull Handle blk) { // TODO: no such thing as nongreedy ()? so give error BlockStartState blkStart = (BlockStartState)blk.left; @@ -433,6 +448,7 @@ public class ParserATNFactory implements ATNFactory { * blk start. */ @NotNull + @Override public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) { PlusBlockStartState blkStart = (PlusBlockStartState)blk.left; BlockEndState blkEnd = (BlockEndState)blk.right; @@ -474,6 +490,7 @@ public class ParserATNFactory implements ATNFactory { * not the same thing as (A|B|)+. */ @NotNull + @Override public Handle star(@NotNull GrammarAST starAST, @NotNull Handle elem) { StarBlockStartState blkStart = (StarBlockStartState)elem.left; BlockEndState blkEnd = (BlockEndState)elem.right; @@ -505,6 +522,7 @@ public class ParserATNFactory implements ATNFactory { /** Build an atom with all possible values in its label */ @NotNull + @Override public Handle wildcard(GrammarAST node) { ATNState left = newState(node); ATNState right = newState(node); @@ -516,6 +534,7 @@ public class ParserATNFactory implements ATNFactory { /** Build a subrule matching ^(. .*) (any tree or node). Let's use * (^(. .+) | .) to be safe. */ + @Override public Handle wildcardTree(GrammarAST associatedAST) { throw new UnsupportedOperationException(); } void epsilon(ATNState a, @NotNull ATNState b) { @@ -572,10 +591,12 @@ public class ParserATNFactory implements ATNFactory { return n; } + @Override public Handle label(Handle t) { return t; } + @Override public Handle listLabel(Handle t) { return t; } @@ -606,6 +627,7 @@ public class ParserATNFactory implements ATNFactory { } @NotNull + @Override public ATNState newState() { return newState(null); } public boolean isGreedy(@NotNull BlockAST blkAST) { diff --git a/tool/src/org/antlr/v4/codegen/ActionTranslator.java b/tool/src/org/antlr/v4/codegen/ActionTranslator.java index 09152f438..0159dbbd7 100644 --- a/tool/src/org/antlr/v4/codegen/ActionTranslator.java +++ b/tool/src/org/antlr/v4/codegen/ActionTranslator.java @@ -130,6 +130,7 @@ public class ActionTranslator implements ActionSplitterListener { return translator.chunks; } + @Override public void attr(String expr, Token x) { gen.g.tool.log("action-translator", "attr "+x); Attribute a = node.resolver.resolveToAttribute(x.getText(), node); @@ -160,6 +161,7 @@ public class ActionTranslator implements ActionSplitterListener { } /** $x.y = expr; */ + @Override public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) { gen.g.tool.log("action-translator", "setQAttr "+x+"."+y+"="+rhs); // x has to be current rule; just set y attr @@ -167,6 +169,7 @@ public class ActionTranslator implements ActionSplitterListener { chunks.add(new SetAttr(nodeContext,y.getText(), rhsChunks)); } + @Override public void qualifiedAttr(String expr, Token x, Token y) { gen.g.tool.log("action-translator", "qattr "+x+"."+y); Attribute a = node.resolver.resolveToAttribute(x.getText(), y.getText(), node); @@ -197,6 +200,7 @@ public class ActionTranslator implements ActionSplitterListener { } } + @Override public void setAttr(String expr, Token x, Token rhs) { gen.g.tool.log("action-translator", "setAttr "+x+" "+rhs); List rhsChunks = translateActionChunk(factory,rf,rhs.getText(),node); @@ -205,12 +209,14 @@ public class ActionTranslator implements ActionSplitterListener { chunks.add(s); } + @Override public void nonLocalAttr(String expr, Token x, Token y) { gen.g.tool.log("action-translator", "nonLocalAttr "+x+"::"+y); Rule r = factory.getGrammar().getRule(x.getText()); chunks.add(new NonLocalAttrRef(nodeContext, x.getText(), y.getText(), r.index)); } + @Override public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) { gen.g.tool.log("action-translator", "setNonLocalAttr "+x+"::"+y+"="+rhs); Rule r = factory.getGrammar().getRule(x.getText()); @@ -219,9 +225,11 @@ public class ActionTranslator implements ActionSplitterListener { chunks.add(s); } + @Override public void unknownSyntax(Token t) { } + @Override public void text(String text) { chunks.add(new ActionText(nodeContext,text)); } diff --git a/tool/src/org/antlr/v4/codegen/BlankOutputModelFactory.java b/tool/src/org/antlr/v4/codegen/BlankOutputModelFactory.java index 751424469..2f92a38ba 100644 --- a/tool/src/org/antlr/v4/codegen/BlankOutputModelFactory.java +++ b/tool/src/org/antlr/v4/codegen/BlankOutputModelFactory.java @@ -37,60 +37,85 @@ import org.antlr.v4.tool.ast.*; import java.util.List; public abstract class BlankOutputModelFactory implements OutputModelFactory { + @Override public ParserFile parserFile(String fileName) { return null; } + @Override public Parser parser(ParserFile file) { return null; } + @Override public RuleFunction rule(Rule r) { return null; } + @Override public List rulePostamble(RuleFunction function, Rule r) { return null; } + @Override public LexerFile lexerFile(String fileName) { return null; } + @Override public Lexer lexer(LexerFile file) { return null; } // ALTERNATIVES / ELEMENTS + @Override public CodeBlockForAlt alternative(Alternative alt, boolean outerMost) { return null; } + @Override public CodeBlockForAlt finishAlternative(CodeBlockForAlt blk, List ops) { return blk; } + @Override public CodeBlockForAlt epsilon(Alternative alt, boolean outerMost) { return null; } + @Override public List ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; } + @Override public List tokenRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; } + @Override public List stringRef(GrammarAST ID, GrammarAST label) { return tokenRef(ID, label, null); } + @Override public List set(GrammarAST setAST, GrammarAST label, boolean invert) { return null; } + @Override public List wildcard(GrammarAST ast, GrammarAST labelAST) { return null; } // ACTIONS + @Override public List action(GrammarAST ast) { return null; } + @Override public List forcedAction(GrammarAST ast) { return null; } + @Override public List sempred(GrammarAST ast) { return null; } // BLOCKS + @Override public Choice getChoiceBlock(BlockAST blkAST, List alts, GrammarAST label) { return null; } + @Override public Choice getEBNFBlock(GrammarAST ebnfRoot, List alts) { return null; } + @Override public Choice getLL1ChoiceBlock(BlockAST blkAST, List alts) { return null; } + @Override public Choice getComplexChoiceBlock(BlockAST blkAST, List alts) { return null; } + @Override public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List alts) { return null; } + @Override public Choice getComplexEBNFBlock(GrammarAST ebnfRoot, List alts) { return null; } + @Override public List getLL1Test(IntervalSet look, GrammarAST blkAST) { return null; } + @Override public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { return false; } } diff --git a/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java b/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java index 0ced90947..f2a993f54 100644 --- a/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java +++ b/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java @@ -68,6 +68,7 @@ public abstract class DefaultOutputModelFactory extends BlankOutputModelFactory // Convenience methods @NotNull + @Override public Grammar getGrammar() { return g; } @Override diff --git a/tool/src/org/antlr/v4/codegen/ParserFactory.java b/tool/src/org/antlr/v4/codegen/ParserFactory.java index f5a405d53..92cfb4d63 100644 --- a/tool/src/org/antlr/v4/codegen/ParserFactory.java +++ b/tool/src/org/antlr/v4/codegen/ParserFactory.java @@ -44,14 +44,17 @@ import java.util.List; public class ParserFactory extends DefaultOutputModelFactory { public ParserFactory(CodeGenerator gen) { super(gen); } + @Override public ParserFile parserFile(String fileName) { return new ParserFile(this, fileName); } + @Override public Parser parser(ParserFile file) { return new Parser(this, file); } + @Override public RuleFunction rule(Rule r) { if ( r instanceof LeftRecursiveRule ) { return new LeftRecursiveRuleFunction(this, (LeftRecursiveRule)r); @@ -62,10 +65,12 @@ public class ParserFactory extends DefaultOutputModelFactory { } } + @Override public CodeBlockForAlt epsilon(Alternative alt, boolean outerMost) { return alternative(alt, outerMost); } + @Override public CodeBlockForAlt alternative(Alternative alt, boolean outerMost) { if ( outerMost ) return new CodeBlockForOuterMostAlt(this, alt); return new CodeBlockForAlt(this); @@ -77,10 +82,13 @@ public class ParserFactory extends DefaultOutputModelFactory { return blk; } + @Override public List action(GrammarAST ast) { return list(new Action(this, ast)); } + @Override public List sempred(GrammarAST ast) { return list(new SemPred(this, ast)); } + @Override public List ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { InvokeRule invokeOp = new InvokeRule(this, ID, label); // If no manual label and action refs as token/rule not label, we need to define implicit label @@ -89,6 +97,7 @@ public class ParserFactory extends DefaultOutputModelFactory { return list(invokeOp, listLabelOp); } + @Override public List tokenRef(GrammarAST ID, GrammarAST labelAST, GrammarAST args) { LabeledOp matchOp = new MatchToken(this, (TerminalAST) ID); if ( labelAST!=null ) { @@ -166,6 +175,7 @@ public class ParserFactory extends DefaultOutputModelFactory { return list(wild, listLabelOp); } + @Override public Choice getChoiceBlock(BlockAST blkAST, List alts, GrammarAST labelAST) { int decision = ((DecisionState)blkAST.atnState).decision; Choice c; @@ -191,6 +201,7 @@ public class ParserFactory extends DefaultOutputModelFactory { return c; } + @Override public Choice getEBNFBlock(GrammarAST ebnfRoot, List alts) { if (!g.tool.force_atn) { int decision; @@ -212,14 +223,17 @@ public class ParserFactory extends DefaultOutputModelFactory { return getComplexEBNFBlock(ebnfRoot, alts); } + @Override public Choice getLL1ChoiceBlock(BlockAST blkAST, List alts) { return new LL1AltBlock(this, blkAST, alts); } + @Override public Choice getComplexChoiceBlock(BlockAST blkAST, List alts) { return new AltBlock(this, blkAST, alts); } + @Override public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List alts) { int ebnf = 0; if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType(); @@ -241,6 +255,7 @@ public class ParserFactory extends DefaultOutputModelFactory { return c; } + @Override public Choice getComplexEBNFBlock(GrammarAST ebnfRoot, List alts) { int ebnf = 0; if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType(); @@ -259,10 +274,12 @@ public class ParserFactory extends DefaultOutputModelFactory { return c; } + @Override public List getLL1Test(IntervalSet look, GrammarAST blkAST) { return list(new TestSetInline(this, blkAST, look)); } + @Override public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { Alternative currentOuterMostAlt = getCurrentOuterMostAlt(); boolean actionRefsAsToken = currentOuterMostAlt.tokenRefsInActions.containsKey(ID.getText()); diff --git a/tool/src/org/antlr/v4/codegen/model/InvokeRule.java b/tool/src/org/antlr/v4/codegen/model/InvokeRule.java index 5649a138f..846eef973 100644 --- a/tool/src/org/antlr/v4/codegen/model/InvokeRule.java +++ b/tool/src/org/antlr/v4/codegen/model/InvokeRule.java @@ -91,6 +91,7 @@ public class InvokeRule extends RuleElement implements LabeledOp { } } + @Override public List getLabels() { return labels.elements(); } diff --git a/tool/src/org/antlr/v4/codegen/model/MatchToken.java b/tool/src/org/antlr/v4/codegen/model/MatchToken.java index 76b51cfa7..1ed44929a 100644 --- a/tool/src/org/antlr/v4/codegen/model/MatchToken.java +++ b/tool/src/org/antlr/v4/codegen/model/MatchToken.java @@ -57,5 +57,6 @@ public class MatchToken extends RuleElement implements LabeledOp { super(factory, ast); } + @Override public List getLabels() { return labels; } } diff --git a/tool/src/org/antlr/v4/misc/Graph.java b/tool/src/org/antlr/v4/misc/Graph.java index 90ad769e8..9077afd52 100644 --- a/tool/src/org/antlr/v4/misc/Graph.java +++ b/tool/src/org/antlr/v4/misc/Graph.java @@ -48,6 +48,7 @@ public class Graph { if ( !edges.contains(n) ) edges.add(n); } + @Override public String toString() { return payload.toString(); } } diff --git a/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java b/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java index 5888de984..eddf0f4ce 100644 --- a/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java +++ b/tool/src/org/antlr/v4/parse/GrammarASTAdaptor.java @@ -42,6 +42,7 @@ public class GrammarASTAdaptor extends CommonTreeAdaptor { public GrammarASTAdaptor() { ; } public GrammarASTAdaptor(org.antlr.runtime.CharStream input) { this.input = input; } + @Override public Object create(Token token) { return new GrammarAST(token); } @@ -66,11 +67,13 @@ public class GrammarASTAdaptor extends CommonTreeAdaptor { return t; } + @Override public Object dupNode(Object t) { if ( t==null ) return null; return ((GrammarAST)t).dupNode(); //create(((GrammarAST)t).token); } + @Override public Object errorNode(org.antlr.runtime.TokenStream input, org.antlr.runtime.Token start, org.antlr.runtime.Token stop, org.antlr.runtime.RecognitionException e) { diff --git a/tool/src/org/antlr/v4/parse/ToolANTLRParser.java b/tool/src/org/antlr/v4/parse/ToolANTLRParser.java index 9542e7909..7b06a3db6 100644 --- a/tool/src/org/antlr/v4/parse/ToolANTLRParser.java +++ b/tool/src/org/antlr/v4/parse/ToolANTLRParser.java @@ -44,6 +44,7 @@ public class ToolANTLRParser extends ANTLRParser { this.tool = tool; } + @Override public void displayRecognitionError(String[] tokenNames, RecognitionException e) { diff --git a/tool/src/org/antlr/v4/semantics/AttributeChecks.java b/tool/src/org/antlr/v4/semantics/AttributeChecks.java index ec32006ea..12e903f95 100644 --- a/tool/src/org/antlr/v4/semantics/AttributeChecks.java +++ b/tool/src/org/antlr/v4/semantics/AttributeChecks.java @@ -101,12 +101,14 @@ public class AttributeChecks implements ActionSplitterListener { // LISTENER METHODS + @Override public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) { qualifiedAttr(expr, x, y); new AttributeChecks(g, r, alt, node, rhs).examineAction(); } // $x.y + @Override public void qualifiedAttr(String expr, Token x, Token y) { if ( node.resolver.resolveToAttribute(x.getText(), y.getText(), node)==null ) { Rule rref = isolatedRuleRef(x.getText()); @@ -131,6 +133,7 @@ public class AttributeChecks implements ActionSplitterListener { } } + @Override public void setAttr(String expr, Token x, Token rhs) { if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) { errMgr.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE, @@ -139,6 +142,7 @@ public class AttributeChecks implements ActionSplitterListener { new AttributeChecks(g, r, alt, node, rhs).examineAction(); } + @Override public void attr(String expr, Token x) { if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) { if ( node.resolver.resolvesToToken(x.getText(), node) ) { @@ -157,6 +161,7 @@ public class AttributeChecks implements ActionSplitterListener { } } + @Override public void nonLocalAttr(String expr, Token x, Token y) { Rule r = g.getRule(x.getText()); if ( r==null ) { @@ -170,6 +175,7 @@ public class AttributeChecks implements ActionSplitterListener { } } + @Override public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) { Rule r = g.getRule(x.getText()); if ( r==null ) { @@ -183,11 +189,13 @@ public class AttributeChecks implements ActionSplitterListener { } } + @Override public void unknownSyntax(Token t) { errMgr.grammarError(ErrorType.INVALID_TEMPLATE_ACTION, g.fileName, t, t.getText()); } + @Override public void text(String text) { } // don't care diff --git a/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java b/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java index e29b2d915..69429294b 100644 --- a/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java +++ b/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java @@ -33,24 +33,30 @@ import org.antlr.runtime.Token; import org.antlr.v4.parse.ActionSplitterListener; public class BlankActionSplitterListener implements ActionSplitterListener { + @Override public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) { } + @Override public void qualifiedAttr(String expr, Token x, Token y) { } + @Override public void setAttr(String expr, Token x, Token rhs) { } + @Override public void attr(String expr, Token x) { } public void templateInstance(String expr) { } + @Override public void nonLocalAttr(String expr, Token x, Token y) { } + @Override public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) { } @@ -66,9 +72,11 @@ public class BlankActionSplitterListener implements ActionSplitterListener { public void templateExpr(String expr) { } + @Override public void unknownSyntax(Token t) { } + @Override public void text(String text) { } } diff --git a/tool/src/org/antlr/v4/tool/Alternative.java b/tool/src/org/antlr/v4/tool/Alternative.java index f008f1e7e..013fb1445 100644 --- a/tool/src/org/antlr/v4/tool/Alternative.java +++ b/tool/src/org/antlr/v4/tool/Alternative.java @@ -77,6 +77,7 @@ public class Alternative implements AttributeResolver { public Alternative(Rule r, int altNum) { this.rule = r; this.altNum = altNum; } + @Override public boolean resolvesToToken(String x, ActionAST node) { if ( tokenRefs.get(x)!=null ) return true; LabelElementPair anyLabelDef = getAnyLabelDef(x); @@ -84,6 +85,7 @@ public class Alternative implements AttributeResolver { return false; } + @Override public boolean resolvesToAttributeDict(String x, ActionAST node) { if ( resolvesToToken(x, node) ) return true; if ( ruleRefs.get(x)!=null ) return true; // rule ref in this alt? @@ -95,6 +97,7 @@ public class Alternative implements AttributeResolver { /** $x Attribute: rule arguments, return values, predefined rule prop. */ + @Override public Attribute resolveToAttribute(String x, ActionAST node) { return rule.resolveToAttribute(x, node); // reuse that code } @@ -102,6 +105,7 @@ public class Alternative implements AttributeResolver { /** $x.y, x can be surrounding rule, token/rule/label ref. y is visible * attr in that dictionary. Can't see args on rule refs. */ + @Override public Attribute resolveToAttribute(String x, String y, ActionAST node) { if ( rule.name.equals(x) ) { // x is this rule? return rule.resolveToAttribute(x, y, node); @@ -123,6 +127,7 @@ public class Alternative implements AttributeResolver { return null; } + @Override public boolean resolvesToLabel(String x, ActionAST node) { LabelElementPair anyLabelDef = getAnyLabelDef(x); return anyLabelDef!=null && @@ -130,6 +135,7 @@ public class Alternative implements AttributeResolver { anyLabelDef.type==LabelType.RULE_LABEL); } + @Override public boolean resolvesToListLabel(String x, ActionAST node) { LabelElementPair anyLabelDef = getAnyLabelDef(x); return anyLabelDef!=null && diff --git a/tool/src/org/antlr/v4/tool/Attribute.java b/tool/src/org/antlr/v4/tool/Attribute.java index 8bba88643..b52026771 100644 --- a/tool/src/org/antlr/v4/tool/Attribute.java +++ b/tool/src/org/antlr/v4/tool/Attribute.java @@ -57,6 +57,7 @@ public class Attribute { this.decl = decl; } + @Override public String toString() { if ( initValue!=null ) { return type+" "+name+"="+initValue; diff --git a/tool/src/org/antlr/v4/tool/AttributeDict.java b/tool/src/org/antlr/v4/tool/AttributeDict.java index 0f8432785..302a0bc31 100644 --- a/tool/src/org/antlr/v4/tool/AttributeDict.java +++ b/tool/src/org/antlr/v4/tool/AttributeDict.java @@ -106,6 +106,7 @@ public class AttributeDict { return inter; } + @Override public String toString() { return getName()+":"+attributes; } diff --git a/tool/src/org/antlr/v4/tool/DefaultToolListener.java b/tool/src/org/antlr/v4/tool/DefaultToolListener.java index d5a1db6da..f4cb365dd 100644 --- a/tool/src/org/antlr/v4/tool/DefaultToolListener.java +++ b/tool/src/org/antlr/v4/tool/DefaultToolListener.java @@ -38,6 +38,7 @@ public class DefaultToolListener implements ANTLRToolListener { public DefaultToolListener(Tool tool) { this.tool = tool; } + @Override public void info(String msg) { if (tool.errMgr.formatWantsSingleLineMessage()) { msg = msg.replaceAll("\n", " "); @@ -45,6 +46,7 @@ public class DefaultToolListener implements ANTLRToolListener { System.out.println(msg); } + @Override public void error(ANTLRMessage msg) { ST msgST = tool.errMgr.getMessageTemplate(msg); String outputMsg = msgST.render(); @@ -54,6 +56,7 @@ public class DefaultToolListener implements ANTLRToolListener { System.err.println(outputMsg); } + @Override public void warning(ANTLRMessage msg) { ST msgST = tool.errMgr.getMessageTemplate(msg); String outputMsg = msgST.render(); diff --git a/tool/src/org/antlr/v4/tool/ErrorManager.java b/tool/src/org/antlr/v4/tool/ErrorManager.java index 1d5d09ad9..e52bd52ee 100644 --- a/tool/src/org/antlr/v4/tool/ErrorManager.java +++ b/tool/src/org/antlr/v4/tool/ErrorManager.java @@ -59,18 +59,22 @@ public class ErrorManager { STErrorListener theDefaultSTListener = new STErrorListener() { + @Override public void compileTimeError(STMessage msg) { ErrorManager.internalError(msg.toString()); } + @Override public void runTimeError(STMessage msg) { ErrorManager.internalError(msg.toString()); } + @Override public void IOError(STMessage msg) { ErrorManager.internalError(msg.toString()); } + @Override public void internalError(STMessage msg) { ErrorManager.internalError(msg.toString()); } diff --git a/tool/src/org/antlr/v4/tool/Grammar.java b/tool/src/org/antlr/v4/tool/Grammar.java index 9217f85ce..bcd8510b2 100644 --- a/tool/src/org/antlr/v4/tool/Grammar.java +++ b/tool/src/org/antlr/v4/tool/Grammar.java @@ -202,7 +202,9 @@ public class Grammar implements AttributeResolver { final Grammar thiz = this; TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor()); v.visit(ast, new TreeVisitorAction() { + @Override public Object pre(Object t) { ((GrammarAST)t).g = thiz; return t; } + @Override public Object post(Object t) { return t; } }); initTokenSymbolTables(); @@ -603,21 +605,27 @@ public class Grammar implements AttributeResolver { } // no isolated attr at grammar action level + @Override public Attribute resolveToAttribute(String x, ActionAST node) { return null; } // no $x.y makes sense here + @Override public Attribute resolveToAttribute(String x, String y, ActionAST node) { return null; } + @Override public boolean resolvesToLabel(String x, ActionAST node) { return false; } + @Override public boolean resolvesToListLabel(String x, ActionAST node) { return false; } + @Override public boolean resolvesToToken(String x, ActionAST node) { return false; } + @Override public boolean resolvesToAttributeDict(String x, ActionAST node) { return false; } diff --git a/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java b/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java index 675b53daa..45b1e6ba8 100644 --- a/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java +++ b/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java @@ -84,12 +84,14 @@ public class GrammarTransformPipeline { public void expandParameterizedLoops(GrammarAST root) { TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor()); v.visit(root, new TreeVisitorAction() { + @Override public Object pre(Object t) { if ( ((GrammarAST)t).getType() == 3 ) { return expandParameterizedLoop((GrammarAST)t); } return t; } + @Override public Object post(Object t) { return t; } }); } @@ -104,7 +106,9 @@ public class GrammarTransformPipeline { // ensure each node has pointer to surrounding grammar TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor()); v.visit(tree, new TreeVisitorAction() { + @Override public Object pre(Object t) { ((GrammarAST)t).g = g; return t; } + @Override public Object post(Object t) { return t; } }); } diff --git a/tool/src/org/antlr/v4/tool/LabelElementPair.java b/tool/src/org/antlr/v4/tool/LabelElementPair.java index 38452496f..7c5184df8 100644 --- a/tool/src/org/antlr/v4/tool/LabelElementPair.java +++ b/tool/src/org/antlr/v4/tool/LabelElementPair.java @@ -66,6 +66,7 @@ public class LabelElementPair { } } + @Override public String toString() { return label.getText()+" "+type+" "+element.toString(); } diff --git a/tool/src/org/antlr/v4/tool/Rule.java b/tool/src/org/antlr/v4/tool/Rule.java index f4611a89f..ed053c49c 100644 --- a/tool/src/org/antlr/v4/tool/Rule.java +++ b/tool/src/org/antlr/v4/tool/Rule.java @@ -233,6 +233,7 @@ public class Rule implements AttributeResolver { /** $x Attribute: rule arguments, return values, predefined rule prop. */ + @Override public Attribute resolveToAttribute(String x, ActionAST node) { if ( args!=null ) { Attribute a = args.get(x); if ( a!=null ) return a; @@ -248,6 +249,7 @@ public class Rule implements AttributeResolver { } /** $x.y Attribute: x is surrounding rule, label ref (in any alts) */ + @Override public Attribute resolveToAttribute(String x, String y, ActionAST node) { if ( this.name.equals(x) ) { // x is this rule? return resolveToAttribute(y, node); @@ -265,6 +267,7 @@ public class Rule implements AttributeResolver { } + @Override public boolean resolvesToLabel(String x, ActionAST node) { LabelElementPair anyLabelDef = getAnyLabelDef(x); return anyLabelDef!=null && @@ -272,6 +275,7 @@ public class Rule implements AttributeResolver { anyLabelDef.type==LabelType.TOKEN_LABEL); } + @Override public boolean resolvesToListLabel(String x, ActionAST node) { LabelElementPair anyLabelDef = getAnyLabelDef(x); return anyLabelDef!=null && @@ -279,12 +283,14 @@ public class Rule implements AttributeResolver { anyLabelDef.type==LabelType.TOKEN_LIST_LABEL); } + @Override public boolean resolvesToToken(String x, ActionAST node) { LabelElementPair anyLabelDef = getAnyLabelDef(x); if ( anyLabelDef!=null && anyLabelDef.type==LabelType.TOKEN_LABEL ) return true; return false; } + @Override public boolean resolvesToAttributeDict(String x, ActionAST node) { if ( resolvesToToken(x, node) ) return true; if ( x.equals(name) ) return true; // $r for action in rule r, $r is a dict diff --git a/tool/src/org/antlr/v4/tool/ast/GrammarASTErrorNode.java b/tool/src/org/antlr/v4/tool/ast/GrammarASTErrorNode.java index 434d3a2fb..3f901634a 100644 --- a/tool/src/org/antlr/v4/tool/ast/GrammarASTErrorNode.java +++ b/tool/src/org/antlr/v4/tool/ast/GrammarASTErrorNode.java @@ -42,10 +42,14 @@ public class GrammarASTErrorNode extends GrammarAST { delegate = new CommonErrorNode(input,start,stop,e); } + @Override public boolean isNil() { return delegate.isNil(); } + @Override public int getType() { return delegate.getType(); } + @Override public String getText() { return delegate.getText(); } + @Override public String toString() { return delegate.toString(); } } diff --git a/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java b/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java index 9bad5fea4..6015a32fc 100644 --- a/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java +++ b/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java @@ -58,6 +58,7 @@ public class LexerInterpreter implements TokenSource { this.input = input; } + @Override public String getSourceName() { return g.name; } @Override @@ -65,18 +66,22 @@ public class LexerInterpreter implements TokenSource { // TODO: use TokenFactory } + @Override public int getCharPositionInLine() { return 0; } + @Override public int getLine() { return 0; } + @Override public CharStream getInputStream() { return input; } + @Override public Token nextToken() { // TODO: Deal with off channel tokens int start = input.index(); diff --git a/tool/test/org/antlr/v4/test/ErrorQueue.java b/tool/test/org/antlr/v4/test/ErrorQueue.java index 59f727437..d837b6543 100644 --- a/tool/test/org/antlr/v4/test/ErrorQueue.java +++ b/tool/test/org/antlr/v4/test/ErrorQueue.java @@ -43,15 +43,18 @@ public class ErrorQueue implements ANTLRToolListener { public List warnings = new ArrayList(); public List all = new ArrayList(); + @Override public void info(String msg) { infos.add(msg); } + @Override public void error(ANTLRMessage msg) { errors.add(msg); all.add(msg); } + @Override public void warning(ANTLRMessage msg) { warnings.add(msg); all.add(msg); @@ -66,6 +69,7 @@ public class ErrorQueue implements ANTLRToolListener { return all.size() + infos.size(); } + @Override public String toString() { return Utils.join(all.iterator(), "\n"); } public String toString(Tool tool) { diff --git a/tool/test/org/antlr/v4/test/TestCommonTokenStream.java b/tool/test/org/antlr/v4/test/TestCommonTokenStream.java index dd42e2bc7..6701c544f 100644 --- a/tool/test/org/antlr/v4/test/TestCommonTokenStream.java +++ b/tool/test/org/antlr/v4/test/TestCommonTokenStream.java @@ -189,16 +189,21 @@ public class TestCommonTokenStream extends BaseTest { new CommonToken(1,"\n") {{channel = Lexer.HIDDEN;}}, new CommonToken(Token.EOF,"") }; + @Override public Token nextToken() { return tokens[i++]; } + @Override public String getSourceName() { return "test"; } + @Override public int getCharPositionInLine() { return 0; } + @Override public int getLine() { return 0; } + @Override public CharStream getInputStream() { return null; }