use of spoon.Launcher in project spoon by INRIA.
the class ImportTest method testAccessType.
@Test
public void testAccessType() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "-i", "./src/test/java/spoon/test/imports/testclasses", "--with-imports" });
launcher.buildModel();
final CtClass<ImportTest> aInnerClass = launcher.getFactory().Class().get(ClientClass.class.getName() + "$InnerClass");
final CtClass<ImportTest> aSuperClass = launcher.getFactory().Class().get("spoon.test.imports.testclasses.internal.SuperClass");
assertEquals(ClientClass.class.getName() + "$InnerClass", aInnerClass.getQualifiedName());
// Check that access type of ClientClass$InnerClass in package protected class is still ClientClass
assertEquals(ClientClass.class.getName(), aInnerClass.getReference().getAccessType().getQualifiedName());
final CtTypeReference<?> innerClassProtectedByGetSuperClass = aInnerClass.getSuperclass();
final CtTypeReference<?> innerClassProtectedByQualifiedName = launcher.getFactory().Class().get("spoon.test.imports.testclasses.internal.SuperClass$InnerClassProtected").getReference();
assertEquals("spoon.test.imports.testclasses.internal.SuperClass$InnerClassProtected", innerClassProtectedByGetSuperClass.getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.SuperClass$InnerClassProtected", innerClassProtectedByQualifiedName.getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.ChildClass", innerClassProtectedByGetSuperClass.getAccessType().getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.SuperClass", innerClassProtectedByQualifiedName.getAccessType().getQualifiedName());
assertEquals("spoon.test.imports.testclasses.internal.ChildClass.InnerClassProtected", innerClassProtectedByGetSuperClass.toString());
assertEquals("spoon.test.imports.testclasses.internal.SuperClass.InnerClassProtected", innerClassProtectedByQualifiedName.toString());
}
use of spoon.Launcher in project spoon by INRIA.
the class ImportTest method testShouldNotCreateAutoreference.
@Test
public void testShouldNotCreateAutoreference() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(false);
String outputDir = "./target/spooned-autoref";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses/ShouldNotAutoreference.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.run();
PrettyPrinter prettyPrinter = launcher.createPrettyPrinter();
CtType element = launcher.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
prettyPrinter.calculate(element.getPosition().getCompilationUnit(), toPrint);
String output = prettyPrinter.getResult();
assertTrue("The file should not contain a static import for NOFOLLOW_LINKS", !output.contains("import static java.nio.file.LinkOption.NOFOLLOW_LINKS;"));
canBeBuilt(outputDir, 7);
}
use of spoon.Launcher in project spoon by INRIA.
the class ImportTest method testmportInCu.
@Test
public void testmportInCu() throws Exception {
// contract: auto-import works for compilation units with multiple classes
String[] options = { "--output-type", "compilationunits", "--output", "target/testmportInCu", "--with-imports" };
String path = "spoon/test/prettyprinter/testclasses/A.java";
final Launcher launcher = new Launcher();
launcher.setArgs(options);
launcher.addInputResource("./src/test/java/" + path);
launcher.run();
File output = new File("target/testmportInCu/" + path);
String code = IOUtils.toString(new FileReader(output));
// the ArrayList is imported and used in short mode
assertTrue(code.contains("import java.util.ArrayList"));
// no fully qualified usage
assertFalse(code.contains("new java.util.ArrayList"));
// sanity check: the actual code
assertTrue(code.contains("ArrayList<String> list = new ArrayList<>()"));
// cleaning
output.delete();
}
use of spoon.Launcher in project spoon by INRIA.
the class FieldAccessTest method testGetReference.
@Test
public void testGetReference() throws Exception {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setShouldCompile(true);
launcher.setArgs(new String[] { "--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/");
launcher.getEnvironment().setAutoImports(true);
launcher.run();
final CtClass<B> aClass = launcher.getFactory().Class().get(B.class);
// now static fields are used with the name of the parent class
assertEquals("A.myField", aClass.getElements(new TypeFilter<>(CtFieldWrite.class)).get(0).toString());
assertEquals("finalField", aClass.getElements(new TypeFilter<>(CtFieldWrite.class)).get(1).toString());
}
use of spoon.Launcher 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());
}
Aggregations