use of spoon.Launcher in project spoon by INRIA.
the class GetBinaryFilesTest method testSingleBinary.
@Test
public void testSingleBinary() {
final String input = "./src/test/resources/compilation/compilation-tests/IBar.java";
final Launcher launcher = new Launcher();
launcher.addInputResource(input);
launcher.setBinaryOutputDirectory(tmpFolder.getRoot());
launcher.buildModel();
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.FILES);
final Map<String, CompilationUnit> cus = launcher.getFactory().CompilationUnit().getMap();
assertEquals(1, cus.size());
final List<File> binaries = cus.values().iterator().next().getBinaryFiles();
assertEquals(1, binaries.size());
assertEquals("IBar.class", binaries.get(0).getName());
assertTrue(binaries.get(0).isFile());
}
use of spoon.Launcher in project spoon by INRIA.
the class TestCompilationUnit method testGetUnitTypeWorksWithDeclaredType.
@Test
public void testGetUnitTypeWorksWithDeclaredType() {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/api/testclasses/Bar.java");
launcher.buildModel();
CtType type = launcher.getFactory().Type().get(Bar.class);
CompilationUnit compilationUnit = type.getPosition().getCompilationUnit();
assertEquals(CompilationUnit.UNIT_TYPE.TYPE_DECLARATION, compilationUnit.getUnitType());
}
use of spoon.Launcher in project spoon by INRIA.
the class CtClassTest method testCloneAnonymousClassInvocationWithAutoimports.
@Test
public void testCloneAnonymousClassInvocationWithAutoimports() {
// contract: after cloning an anonymous class invocation, we still should be able to print it, when using autoimport
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/ctClass/testclasses/AnonymousClass.java");
launcher.getEnvironment().setAutoImports(true);
launcher.buildModel();
CtModel model = launcher.getModel();
CtNewClass newClassInvocation = launcher.getModel().getElements(new TypeFilter<CtNewClass>(CtNewClass.class)).get(0);
CtNewClass newClassInvocationCloned = newClassInvocation.clone();
CtClass anonymousClass = newClassInvocation.getAnonymousClass();
CtClass anonymousClassCloned = newClassInvocationCloned.getAnonymousClass();
// The test stops failing if we set the parent below
// newClassInvocationCloned.setParent(launcher.getFactory().Class().get(AnonymousClass.class));
assertEquals(0, anonymousClass.getAllFields().size());
assertEquals(0, anonymousClassCloned.getAllFields().size());
assertTrue(newClassInvocation.toString().length() > 0);
assertTrue(newClassInvocationCloned.toString().length() > 0);
assertEquals(newClassInvocation.toString(), newClassInvocationCloned.toString());
}
use of spoon.Launcher in project spoon by INRIA.
the class CtClassTest method testParentOfTheEnclosingClassOfStaticClass.
@Test
public void testParentOfTheEnclosingClassOfStaticClass() throws Exception {
// contract: When we have a static class which extends a superclass in the classpath,
// the enclosing class don't have a superclass. This is probably a bug in JDT but good
// luck to report a bug about noclasspath in their bugtracker. :)
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/noclasspath/InvariantChecker.java");
launcher.addInputResource("./src/test/resources/noclasspath/FileIO.java");
launcher.addInputResource("./src/test/resources/noclasspath/Daikon.java");
launcher.setSourceOutputDirectory("./target/class");
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Object> aClass = launcher.getFactory().Class().get("daikon.tools.InvariantChecker");
final CtType<?> staticClass = aClass.getNestedType("InvariantCheckProcessor");
assertNotNull(staticClass);
assertEquals("InvariantCheckProcessor", staticClass.getSimpleName());
assertNotNull(staticClass.getSuperclass());
assertEquals("daikon.FileIO$Processor", staticClass.getSuperclass().getQualifiedName());
assertNull(aClass.getSuperclass());
canBeBuilt("./target/class", 8, true);
}
use of spoon.Launcher in project spoon by INRIA.
the class CtClassTest method testCloneAnonymousClassInvocation.
@Test
public void testCloneAnonymousClassInvocation() {
// contract: after cloning an anonymous class invocation, we still should be able to print it, when not using autoimport
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/ctClass/testclasses/AnonymousClass.java");
launcher.getEnvironment().setAutoImports(false);
launcher.buildModel();
CtModel model = launcher.getModel();
CtNewClass newClassInvocation = launcher.getModel().getElements(new TypeFilter<CtNewClass>(CtNewClass.class)).get(0);
CtNewClass newClassInvocationCloned = newClassInvocation.clone();
CtClass anonymousClass = newClassInvocation.getAnonymousClass();
CtClass anonymousClassCloned = newClassInvocationCloned.getAnonymousClass();
// The test stops failing if we set the parent below
// newClassInvocationCloned.setParent(launcher.getFactory().Class().get(AnonymousClass.class));
assertEquals(0, anonymousClass.getAllFields().size());
assertEquals(0, anonymousClassCloned.getAllFields().size());
assertTrue(newClassInvocation.toString().length() > 0);
assertTrue(newClassInvocationCloned.toString().length() > 0);
assertEquals(newClassInvocation.toString(), newClassInvocationCloned.toString());
}
Aggregations