Search in sources :

Example 1 with CtModuleDirective

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

the class CtModuleImpl method setModuleDirectives.

@Override
public <T extends CtModule> T setModuleDirectives(List<CtModuleDirective> moduleDirectives) {
    getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CtRole.MODULE_DIRECTIVE, this.moduleDirectives, new ArrayList<>(this.moduleDirectives));
    if (moduleDirectives == null || moduleDirectives.isEmpty()) {
        this.moduleDirectives = CtElementImpl.emptyList();
        return (T) this;
    }
    if (this.moduleDirectives == CtElementImpl.<CtModuleDirective>emptyList()) {
        this.moduleDirectives = new SortedList<>(new CtLineElementComparator());
    }
    this.moduleDirectives.clear();
    for (CtModuleDirective moduleDirective : moduleDirectives) {
        this.addModuleDirective(moduleDirective);
    }
    return (T) this;
}
Also used : CtLineElementComparator(spoon.support.comparator.CtLineElementComparator) CtModuleDirective(spoon.reflect.declaration.CtModuleDirective)

Example 2 with CtModuleDirective

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

the class TestModule method testDirectiveOrders.

@Test
public void testDirectiveOrders() {
    // contract: module directive should be ordered the same way as in the original file
    final Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.getEnvironment().setComplianceLevel(9);
    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);
    List<CtModuleDirective> moduleDirectives = module.getModuleDirectives();
    assertEquals(3, moduleDirectives.size());
    assertTrue(moduleDirectives.get(0) instanceof CtModuleRequirement);
    assertTrue(moduleDirectives.get(1) instanceof CtProvidedService);
    assertTrue(moduleDirectives.get(2) instanceof CtUsedService);
}
Also used : CtProvidedService(spoon.reflect.declaration.CtProvidedService) Launcher(spoon.Launcher) CtModuleRequirement(spoon.reflect.declaration.CtModuleRequirement) CtModule(spoon.reflect.declaration.CtModule) CtModuleDirective(spoon.reflect.declaration.CtModuleDirective) CtUsedService(spoon.reflect.declaration.CtUsedService) Test(org.junit.Test)

Example 3 with CtModuleDirective

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

the class DefaultJavaPrettyPrinter method visitCtModule.

@Override
public void visitCtModule(CtModule module) {
    enter(module);
    if (module.isOpenModule()) {
        printer.writeKeyword("open").writeSpace();
    }
    printer.writeKeyword("module").writeSpace().writeIdentifier(module.getSimpleName());
    printer.writeSpace().writeSeparator("{").incTab().writeln();
    for (CtModuleDirective moduleDirective : module.getModuleDirectives()) {
        scan(moduleDirective);
    }
    printer.decTab().writeSeparator("}");
    exit(module);
}
Also used : CtModuleDirective(spoon.reflect.declaration.CtModuleDirective)

Aggregations

CtModuleDirective (spoon.reflect.declaration.CtModuleDirective)3 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtModule (spoon.reflect.declaration.CtModule)1 CtModuleRequirement (spoon.reflect.declaration.CtModuleRequirement)1 CtProvidedService (spoon.reflect.declaration.CtProvidedService)1 CtUsedService (spoon.reflect.declaration.CtUsedService)1 CtLineElementComparator (spoon.support.comparator.CtLineElementComparator)1