forked from jasder/antlr
Add missing generic type arguments
This commit is contained in:
parent
51dadaf7e8
commit
ac55cf3990
|
@ -130,10 +130,13 @@ package org.antlr.v4.parse;
|
||||||
|
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
import org.antlr.v4.tool.ast.*;
|
import org.antlr.v4.tool.ast.*;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
}
|
}
|
||||||
|
|
||||||
@members {
|
@members {
|
||||||
Stack paraphrases = new Stack();
|
Deque<String> paraphrases = new ArrayDeque<String>();
|
||||||
public void grammarError(ErrorType etype, org.antlr.runtime.Token token, Object... args) { }
|
public void grammarError(ErrorType etype, org.antlr.runtime.Token token, Object... args) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,26 +60,21 @@ public class TestASTStructure {
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
ANTLRStringStream is = new ANTLRStringStream(input);
|
ANTLRStringStream is = new ANTLRStringStream(input);
|
||||||
Class lexerClass = Class.forName(lexerClassName);
|
Class<? extends TokenSource> lexerClass = Class.forName(lexerClassName).asSubclass(TokenSource.class);
|
||||||
Class[] lexArgTypes = new Class[]{CharStream.class};
|
Constructor<? extends TokenSource> lexConstructor = lexerClass.getConstructor(CharStream.class);
|
||||||
Constructor lexConstructor = lexerClass.getConstructor(lexArgTypes);
|
TokenSource lexer = lexConstructor.newInstance(is);
|
||||||
Object[] lexArgs = new Object[]{is};
|
|
||||||
TokenSource lexer = (TokenSource)lexConstructor.newInstance(lexArgs);
|
|
||||||
is.setLine(scriptLine);
|
is.setLine(scriptLine);
|
||||||
|
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
|
|
||||||
Class parserClass = Class.forName(parserClassName);
|
Class<? extends Parser> parserClass = Class.forName(parserClassName).asSubclass(Parser.class);
|
||||||
Class[] parArgTypes = new Class[]{TokenStream.class};
|
Constructor<? extends Parser> parConstructor = parserClass.getConstructor(TokenStream.class);
|
||||||
Constructor parConstructor = parserClass.getConstructor(parArgTypes);
|
Parser parser = parConstructor.newInstance(tokens);
|
||||||
Object[] parArgs = new Object[]{tokens};
|
|
||||||
Parser parser = (Parser)parConstructor.newInstance(parArgs);
|
|
||||||
|
|
||||||
// set up customized tree adaptor if necessary
|
// set up customized tree adaptor if necessary
|
||||||
if ( adaptorClassName!=null ) {
|
if ( adaptorClassName!=null ) {
|
||||||
parArgTypes = new Class[]{TreeAdaptor.class};
|
Method m = parserClass.getMethod("setTreeAdaptor", TreeAdaptor.class);
|
||||||
Method m = parserClass.getMethod("setTreeAdaptor", parArgTypes);
|
Class<? extends TreeAdaptor> adaptorClass = Class.forName(adaptorClassName).asSubclass(TreeAdaptor.class);
|
||||||
Class adaptorClass = Class.forName(adaptorClassName);
|
|
||||||
m.invoke(parser, adaptorClass.newInstance());
|
m.invoke(parser, adaptorClass.newInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,7 +370,6 @@ public class TestIntervalSet extends BaseTest {
|
||||||
s.add(50,55);
|
s.add(50,55);
|
||||||
s.add(5,5);
|
s.add(5,5);
|
||||||
String expecting = "[5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55]";
|
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());
|
String result = String.valueOf(s.toList());
|
||||||
assertEquals(result, expecting);
|
assertEquals(result, expecting);
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class TestTokenTypeAssignment extends BaseTest {
|
||||||
Grammar g = new Grammar(
|
Grammar g = new Grammar(
|
||||||
"grammar t;\n"+
|
"grammar t;\n"+
|
||||||
"a : '\\n';\n");
|
"a : '\\n';\n");
|
||||||
Set literals = g.stringLiteralToTypeMap.keySet();
|
Set<?> literals = g.stringLiteralToTypeMap.keySet();
|
||||||
// must store literals how they appear in the antlr grammar
|
// must store literals how they appear in the antlr grammar
|
||||||
assertEquals("'\\n'", literals.toArray()[0]);
|
assertEquals("'\\n'", literals.toArray()[0]);
|
||||||
}
|
}
|
||||||
|
@ -179,8 +179,7 @@ public class TestTokenTypeAssignment extends BaseTest {
|
||||||
tokens.remove(tokenName);
|
tokens.remove(tokenName);
|
||||||
}
|
}
|
||||||
// make sure there are not any others (other than <EOF> etc...)
|
// make sure there are not any others (other than <EOF> etc...)
|
||||||
for (Iterator iter = tokens.iterator(); iter.hasNext();) {
|
for (String tokenName : tokens) {
|
||||||
String tokenName = (String) iter.next();
|
|
||||||
assertTrue("unexpected token name "+tokenName,
|
assertTrue("unexpected token name "+tokenName,
|
||||||
g.getTokenType(tokenName) < Token.MIN_USER_TOKEN_TYPE);
|
g.getTokenType(tokenName) < Token.MIN_USER_TOKEN_TYPE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
||||||
public class TestTopologicalSort extends BaseTest {
|
public class TestTopologicalSort extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFairlyLargeGraph() throws Exception {
|
public void testFairlyLargeGraph() throws Exception {
|
||||||
Graph g = new Graph();
|
Graph<String> g = new Graph<String>();
|
||||||
g.addEdge("C", "F");
|
g.addEdge("C", "F");
|
||||||
g.addEdge("C", "G");
|
g.addEdge("C", "G");
|
||||||
g.addEdge("C", "A");
|
g.addEdge("C", "A");
|
||||||
|
@ -52,63 +52,63 @@ public class TestTopologicalSort extends BaseTest {
|
||||||
g.addEdge("E", "F");
|
g.addEdge("E", "F");
|
||||||
|
|
||||||
String expecting = "[H, F, E, D, G, A, B, C]";
|
String expecting = "[H, F, E, D, G, A, B, C]";
|
||||||
List nodes = g.sort();
|
List<String> nodes = g.sort();
|
||||||
String result = nodes.toString();
|
String result = nodes.toString();
|
||||||
assertEquals(expecting, result);
|
assertEquals(expecting, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCyclicGraph() throws Exception {
|
public void testCyclicGraph() throws Exception {
|
||||||
Graph g = new Graph();
|
Graph<String> g = new Graph<String>();
|
||||||
g.addEdge("A", "B");
|
g.addEdge("A", "B");
|
||||||
g.addEdge("B", "C");
|
g.addEdge("B", "C");
|
||||||
g.addEdge("C", "A");
|
g.addEdge("C", "A");
|
||||||
g.addEdge("C", "D");
|
g.addEdge("C", "D");
|
||||||
|
|
||||||
String expecting = "[D, C, B, A]";
|
String expecting = "[D, C, B, A]";
|
||||||
List nodes = g.sort();
|
List<String> nodes = g.sort();
|
||||||
String result = nodes.toString();
|
String result = nodes.toString();
|
||||||
assertEquals(expecting, result);
|
assertEquals(expecting, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatedEdges() throws Exception {
|
public void testRepeatedEdges() throws Exception {
|
||||||
Graph g = new Graph();
|
Graph<String> g = new Graph<String>();
|
||||||
g.addEdge("A", "B");
|
g.addEdge("A", "B");
|
||||||
g.addEdge("B", "C");
|
g.addEdge("B", "C");
|
||||||
g.addEdge("A", "B"); // dup
|
g.addEdge("A", "B"); // dup
|
||||||
g.addEdge("C", "D");
|
g.addEdge("C", "D");
|
||||||
|
|
||||||
String expecting = "[D, C, B, A]";
|
String expecting = "[D, C, B, A]";
|
||||||
List nodes = g.sort();
|
List<String> nodes = g.sort();
|
||||||
String result = nodes.toString();
|
String result = nodes.toString();
|
||||||
assertEquals(expecting, result);
|
assertEquals(expecting, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleTokenDependence() throws Exception {
|
public void testSimpleTokenDependence() throws Exception {
|
||||||
Graph g = new Graph();
|
Graph<String> g = new Graph<String>();
|
||||||
g.addEdge("Java.g4", "MyJava.tokens"); // Java feeds off manual token file
|
g.addEdge("Java.g4", "MyJava.tokens"); // Java feeds off manual token file
|
||||||
g.addEdge("Java.tokens", "Java.g4");
|
g.addEdge("Java.tokens", "Java.g4");
|
||||||
g.addEdge("Def.g4", "Java.tokens"); // walkers feed off generated tokens
|
g.addEdge("Def.g4", "Java.tokens"); // walkers feed off generated tokens
|
||||||
g.addEdge("Ref.g4", "Java.tokens");
|
g.addEdge("Ref.g4", "Java.tokens");
|
||||||
|
|
||||||
String expecting = "[MyJava.tokens, Java.g4, Java.tokens, Ref.g4, Def.g4]";
|
String expecting = "[MyJava.tokens, Java.g4, Java.tokens, Ref.g4, Def.g4]";
|
||||||
List nodes = g.sort();
|
List<String> nodes = g.sort();
|
||||||
String result = nodes.toString();
|
String result = nodes.toString();
|
||||||
assertEquals(expecting, result);
|
assertEquals(expecting, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParserLexerCombo() throws Exception {
|
public void testParserLexerCombo() throws Exception {
|
||||||
Graph g = new Graph();
|
Graph<String> g = new Graph<String>();
|
||||||
g.addEdge("JavaLexer.tokens", "JavaLexer.g4");
|
g.addEdge("JavaLexer.tokens", "JavaLexer.g4");
|
||||||
g.addEdge("JavaParser.g4", "JavaLexer.tokens");
|
g.addEdge("JavaParser.g4", "JavaLexer.tokens");
|
||||||
g.addEdge("Def.g4", "JavaLexer.tokens");
|
g.addEdge("Def.g4", "JavaLexer.tokens");
|
||||||
g.addEdge("Ref.g4", "JavaLexer.tokens");
|
g.addEdge("Ref.g4", "JavaLexer.tokens");
|
||||||
|
|
||||||
String expecting = "[JavaLexer.g4, JavaLexer.tokens, JavaParser.g4, Ref.g4, Def.g4]";
|
String expecting = "[JavaLexer.g4, JavaLexer.tokens, JavaParser.g4, Ref.g4, Def.g4]";
|
||||||
List nodes = g.sort();
|
List<String> nodes = g.sort();
|
||||||
String result = nodes.toString();
|
String result = nodes.toString();
|
||||||
assertEquals(expecting, result);
|
assertEquals(expecting, result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue