From ac55cf39907cb0ca2535446c018a395967624f18 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 14 Dec 2012 09:34:20 -0600 Subject: [PATCH] Add missing generic type arguments --- tool/src/org/antlr/v4/parse/ANTLRParser.g | 5 ++++- .../org/antlr/v4/test/TestASTStructure.java | 21 +++++++------------ .../org/antlr/v4/test/TestIntervalSet.java | 1 - .../v4/test/TestTokenTypeAssignment.java | 5 ++--- .../antlr/v4/test/TestTopologicalSort.java | 20 +++++++++--------- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/tool/src/org/antlr/v4/parse/ANTLRParser.g b/tool/src/org/antlr/v4/parse/ANTLRParser.g index 3bf5a5b35..442b86bec 100644 --- a/tool/src/org/antlr/v4/parse/ANTLRParser.g +++ b/tool/src/org/antlr/v4/parse/ANTLRParser.g @@ -130,10 +130,13 @@ package org.antlr.v4.parse; import org.antlr.v4.tool.*; import org.antlr.v4.tool.ast.*; + +import java.util.ArrayDeque; +import java.util.Deque; } @members { -Stack paraphrases = new Stack(); +Deque paraphrases = new ArrayDeque(); public void grammarError(ErrorType etype, org.antlr.runtime.Token token, Object... args) { } } diff --git a/tool/test/org/antlr/v4/test/TestASTStructure.java b/tool/test/org/antlr/v4/test/TestASTStructure.java index e30bcfe3e..90662460d 100644 --- a/tool/test/org/antlr/v4/test/TestASTStructure.java +++ b/tool/test/org/antlr/v4/test/TestASTStructure.java @@ -60,26 +60,21 @@ public class TestASTStructure { throws Exception { ANTLRStringStream is = new ANTLRStringStream(input); - Class lexerClass = Class.forName(lexerClassName); - Class[] lexArgTypes = new Class[]{CharStream.class}; - Constructor lexConstructor = lexerClass.getConstructor(lexArgTypes); - Object[] lexArgs = new Object[]{is}; - TokenSource lexer = (TokenSource)lexConstructor.newInstance(lexArgs); + Class lexerClass = Class.forName(lexerClassName).asSubclass(TokenSource.class); + Constructor lexConstructor = lexerClass.getConstructor(CharStream.class); + TokenSource lexer = lexConstructor.newInstance(is); is.setLine(scriptLine); CommonTokenStream tokens = new CommonTokenStream(lexer); - Class parserClass = Class.forName(parserClassName); - Class[] parArgTypes = new Class[]{TokenStream.class}; - Constructor parConstructor = parserClass.getConstructor(parArgTypes); - Object[] parArgs = new Object[]{tokens}; - Parser parser = (Parser)parConstructor.newInstance(parArgs); + Class parserClass = Class.forName(parserClassName).asSubclass(Parser.class); + Constructor parConstructor = parserClass.getConstructor(TokenStream.class); + Parser parser = parConstructor.newInstance(tokens); // set up customized tree adaptor if necessary if ( adaptorClassName!=null ) { - parArgTypes = new Class[]{TreeAdaptor.class}; - Method m = parserClass.getMethod("setTreeAdaptor", parArgTypes); - Class adaptorClass = Class.forName(adaptorClassName); + Method m = parserClass.getMethod("setTreeAdaptor", TreeAdaptor.class); + Class adaptorClass = Class.forName(adaptorClassName).asSubclass(TreeAdaptor.class); m.invoke(parser, adaptorClass.newInstance()); } diff --git a/tool/test/org/antlr/v4/test/TestIntervalSet.java b/tool/test/org/antlr/v4/test/TestIntervalSet.java index d58bdf9d6..8e3f17437 100644 --- a/tool/test/org/antlr/v4/test/TestIntervalSet.java +++ b/tool/test/org/antlr/v4/test/TestIntervalSet.java @@ -370,7 +370,6 @@ public class TestIntervalSet extends BaseTest { s.add(50,55); s.add(5,5); String expecting = "[5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55]"; - List foo = new ArrayList(); String result = String.valueOf(s.toList()); assertEquals(result, expecting); } diff --git a/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java b/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java index 83702f892..67da8eff3 100644 --- a/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java +++ b/tool/test/org/antlr/v4/test/TestTokenTypeAssignment.java @@ -156,7 +156,7 @@ public class TestTokenTypeAssignment extends BaseTest { Grammar g = new Grammar( "grammar t;\n"+ "a : '\\n';\n"); - Set literals = g.stringLiteralToTypeMap.keySet(); + Set literals = g.stringLiteralToTypeMap.keySet(); // must store literals how they appear in the antlr grammar assertEquals("'\\n'", literals.toArray()[0]); } @@ -179,8 +179,7 @@ public class TestTokenTypeAssignment extends BaseTest { tokens.remove(tokenName); } // make sure there are not any others (other than etc...) - for (Iterator iter = tokens.iterator(); iter.hasNext();) { - String tokenName = (String) iter.next(); + for (String tokenName : tokens) { assertTrue("unexpected token name "+tokenName, g.getTokenType(tokenName) < Token.MIN_USER_TOKEN_TYPE); } diff --git a/tool/test/org/antlr/v4/test/TestTopologicalSort.java b/tool/test/org/antlr/v4/test/TestTopologicalSort.java index cf4964c53..42855dd7c 100644 --- a/tool/test/org/antlr/v4/test/TestTopologicalSort.java +++ b/tool/test/org/antlr/v4/test/TestTopologicalSort.java @@ -38,7 +38,7 @@ import java.util.List; public class TestTopologicalSort extends BaseTest { @Test public void testFairlyLargeGraph() throws Exception { - Graph g = new Graph(); + Graph g = new Graph(); g.addEdge("C", "F"); g.addEdge("C", "G"); g.addEdge("C", "A"); @@ -52,63 +52,63 @@ public class TestTopologicalSort extends BaseTest { g.addEdge("E", "F"); String expecting = "[H, F, E, D, G, A, B, C]"; - List nodes = g.sort(); + List nodes = g.sort(); String result = nodes.toString(); assertEquals(expecting, result); } @Test public void testCyclicGraph() throws Exception { - Graph g = new Graph(); + Graph g = new Graph(); g.addEdge("A", "B"); g.addEdge("B", "C"); g.addEdge("C", "A"); g.addEdge("C", "D"); String expecting = "[D, C, B, A]"; - List nodes = g.sort(); + List nodes = g.sort(); String result = nodes.toString(); assertEquals(expecting, result); } @Test public void testRepeatedEdges() throws Exception { - Graph g = new Graph(); + Graph g = new Graph(); g.addEdge("A", "B"); g.addEdge("B", "C"); g.addEdge("A", "B"); // dup g.addEdge("C", "D"); String expecting = "[D, C, B, A]"; - List nodes = g.sort(); + List nodes = g.sort(); String result = nodes.toString(); assertEquals(expecting, result); } @Test public void testSimpleTokenDependence() throws Exception { - Graph g = new Graph(); + Graph g = new Graph(); g.addEdge("Java.g4", "MyJava.tokens"); // Java feeds off manual token file g.addEdge("Java.tokens", "Java.g4"); g.addEdge("Def.g4", "Java.tokens"); // walkers feed off generated tokens g.addEdge("Ref.g4", "Java.tokens"); String expecting = "[MyJava.tokens, Java.g4, Java.tokens, Ref.g4, Def.g4]"; - List nodes = g.sort(); + List nodes = g.sort(); String result = nodes.toString(); assertEquals(expecting, result); } @Test public void testParserLexerCombo() throws Exception { - Graph g = new Graph(); + Graph g = new Graph(); g.addEdge("JavaLexer.tokens", "JavaLexer.g4"); g.addEdge("JavaParser.g4", "JavaLexer.tokens"); g.addEdge("Def.g4", "JavaLexer.tokens"); g.addEdge("Ref.g4", "JavaLexer.tokens"); String expecting = "[JavaLexer.g4, JavaLexer.tokens, JavaParser.g4, Ref.g4, Def.g4]"; - List nodes = g.sort(); + List nodes = g.sort(); String result = nodes.toString(); assertEquals(expecting, result); }