use of spoon.reflect.declaration.CtModuleRequirement in project spoon by INRIA.
the class JDTTreeBuilderHelper method createModule.
/**
* Creates an entire object CtModule from a module declaration.
* @return a CtModule
*/
CtModule createModule(ModuleDeclaration moduleDeclaration) {
CtModule module = jdtTreeBuilder.getFactory().Module().getOrCreate(new String(moduleDeclaration.moduleName));
module.setIsOpenModule(moduleDeclaration.isOpen());
jdtTreeBuilder.getContextBuilder().enter(module, moduleDeclaration);
if (moduleDeclaration.requires != null && moduleDeclaration.requires.length > 0) {
List<CtModuleRequirement> moduleRequirements = new ArrayList<>();
for (RequiresStatement requiresStatement : moduleDeclaration.requires) {
moduleRequirements.add(this.createModuleRequirement(requiresStatement));
}
module.setRequiredModules(moduleRequirements);
}
if (moduleDeclaration.exports != null && moduleDeclaration.exports.length > 0) {
List<CtPackageExport> moduleExports = new ArrayList<>();
for (ExportsStatement exportsStatement : moduleDeclaration.exports) {
moduleExports.add(this.createModuleExport(exportsStatement));
}
module.setExportedPackages(moduleExports);
}
if (moduleDeclaration.opens != null && moduleDeclaration.opens.length > 0) {
List<CtPackageExport> moduleOpens = new ArrayList<>();
for (OpensStatement opensStatement : moduleDeclaration.opens) {
moduleOpens.add(this.createModuleExport(opensStatement));
}
module.setOpenedPackages(moduleOpens);
}
if (moduleDeclaration.uses != null && moduleDeclaration.uses.length > 0) {
List<CtUsedService> consumedServices = new ArrayList<>();
for (UsesStatement consumedService : moduleDeclaration.uses) {
consumedServices.add(this.createUsedService(consumedService));
}
module.setUsedServices(consumedServices);
}
if (moduleDeclaration.services != null && moduleDeclaration.services.length > 0) {
List<CtProvidedService> moduleProvidedServices = new ArrayList<>();
for (ProvidesStatement providesStatement : moduleDeclaration.services) {
moduleProvidedServices.add(this.createModuleProvidedService(providesStatement));
}
module.setProvidedServices(moduleProvidedServices);
}
module.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(moduleDeclaration.declarationSourceStart, moduleDeclaration.declarationSourceEnd));
return module;
}
use of spoon.reflect.declaration.CtModuleRequirement in project spoon by INRIA.
the class JDTTreeBuilderHelper method createModuleRequirement.
CtModuleRequirement createModuleRequirement(RequiresStatement requiresStatement) {
int sourceStart = requiresStatement.sourceStart;
int sourceEnd = requiresStatement.sourceEnd;
CtModuleReference ctModuleReference = jdtTreeBuilder.references.getModuleReference(requiresStatement.module);
CtModuleRequirement moduleRequirement = jdtTreeBuilder.getFactory().Module().createModuleRequirement(ctModuleReference);
Set<CtModuleRequirement.RequiresModifier> modifiers = new HashSet<>();
if (requiresStatement.isStatic()) {
modifiers.add(CtModuleRequirement.RequiresModifier.STATIC);
}
if (requiresStatement.isTransitive()) {
modifiers.add(CtModuleRequirement.RequiresModifier.TRANSITIVE);
}
moduleRequirement.setRequiresModifiers(modifiers);
moduleRequirement.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
return moduleRequirement;
}
use of spoon.reflect.declaration.CtModuleRequirement in project spoon by INRIA.
the class DefaultCoreFactory method createModuleRequirement.
@Override
public CtModuleRequirement createModuleRequirement() {
CtModuleRequirement moduleRequirement = new CtModuleRequirementImpl();
moduleRequirement.setFactory(getMainFactory());
return moduleRequirement;
}
use of spoon.reflect.declaration.CtModuleRequirement 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);
}
use of spoon.reflect.declaration.CtModuleRequirement in project spoon by INRIA.
the class CtModuleImpl method setRequiredModules.
@Override
public <T extends CtModule> T setRequiredModules(List<CtModuleRequirement> requiredModules) {
if (requiredModules == null || requiredModules.isEmpty()) {
return (T) this;
}
List<CtModuleRequirement> oldRequiredModules = getRequiredModules();
getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CtRole.REQUIRED_MODULE, this.moduleDirectives, new ArrayList<>(oldRequiredModules));
this.moduleDirectives.removeAll(oldRequiredModules);
for (CtModuleRequirement moduleRequirement : requiredModules) {
this.addModuleDirective(moduleRequirement);
}
return (T) this;
}
Aggregations