Search in sources :

Example 1 with ListPrinter

use of spoon.reflect.visitor.ListPrinter 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());
}
Also used : ElementPrinterHelper(spoon.reflect.visitor.ElementPrinterHelper) DefaultTokenWriter(spoon.reflect.visitor.DefaultTokenWriter) TokenWriter(spoon.reflect.visitor.TokenWriter) Launcher(spoon.Launcher) DefaultJavaPrettyPrinter(spoon.reflect.visitor.DefaultJavaPrettyPrinter) DefaultTokenWriter(spoon.reflect.visitor.DefaultTokenWriter) ListPrinter(spoon.reflect.visitor.ListPrinter) ElementPrinterHelper(spoon.reflect.visitor.ElementPrinterHelper) PrinterHelper(spoon.reflect.visitor.PrinterHelper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 DefaultJavaPrettyPrinter (spoon.reflect.visitor.DefaultJavaPrettyPrinter)1 DefaultTokenWriter (spoon.reflect.visitor.DefaultTokenWriter)1 ElementPrinterHelper (spoon.reflect.visitor.ElementPrinterHelper)1 ListPrinter (spoon.reflect.visitor.ListPrinter)1 PrinterHelper (spoon.reflect.visitor.PrinterHelper)1 TokenWriter (spoon.reflect.visitor.TokenWriter)1