use of org.snt.inmemantlr.GenericParserToGo in project inmemantlr by julianthome.
the class TestGenericParserToGo method testParser.
@Test
public void testParser() {
File gfile = new File(TestGenericParserToGo.class.getClassLoader().getResource("inmemantlr/Java.g4").getFile());
File cfile = new File(TestGenericParserToGo.class.getClassLoader().getResource("inmemantlr/HelloWorld.java").getFile());
ParseTree pt = new GenericParserToGo(gfile).parse(cfile, "compilationUnit");
Assertions.assertEquals(pt.getNodes().size(), 60);
}
use of org.snt.inmemantlr.GenericParserToGo in project inmemantlr by julianthome.
the class TestParseTreeInjection method testInjection.
@Test
public void testInjection() {
File gfile = new File(TestGenericParserToGo.class.getClassLoader().getResource("inmemantlr/Java.g4").getFile());
File cfile = new File(TestGenericParserToGo.class.getClassLoader().getResource("inmemantlr/HelloWorld.java").getFile());
GenericParserToGo g4go = new GenericParserToGo(gfile);
ParseTree pt = g4go.parse(cfile, "compilationUnit");
LOGGER.debug(pt.toDot());
InjectionPointDetector ipdb = new InjectionPointDetector() {
@Override
public ParseTreeNode detect(ParseTree t) {
return t.getNodes().stream().filter(n -> n.getRule().equals("block")).findFirst().orElse(null);
}
@Override
public Position getPosition() {
return Position.BEFORE;
}
};
InjectionPointDetector ipda = new InjectionPointDetector() {
@Override
public ParseTreeNode detect(ParseTree t) {
return t.getNodes().stream().filter(n -> n.getRule().equals("block")).findFirst().orElse(null);
}
@Override
public Position getPosition() {
return Position.AFTER;
}
};
ParseTree inj = g4go.parse("int x = 0;", "blockStatement");
try {
ParseTreeManipulator.INTANCE.inject(pt, ipdb, inj);
ParseTreeManipulator.INTANCE.inject(pt, ipda, inj);
} catch (InjectionException e) {
Assertions.assertTrue(false);
LOGGER.error(e.getMessage());
}
Assertions.assertEquals(pt.getNodes().size(), 94);
}
Aggregations