Search in sources :

Example 1 with CtProvidedService

use of spoon.reflect.declaration.CtProvidedService 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;
}
Also used : OpensStatement(org.eclipse.jdt.internal.compiler.ast.OpensStatement) CtProvidedService(spoon.reflect.declaration.CtProvidedService) RequiresStatement(org.eclipse.jdt.internal.compiler.ast.RequiresStatement) ArrayList(java.util.ArrayList) CtModuleRequirement(spoon.reflect.declaration.CtModuleRequirement) CtModule(spoon.reflect.declaration.CtModule) CtUsedService(spoon.reflect.declaration.CtUsedService) ProvidesStatement(org.eclipse.jdt.internal.compiler.ast.ProvidesStatement) CtPackageExport(spoon.reflect.declaration.CtPackageExport) UsesStatement(org.eclipse.jdt.internal.compiler.ast.UsesStatement) ExportsStatement(org.eclipse.jdt.internal.compiler.ast.ExportsStatement)

Example 2 with CtProvidedService

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

the class JDTTreeBuilderHelper method createModuleProvidedService.

CtProvidedService createModuleProvidedService(ProvidesStatement providesStatement) {
    int sourceStart = providesStatement.sourceStart;
    int sourceEnd = providesStatement.sourceEnd;
    CtTypeReference provideService = this.jdtTreeBuilder.references.getTypeReference(providesStatement.serviceInterface);
    List<CtTypeReference> implementations = new ArrayList<>();
    for (TypeReference typeReference : providesStatement.implementations) {
        implementations.add(this.jdtTreeBuilder.references.getTypeReference(typeReference));
    }
    CtProvidedService providedService = this.jdtTreeBuilder.getFactory().Module().createProvidedService(provideService);
    providedService.setImplementationTypes(implementations);
    providedService.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
    return providedService;
}
Also used : CtProvidedService(spoon.reflect.declaration.CtProvidedService) CtTypeReference(spoon.reflect.reference.CtTypeReference) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) CtArrayTypeReference(spoon.reflect.reference.CtArrayTypeReference) UnionTypeReference(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference) CtTypeReference(spoon.reflect.reference.CtTypeReference)

Example 3 with CtProvidedService

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

the class DefaultCoreFactory method createProvidedService.

@Override
public CtProvidedService createProvidedService() {
    CtProvidedService moduleProvidedService = new CtProvidedServiceImpl();
    moduleProvidedService.setFactory(getMainFactory());
    return moduleProvidedService;
}
Also used : CtProvidedServiceImpl(spoon.support.reflect.declaration.CtProvidedServiceImpl) CtProvidedService(spoon.reflect.declaration.CtProvidedService)

Example 4 with CtProvidedService

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

the class CtModuleImpl method setProvidedServices.

@Override
public <T extends CtModule> T setProvidedServices(List<CtProvidedService> providedServices) {
    if (providedServices == null || providedServices.isEmpty()) {
        return (T) this;
    }
    List<CtProvidedService> oldProvidedServices = getProvidedServices();
    getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CtRole.PROVIDED_SERVICE, this.moduleDirectives, new ArrayList<>(oldProvidedServices));
    this.moduleDirectives.removeAll(oldProvidedServices);
    for (CtProvidedService providedService : providedServices) {
        this.addModuleDirective(providedService);
    }
    return (T) this;
}
Also used : CtProvidedService(spoon.reflect.declaration.CtProvidedService)

Example 5 with CtProvidedService

use of spoon.reflect.declaration.CtProvidedService 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)

Aggregations

CtProvidedService (spoon.reflect.declaration.CtProvidedService)7 CtModule (spoon.reflect.declaration.CtModule)4 CtModuleRequirement (spoon.reflect.declaration.CtModuleRequirement)4 CtUsedService (spoon.reflect.declaration.CtUsedService)4 Test (org.junit.Test)3 Launcher (spoon.Launcher)3 ArrayList (java.util.ArrayList)2 CtPackageExport (spoon.reflect.declaration.CtPackageExport)2 ExportsStatement (org.eclipse.jdt.internal.compiler.ast.ExportsStatement)1 OpensStatement (org.eclipse.jdt.internal.compiler.ast.OpensStatement)1 ProvidesStatement (org.eclipse.jdt.internal.compiler.ast.ProvidesStatement)1 RequiresStatement (org.eclipse.jdt.internal.compiler.ast.RequiresStatement)1 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)1 UnionTypeReference (org.eclipse.jdt.internal.compiler.ast.UnionTypeReference)1 UsesStatement (org.eclipse.jdt.internal.compiler.ast.UsesStatement)1 CtComment (spoon.reflect.code.CtComment)1 CtModuleDirective (spoon.reflect.declaration.CtModuleDirective)1 CtArrayTypeReference (spoon.reflect.reference.CtArrayTypeReference)1 CtModuleReference (spoon.reflect.reference.CtModuleReference)1 CtTypeReference (spoon.reflect.reference.CtTypeReference)1