Search in sources :

Example 1 with CtPackageExport

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

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

the class JDTTreeBuilderHelper method createModuleExport.

CtPackageExport createModuleExport(ExportsStatement exportsStatement) {
    String packageName = new String(exportsStatement.pkgName);
    int sourceStart = exportsStatement.sourceStart;
    int sourceEnd = exportsStatement.sourceEnd;
    CtPackageReference ctPackageReference = jdtTreeBuilder.references.getPackageReference(packageName);
    CtPackageExport moduleExport = jdtTreeBuilder.getFactory().Module().createPackageExport(ctPackageReference);
    if (exportsStatement.targets != null && exportsStatement.targets.length > 0) {
        List<CtModuleReference> moduleReferences = new ArrayList<>();
        for (ModuleReference moduleReference : exportsStatement.targets) {
            moduleReferences.add(this.jdtTreeBuilder.references.getModuleReference(moduleReference));
        }
        moduleExport.setTargetExport(moduleReferences);
    }
    moduleExport.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
    return moduleExport;
}
Also used : CtPackageExport(spoon.reflect.declaration.CtPackageExport) CtPackageReference(spoon.reflect.reference.CtPackageReference) ModuleReference(org.eclipse.jdt.internal.compiler.ast.ModuleReference) CtModuleReference(spoon.reflect.reference.CtModuleReference) CtModuleReference(spoon.reflect.reference.CtModuleReference) ArrayList(java.util.ArrayList)

Example 3 with CtPackageExport

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

the class CtModuleImpl method setOpenedPackages.

@Override
public <T extends CtModule> T setOpenedPackages(List<CtPackageExport> openedPackages) {
    if (openedPackages == null || openedPackages.isEmpty()) {
        return (T) this;
    }
    List<CtPackageExport> oldOpenedPackages = getOpenedPackages();
    getFactory().getEnvironment().getModelChangeListener().onListDelete(this, CtRole.OPENED_PACKAGE, this.moduleDirectives, new ArrayList<>(oldOpenedPackages));
    this.moduleDirectives.removeAll(oldOpenedPackages);
    for (CtPackageExport exportedPackage : openedPackages) {
        exportedPackage.setOpenedPackage(true);
        this.addModuleDirective(exportedPackage);
    }
    return (T) this;
}
Also used : CtPackageExport(spoon.reflect.declaration.CtPackageExport)

Example 4 with CtPackageExport

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

the class DefaultCoreFactory method createPackageExport.

@Override
public CtPackageExport createPackageExport() {
    CtPackageExport moduleExport = new CtPackageExportImpl();
    moduleExport.setFactory(getMainFactory());
    return moduleExport;
}
Also used : CtPackageExportImpl(spoon.support.reflect.declaration.CtPackageExportImpl) CtPackageExport(spoon.reflect.declaration.CtPackageExport)

Example 5 with CtPackageExport

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

the class JDTTreeBuilderHelper method createModuleExport.

CtPackageExport createModuleExport(OpensStatement opensStatement) {
    String packageName = new String(opensStatement.pkgName);
    int sourceStart = opensStatement.sourceStart;
    int sourceEnd = opensStatement.sourceEnd;
    CtPackageReference ctPackageReference = jdtTreeBuilder.references.getPackageReference(packageName);
    CtPackageExport moduleExport = jdtTreeBuilder.getFactory().Module().createPackageExport(ctPackageReference);
    if (opensStatement.targets != null && opensStatement.targets.length > 0) {
        List<CtModuleReference> moduleReferences = new ArrayList<>();
        for (ModuleReference moduleReference : opensStatement.targets) {
            moduleReferences.add(this.jdtTreeBuilder.references.getModuleReference(moduleReference));
        }
        moduleExport.setTargetExport(moduleReferences);
    }
    moduleExport.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPosition(sourceStart, sourceEnd));
    return moduleExport;
}
Also used : CtPackageExport(spoon.reflect.declaration.CtPackageExport) CtPackageReference(spoon.reflect.reference.CtPackageReference) ModuleReference(org.eclipse.jdt.internal.compiler.ast.ModuleReference) CtModuleReference(spoon.reflect.reference.CtModuleReference) CtModuleReference(spoon.reflect.reference.CtModuleReference) ArrayList(java.util.ArrayList)

Aggregations

CtPackageExport (spoon.reflect.declaration.CtPackageExport)7 ArrayList (java.util.ArrayList)3 CtModuleReference (spoon.reflect.reference.CtModuleReference)3 ModuleReference (org.eclipse.jdt.internal.compiler.ast.ModuleReference)2 CtModule (spoon.reflect.declaration.CtModule)2 CtModuleRequirement (spoon.reflect.declaration.CtModuleRequirement)2 CtProvidedService (spoon.reflect.declaration.CtProvidedService)2 CtUsedService (spoon.reflect.declaration.CtUsedService)2 CtPackageReference (spoon.reflect.reference.CtPackageReference)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 UsesStatement (org.eclipse.jdt.internal.compiler.ast.UsesStatement)1 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtPackageExportImpl (spoon.support.reflect.declaration.CtPackageExportImpl)1