Search in sources :

Example 16 with Launcher

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());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) Launcher(spoon.Launcher) File(java.io.File) Test(org.junit.Test)

Example 17 with Launcher

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());
}
Also used : CompilationUnit(spoon.reflect.cu.CompilationUnit) CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) Test(org.junit.Test)

Example 18 with Launcher

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());
}
Also used : CtClass(spoon.reflect.declaration.CtClass) CtNewClass(spoon.reflect.code.CtNewClass) Launcher(spoon.Launcher) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtModel(spoon.reflect.CtModel) Test(org.junit.Test)

Example 19 with Launcher

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);
}
Also used : Launcher(spoon.Launcher) Test(org.junit.Test)

Example 20 with Launcher

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());
}
Also used : CtClass(spoon.reflect.declaration.CtClass) CtNewClass(spoon.reflect.code.CtNewClass) Launcher(spoon.Launcher) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtModel(spoon.reflect.CtModel) Test(org.junit.Test)

Aggregations

Launcher (spoon.Launcher)524 Test (org.junit.Test)486 Factory (spoon.reflect.factory.Factory)163 CtClass (spoon.reflect.declaration.CtClass)111 CtMethod (spoon.reflect.declaration.CtMethod)79 File (java.io.File)75 CtType (spoon.reflect.declaration.CtType)66 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)60 CtTypeReference (spoon.reflect.reference.CtTypeReference)48 SpoonModelBuilder (spoon.SpoonModelBuilder)44 ArrayList (java.util.ArrayList)43 CtAnnotation (spoon.reflect.declaration.CtAnnotation)38 CtInvocation (spoon.reflect.code.CtInvocation)32 CtElement (spoon.reflect.declaration.CtElement)27 CtPackage (spoon.reflect.declaration.CtPackage)27 FileSystemFile (spoon.support.compiler.FileSystemFile)26 CtStatement (spoon.reflect.code.CtStatement)25 CtField (spoon.reflect.declaration.CtField)24 NamedElementFilter (spoon.reflect.visitor.filter.NamedElementFilter)24 SpoonAPI (spoon.SpoonAPI)22