Search in sources :

Example 16 with CtModule

use of spoon.reflect.declaration.CtModule in project spoon by INRIA.

the class TestModule method testGetModuleAfterChangingItsName.

@Test
public void testGetModuleAfterChangingItsName() {
    // contract: a module should be always available through ModuleFactory even after its name changed
    final Launcher launcher = new Launcher();
    CtModule module = launcher.getFactory().Module().getOrCreate("myModule");
    module.setSimpleName("newName");
    CtModule moduleNewName = launcher.getFactory().Module().getOrCreate("newName");
    assertSame(module, moduleNewName);
}
Also used : Launcher(spoon.Launcher) CtModule(spoon.reflect.declaration.CtModule) Test(org.junit.Test)

Example 17 with CtModule

use of spoon.reflect.declaration.CtModule in project spoon by INRIA.

the class TestModule method testMultipleModulesAndParents.

@Ignore
@Test
public void testMultipleModulesAndParents() {
    // contract: Spoon is able to build a model with multiple modules
    final Launcher launcher = new Launcher();
    launcher.getEnvironment().setComplianceLevel(9);
    // launcher.addModulePath("./src/test/resources/spoon/test/module/code-multiple-modules/foo");
    // launcher.addModulePath("./src/test/resources/spoon/test/module/code-multiple-modules/bar");
    launcher.addInputResource(MODULE_RESOURCES_PATH + "/code-multiple-modules");
    launcher.run();
    assertEquals(3, launcher.getModel().getAllModules().size());
    CtType barclass = launcher.getFactory().Type().get("packbar.BarClass");
    assertNotNull(barclass);
    assertTrue(barclass.getParent() instanceof CtPackage);
    CtPackage packBar = (CtPackage) barclass.getParent();
    assertTrue(packBar.getParent() instanceof CtModule);
}
Also used : CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) CtPackage(spoon.reflect.declaration.CtPackage) CtModule(spoon.reflect.declaration.CtModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with CtModule

use of spoon.reflect.declaration.CtModule in project spoon by INRIA.

the class TestModule method testModuleInfoWithComments.

@Test
public void testModuleInfoWithComments() {
    // contract: documentation on module-info elements should be managed
    final Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.getEnvironment().setComplianceLevel(9);
    launcher.getEnvironment().setCommentEnabled(true);
    launcher.addInputResource(MODULE_RESOURCES_PATH + "/module_with_comments/module-info.java");
    launcher.buildModel();
    assertEquals(2, launcher.getModel().getAllModules().size());
    CtModule module = launcher.getFactory().Module().getModule("module_with_comments");
    assertNotNull(module);
    assertTrue(module.isOpenModule());
    List<CtComment> comments = module.getComments();
    assertEquals(1, comments.size());
    CtComment comment = comments.get(0);
    assertEquals("This is the main module of the application", comment.getContent());
    assertEquals(CtComment.CommentType.JAVADOC, comment.getCommentType());
    assertEquals(3, module.getModuleDirectives().size());
    CtModuleRequirement moduleRequirement = module.getRequiredModules().get(0);
    comments = moduleRequirement.getComments();
    assertEquals(1, comments.size());
    comment = comments.get(0);
    assertEquals("this is needed for logging stuff", comment.getContent());
    assertEquals(CtComment.CommentType.INLINE, comment.getCommentType());
    CtProvidedService providedService = module.getProvidedServices().get(0);
    comments = providedService.getComments();
    assertEquals(1, comments.size());
    comment = comments.get(0);
    assertEquals("A specific implementation", comment.getContent());
    assertEquals(CtComment.CommentType.JAVADOC, comment.getCommentType());
    CtUsedService usedService = module.getUsedServices().get(0);
    comments = usedService.getComments();
    assertEquals(1, comments.size());
    comment = comments.get(0);
    assertEquals("A simple implementation", comment.getContent());
    assertEquals(CtComment.CommentType.BLOCK, comment.getCommentType());
}
Also used : CtComment(spoon.reflect.code.CtComment) CtProvidedService(spoon.reflect.declaration.CtProvidedService) Launcher(spoon.Launcher) CtModuleRequirement(spoon.reflect.declaration.CtModuleRequirement) CtModule(spoon.reflect.declaration.CtModule) CtUsedService(spoon.reflect.declaration.CtUsedService) Test(org.junit.Test)

Aggregations

CtModule (spoon.reflect.declaration.CtModule)18 Test (org.junit.Test)9 Launcher (spoon.Launcher)9 File (java.io.File)5 CtModuleRequirement (spoon.reflect.declaration.CtModuleRequirement)4 CtPackage (spoon.reflect.declaration.CtPackage)4 CtProvidedService (spoon.reflect.declaration.CtProvidedService)4 CtType (spoon.reflect.declaration.CtType)4 CtUsedService (spoon.reflect.declaration.CtUsedService)4 CompilationUnit (spoon.reflect.cu.CompilationUnit)3 CtElement (spoon.reflect.declaration.CtElement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SpoonException (spoon.SpoonException)2 CtPackageExport (spoon.reflect.declaration.CtPackageExport)2 CtModuleReference (spoon.reflect.reference.CtModuleReference)2 OutputDestinationHandler (spoon.support.OutputDestinationHandler)2 Iterator (java.util.Iterator)1 ExportsStatement (org.eclipse.jdt.internal.compiler.ast.ExportsStatement)1 OpensStatement (org.eclipse.jdt.internal.compiler.ast.OpensStatement)1