use of spoon.reflect.declaration.CtPackageExport in project spoon by INRIA.
the class CtModuleImpl method setExportedPackages.
@Override
public <T extends CtModule> T setExportedPackages(List<CtPackageExport> exportedPackages) {
if (exportedPackages == null || exportedPackages.isEmpty()) {
return (T) this;
}
List<CtPackageExport> oldExportedPackages = getExportedPackages();
getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CtRole.EXPORTED_PACKAGE, this.moduleDirectives, new ArrayList<>(oldExportedPackages));
this.moduleDirectives.removeAll(oldExportedPackages);
for (CtPackageExport exportedPackage : exportedPackages) {
exportedPackage.setOpenedPackage(false);
this.addModuleDirective(exportedPackage);
}
return (T) this;
}
use of spoon.reflect.declaration.CtPackageExport in project spoon by INRIA.
the class TestModule method testCompleteModuleInfoContentNoClasspath.
@Test
public void testCompleteModuleInfoContentNoClasspath() {
// contract: all information of the module-info should be available through the model
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/spoon/test/module/simple_module/module-info.java");
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setComplianceLevel(9);
launcher.buildModel();
assertEquals(2, launcher.getModel().getAllModules().size());
CtModule unnamedModule = launcher.getFactory().Module().getOrCreate(CtModule.TOP_LEVEL_MODULE_NAME);
assertSame(unnamedModule, launcher.getModel().getUnnamedModule());
CtModule moduleGreetings = launcher.getFactory().Module().getOrCreate("simple_module");
assertEquals("simple_module", moduleGreetings.getSimpleName());
assertEquals(7, moduleGreetings.getModuleDirectives().size());
List<CtModuleRequirement> requiredModules = moduleGreetings.getRequiredModules();
assertEquals(1, requiredModules.size());
CtModuleRequirement moduleRequirement = requiredModules.get(0);
assertEquals("java.logging", moduleRequirement.getModuleReference().getSimpleName());
assertTrue(moduleRequirement.getRequiresModifiers().contains(CtModuleRequirement.RequiresModifier.TRANSITIVE));
List<CtPackageExport> moduleExports = moduleGreetings.getExportedPackages();
assertEquals(1, moduleExports.size());
assertEquals("com.greetings.pkg", moduleExports.get(0).getPackageReference().getQualifiedName());
assertEquals(2, moduleExports.get(0).getTargetExport().size());
for (CtModuleReference target : moduleExports.get(0).getTargetExport()) {
if (!target.getSimpleName().equals("com.other.module") && !target.getSimpleName().equals("com.second.module")) {
fail();
}
}
List<CtPackageExport> moduleOpened = moduleGreetings.getOpenedPackages();
assertEquals(2, moduleOpened.size());
CtPackageExport openedFirst = moduleOpened.get(0);
CtPackageExport openedSecond = moduleOpened.get(1);
assertEquals("com.greetings.otherpkg", openedFirst.getPackageReference().getSimpleName());
assertTrue(openedFirst.getTargetExport().isEmpty());
assertEquals("com.greetings.openpkg", openedSecond.getPackageReference().getSimpleName());
assertEquals(1, openedSecond.getTargetExport().size());
assertEquals("com.third.module", openedSecond.getTargetExport().iterator().next().getSimpleName());
List<CtUsedService> consumedService = moduleGreetings.getUsedServices();
assertEquals(1, consumedService.size());
assertEquals("com.greetings.pkg.ConsumedService", consumedService.get(0).getServiceType().getQualifiedName());
List<CtProvidedService> providedServices = moduleGreetings.getProvidedServices();
assertEquals(2, providedServices.size());
CtProvidedService providedService1 = providedServices.get(0);
CtProvidedService providedService2 = providedServices.get(1);
assertEquals("com.greetings.pkg.ConsumedService", providedService1.getServiceType().getQualifiedName());
assertEquals(2, providedService1.getImplementationTypes().size());
assertEquals("com.greetings.pkg.ProvidedClass1", providedService1.getImplementationTypes().get(0).getQualifiedName());
assertEquals("com.greetings.otherpkg.ProvidedClass2", providedService1.getImplementationTypes().get(1).getQualifiedName());
assertEquals("java.logging.Service", providedService2.getServiceType().getQualifiedName());
assertEquals(1, providedService2.getImplementationTypes().size());
assertEquals("com.greetings.logging.Logger", providedService2.getImplementationTypes().get(0).getQualifiedName());
}
Aggregations