use of spoon.reflect.visitor.ElementPrinterHelper in project spoon by INRIA.
the class PrinterTest method testListPrinter.
@Test
public void testListPrinter() {
Launcher spoon = new Launcher();
DefaultJavaPrettyPrinter pp = (DefaultJavaPrettyPrinter) spoon.createPrettyPrinter();
PrinterHelper ph = new PrinterHelper(spoon.getEnvironment());
TokenWriter tw = new DefaultTokenWriter(ph);
pp.setPrinterTokenWriter(tw);
ElementPrinterHelper elementPrinterHelper = pp.getElementPrinterHelper();
String[] listString = new String[] { "un", "deux", "trois" };
try (ListPrinter listPrinter = elementPrinterHelper.createListPrinter(true, "start", true, true, "next", true, true, "end")) {
for (String s : listString) {
listPrinter.printSeparatorIfAppropriate();
tw.writeIdentifier(s);
}
}
String expectedResult = " start un next deux next trois end";
assertEquals(expectedResult, pp.toString());
}
Aggregations