Example usage for org.objectweb.asm ModuleVisitor visitExport

List of usage examples for org.objectweb.asm ModuleVisitor visitExport

Introduction

In this page you can find the example usage for org.objectweb.asm ModuleVisitor visitExport.

Prototype

public void visitExport(final String packaze, final int access, final String... modules) 

Source Link

Document

Visit an exported package of the current module.

Usage

From source file:ModuleInfoGenerator.java

License:Open Source License

public static void main(String[] args) throws Exception {
    File dest = new File(args[0]);
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V9, Opcodes.ACC_MODULE, "module-info", null, null, null);
    ModuleVisitor mv = cw.visitModule("org.joml", 0, args[1]);
    mv.visitRequire("java.base", ACC_MANDATED, "9");
    mv.visitRequire("jdk.unsupported", ACC_STATIC_PHASE, null);
    mv.visitExport("org/joml", 0, (String[]) null);
    mv.visitExport("org/joml/sampling", 0, (String[]) null);
    mv.visitEnd();/*from ww  w.  j  a va 2  s . c o m*/
    cw.visitEnd();
    FileOutputStream fos = new FileOutputStream(new File(dest, "module-info.class"));
    fos.write(cw.toByteArray());
    fos.close();
}

From source file:org.moditect.internal.compiler.ModuleInfoCompiler.java

License:Apache License

public static byte[] compileModuleInfo(ModuleDeclaration module, String mainClass, String version) {
    ClassWriter classWriter = new ClassWriter(0);
    classWriter.visit(V9, ACC_MODULE, "module-info", null, null, null);

    int moduleAccess = module.isOpen() ? ACC_SYNTHETIC | ACC_OPEN : ACC_SYNTHETIC;
    ModuleVisitor mv = classWriter.visitModule(module.getNameAsString(), moduleAccess, version);

    if (mainClass != null) {
        mv.visitMainClass(getNameForBinary(mainClass));
    }// ww w  .j a  v  a2  s  .  co m

    for (ModuleRequiresStmt requires : module.getNodesByType(ModuleRequiresStmt.class)) {
        mv.visitRequire(requires.getName().asString(), requiresModifiersAsInt(requires.getModifiers()), null);
    }

    for (ModuleExportsStmt export : module.getNodesByType(ModuleExportsStmt.class)) {
        mv.visitExport(getNameForBinary(export.getNameAsString()), 0,
                export.getModuleNames().stream().map(Name::toString).toArray(String[]::new));
    }

    for (ModuleProvidesStmt provides : module.getNodesByType(ModuleProvidesStmt.class)) {
        mv.visitProvide(getNameForBinary(provides.getType()), provides.getWithTypes().stream()
                .map(ModuleInfoCompiler::getNameForBinary).toArray(String[]::new));
    }

    for (ModuleUsesStmt uses : module.getNodesByType(ModuleUsesStmt.class)) {
        mv.visitUse(getNameForBinary(uses.getType()));
    }

    for (ModuleOpensStmt opens : module.getNodesByType(ModuleOpensStmt.class)) {
        mv.visitOpen(getNameForBinary(opens.getNameAsString()), 0,
                opens.getModuleNames().stream().map(Name::toString).toArray(String[]::new));
    }

    mv.visitRequire("java.base", ACC_MANDATED, null);
    mv.visitEnd();

    classWriter.visitEnd();

    return classWriter.toByteArray();
}