use of spoon.reflect.visitor.DefaultJavaPrettyPrinter in project dspot by STAMP-project.
the class DSpotUtils method printCtTypeToGivenDirectory.
public static void printCtTypeToGivenDirectory(CtType<?> type, File directory) {
Factory factory = type.getFactory();
Environment env = factory.getEnvironment();
env.setAutoImports(true);
env.setCommentEnabled(withComment);
JavaOutputProcessor processor = new JavaOutputProcessor(new DefaultJavaPrettyPrinter(env));
processor.setFactory(factory);
processor.setOutputDirectory(directory);
processor.createJavaFile(type);
env.setAutoImports(false);
}
use of spoon.reflect.visitor.DefaultJavaPrettyPrinter in project spoon by INRIA.
the class FieldAccessTest method testFieldAccessWithoutAnyImport.
@Test
public void testFieldAccessWithoutAnyImport() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/Kuu.java");
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/Mole.java");
launcher.run();
final CtType<Kuu> aType = launcher.getFactory().Type().get(Kuu.class);
final DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(aType.getFactory().getEnvironment());
assertEquals(0, printer.computeImports(aType).size());
assertEquals("spoon.test.fieldaccesses.testclasses.Mole.Delicious delicious", aType.getMethodsByName("m").get(0).getParameters().get(0).toString());
}
use of spoon.reflect.visitor.DefaultJavaPrettyPrinter in project spoon by INRIA.
the class CtReferenceImpl method toString.
@Override
public String toString() {
DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(getFactory().getEnvironment());
printer.scan(this);
return printer.toString();
}
use of spoon.reflect.visitor.DefaultJavaPrettyPrinter in project spoon by INRIA.
the class DefaultPrettyPrinterTest method importsFromMultipleTypesSupported.
@Test
public void importsFromMultipleTypesSupported() {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/prettyprinter/testclasses/A.java");
launcher.run();
Environment env = launcher.getEnvironment();
env.setAutoImports(true);
DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(env);
printer.calculate(null, Arrays.asList(launcher.getFactory().Class().get("spoon.test.prettyprinter.testclasses.A"), launcher.getFactory().Class().get("spoon.test.prettyprinter.testclasses.B")));
assertTrue(printer.getResult().contains("import java.util.ArrayList;"));
}
use of spoon.reflect.visitor.DefaultJavaPrettyPrinter in project spoon by INRIA.
the class LinesTest method testPrettyPrinterWithLines.
@Test
public void testPrettyPrinterWithLines() throws Exception {
for (CtType<?> t : factory.Type().getAll()) {
if (t.isTopLevel()) {
// System.out.println("calculate " + t.getSimpleName());
DefaultJavaPrettyPrinter pp = new DefaultJavaPrettyPrinter(factory.getEnvironment());
pp.calculate(t.getPosition().getCompilationUnit(), t.getPosition().getCompilationUnit().getDeclaredTypes());
// System.out.println(pp.getResult().toString());
}
}
assertEquals(0, factory.getEnvironment().getWarningCount());
assertEquals(0, factory.getEnvironment().getErrorCount());
// contract: in line preserve mode, toString is not prefixed or suffixed by newlines
String meth = factory.Type().get("spoon.test.prettyprinter.Validation").getMethodsByName("isIdentifier").get(0).toString();
// the added linebreaks due to line preservation are removed
assertFalse(Pattern.compile("^\\s", Pattern.DOTALL).asPredicate().test(meth.toString()));
}
Aggregations