use of spoon.reflect.visitor.PrettyPrinter in project spoon by INRIA.
the class PrinterTest method testChangeAutoImportModeWorks.
@Test
public void testChangeAutoImportModeWorks() throws Exception {
Launcher spoon = new Launcher();
spoon.getEnvironment().setAutoImports(false);
PrettyPrinter printer = spoon.createPrettyPrinter();
spoon.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/AClass.java");
spoon.buildModel();
CtType element = spoon.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
printer.calculate(element.getPosition().getCompilationUnit(), toPrint);
String result = printer.getResult();
assertTrue("The result should not contain imports: " + result, !result.contains("import java.util.List;"));
// recreating an auto-immport printer
spoon.getEnvironment().setAutoImports(true);
printer = spoon.createPrettyPrinter();
printer.calculate(element.getPosition().getCompilationUnit(), toPrint);
result = printer.getResult();
assertTrue("The result should now contain imports: " + result, result.contains("import java.util.List;"));
}
use of spoon.reflect.visitor.PrettyPrinter in project spoon by INRIA.
the class PrinterTest method testFQNModeWriteFQNConstructorInCtVisitor.
@Test
public void testFQNModeWriteFQNConstructorInCtVisitor() {
Launcher spoon = new Launcher();
PrettyPrinter printer = spoon.createPrettyPrinter();
spoon.getEnvironment().setAutoImports(false);
spoon.addInputResource("./src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java");
spoon.buildModel();
CtType element = spoon.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
printer.calculate(element.getPosition().getCompilationUnit(), toPrint);
String result = printer.getResult();
assertTrue("The result should contain FQN for constructor: " + result, result.contains("new spoon.support.visitor.replace.ReplacementVisitor("));
assertTrue("The result should not contain reduced constructors: " + result, !result.contains("new ReplacementVisitor("));
}
use of spoon.reflect.visitor.PrettyPrinter in project spoon by INRIA.
the class PrinterTest method testAutoimportModeDontImportUselessStatic.
@Test
public void testAutoimportModeDontImportUselessStatic() {
Launcher spoon = new Launcher();
spoon.getEnvironment().setAutoImports(true);
PrettyPrinter printer = spoon.createPrettyPrinter();
spoon.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/ImportStatic.java");
spoon.buildModel();
CtType element = spoon.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
printer.calculate(element.getPosition().getCompilationUnit(), toPrint);
String result = printer.getResult();
assertTrue("The result should not contain import static: ", !result.contains("import static spoon.test.prettyprinter.testclasses.sub.Constants.READY"));
assertTrue("The result should contain import type: ", result.contains("import spoon.test.prettyprinter.testclasses.sub.Constants"));
assertTrue("The result should contain import static assertTrue: ", result.contains("import static org.junit.Assert.assertTrue;"));
assertTrue("The result should contain assertTrue(...): ", result.contains("assertTrue(\"blabla\".equals(\"toto\"));"));
assertTrue("The result should use System.out.println(Constants.READY): " + result, result.contains("System.out.println(Constants.READY);"));
}
use of spoon.reflect.visitor.PrettyPrinter in project spoon by INRIA.
the class PrinterTest method testRuleCanBeBuild.
@Test
public void testRuleCanBeBuild() {
Launcher spoon = new Launcher();
PrettyPrinter printer = spoon.createPrettyPrinter();
spoon.getEnvironment().setAutoImports(true);
String output = "./target/spoon-rule/";
spoon.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/Rule.java");
spoon.setSourceOutputDirectory(output);
spoon.run();
CtType element = spoon.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
printer.calculate(element.getPosition().getCompilationUnit(), toPrint);
String result = printer.getResult();
assertTrue("The result should contain direct this accessor for field: " + result, !result.contains("Rule.Phoneme.this.phonemeText"));
canBeBuilt(output, 7);
}
Aggregations