Search in sources :

Example 1 with CtModuleReference

use of spoon.reflect.reference.CtModuleReference 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;
}
Also used : CtModuleReference(spoon.reflect.reference.CtModuleReference) CtModuleRequirement(spoon.reflect.declaration.CtModuleRequirement) HashSet(java.util.HashSet)

Example 2 with CtModuleReference

use of spoon.reflect.reference.CtModuleReference 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 CtModuleReference

use of spoon.reflect.reference.CtModuleReference in project spoon by INRIA.

the class DefaultJavaPrettyPrinter method visitCtPackageExport.

@Override
public void visitCtPackageExport(CtPackageExport moduleExport) {
    if (moduleExport.isOpenedPackage()) {
        printer.writeKeyword("opens");
    } else {
        printer.writeKeyword("exports");
    }
    printer.writeSpace();
    visitCtPackageReference(moduleExport.getPackageReference());
    if (!moduleExport.getTargetExport().isEmpty()) {
        try (ListPrinter lp = this.elementPrinterHelper.createListPrinter(false, " to", true, false, ",", true, false, null)) {
            for (CtModuleReference moduleReference : moduleExport.getTargetExport()) {
                lp.printSeparatorIfAppropriate();
                scan(moduleReference);
            }
        }
    }
    printer.writeSeparator(";").writeln();
}
Also used : CtModuleReference(spoon.reflect.reference.CtModuleReference)

Example 4 with CtModuleReference

use of spoon.reflect.reference.CtModuleReference in project spoon by INRIA.

the class DefaultCoreFactory method createModuleReference.

@Override
public CtModuleReference createModuleReference() {
    CtModuleReference moduleReference = new CtModuleReferenceImpl();
    moduleReference.setFactory(getMainFactory());
    return moduleReference;
}
Also used : CtModuleReferenceImpl(spoon.support.reflect.reference.CtModuleReferenceImpl) CtModuleReference(spoon.reflect.reference.CtModuleReference)

Example 5 with CtModuleReference

use of spoon.reflect.reference.CtModuleReference 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

CtModuleReference (spoon.reflect.reference.CtModuleReference)8 CtPackageExport (spoon.reflect.declaration.CtPackageExport)3 ArrayList (java.util.ArrayList)2 ModuleReference (org.eclipse.jdt.internal.compiler.ast.ModuleReference)2 CtModule (spoon.reflect.declaration.CtModule)2 CtModuleRequirement (spoon.reflect.declaration.CtModuleRequirement)2 CtPackageReference (spoon.reflect.reference.CtPackageReference)2 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtProvidedService (spoon.reflect.declaration.CtProvidedService)1 CtUsedService (spoon.reflect.declaration.CtUsedService)1 CtModuleReferenceImpl (spoon.support.reflect.reference.CtModuleReferenceImpl)1