use of spoon.reflect.reference.CtModuleReference in project spoon by INRIA.
the class ReferenceBuilder method getModuleReference.
public CtModuleReference getModuleReference(ModuleReference moduleReference) {
String moduleName = new String(moduleReference.moduleName);
CtModule module = this.jdtTreeBuilder.getFactory().Module().getModule(moduleName);
if (module == null) {
CtModuleReference ctModuleReference = this.jdtTreeBuilder.getFactory().Core().createModuleReference();
ctModuleReference.setSimpleName(moduleName);
return ctModuleReference;
} else {
return module.getReference();
}
}
use of spoon.reflect.reference.CtModuleReference in project spoon by INRIA.
the class CtPackageExportImpl method setTargetExport.
@Override
public <T extends CtPackageExport> T setTargetExport(List<CtModuleReference> targetExports) {
getFactory().getEnvironment().getModelChangeListener().onListDeleteAll(this, CtRole.MODULE_REF, this.targets, new ArrayList<>(this.targets));
if (targetExports == null || targetExports.isEmpty()) {
this.targets = CtElementImpl.emptyList();
return (T) this;
}
if (this.targets == CtElementImpl.<CtModuleReference>emptyList()) {
this.targets = new ArrayList<>();
}
this.targets.clear();
for (CtModuleReference targetExport : targetExports) {
this.addTargetExport(targetExport);
}
return (T) this;
}
use of spoon.reflect.reference.CtModuleReference 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