Java Code Examples for org.objectweb.asm.ModuleVisitor#visitExport()

The following examples show how to use org.objectweb.asm.ModuleVisitor#visitExport() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASMContentHandler.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void end(final String element) {
  boolean exports = "exports".equals(element);
  boolean opens = "opens".equals(element);
  boolean provides = "provides".equals(element);
  if (exports | opens | provides) {
    @SuppressWarnings("unchecked")
    ArrayList<String> list = (ArrayList<String>) pop();
    int access = (Integer) pop();
    String name = (String) pop();
    String[] tos = null;
    if (!list.isEmpty()) {
      tos = list.toArray(new String[list.size()]);
    }
    ModuleVisitor mv = (ModuleVisitor) peek();
    if (exports) {
      mv.visitExport(name, access, tos);
    } else {
      if (opens) {
        mv.visitOpen(name, access, tos);
      } else {
        mv.visitProvide(name, tos);
      }
    }
  } else if ("module".equals(element)) {
    ((ModuleVisitor) pop()).visitEnd();
  }
}
 
Example 2
Source File: ClassWriterTest.java    From turbine with Apache License 2.0 5 votes vote down vote up
@Test
public void module() throws Exception {

  org.objectweb.asm.ClassWriter cw = new org.objectweb.asm.ClassWriter(0);

  cw.visit(53, /* access= */ 53, "module-info", null, null, null);

  ModuleVisitor mv = cw.visitModule("mod", Opcodes.ACC_OPEN, "mod-ver");

  mv.visitRequire("r1", Opcodes.ACC_TRANSITIVE, "r1-ver");
  mv.visitRequire("r2", Opcodes.ACC_STATIC_PHASE, "r2-ver");
  mv.visitRequire("r3", Opcodes.ACC_STATIC_PHASE | Opcodes.ACC_TRANSITIVE, "r3-ver");

  mv.visitExport("e1", Opcodes.ACC_SYNTHETIC, "e1m1", "e1m2", "e1m3");
  mv.visitExport("e2", Opcodes.ACC_MANDATED, "e2m1", "e2m2");
  mv.visitExport("e3", /* access= */ 0, "e3m1");

  mv.visitOpen("o1", Opcodes.ACC_SYNTHETIC, "o1m1", "o1m2", "o1m3");
  mv.visitOpen("o2", Opcodes.ACC_MANDATED, "o2m1", "o2m2");
  mv.visitOpen("o3", /* access= */ 0, "o3m1");

  mv.visitUse("u1");
  mv.visitUse("u2");
  mv.visitUse("u3");
  mv.visitUse("u4");

  mv.visitProvide("p1", "p1i1", "p1i2");
  mv.visitProvide("p2", "p2i1", "p2i2", "p2i3");

  byte[] inputBytes = cw.toByteArray();
  byte[] outputBytes = ClassWriter.writeClass(ClassReader.read("module-info", inputBytes));

  assertThat(AsmUtils.textify(inputBytes, /* skipDebug= */ true))
      .isEqualTo(AsmUtils.textify(outputBytes, /* skipDebug= */ true));

  // test a round trip
  outputBytes = ClassWriter.writeClass(ClassReader.read("module-info", outputBytes));
  assertThat(AsmUtils.textify(inputBytes, /* skipDebug= */ true))
      .isEqualTo(AsmUtils.textify(outputBytes, /* skipDebug= */ true));
}
 
Example 3
Source File: ModuleInfoGenerator.java    From JOML with MIT License 5 votes vote down vote up
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();
    cw.visitEnd();
    FileOutputStream fos = new FileOutputStream(new File(dest, "module-info.class"));
    fos.write(cw.toByteArray());
    fos.close();
}
 
Example 4
Source File: ModuleExportNode.java    From Cafebabe with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Makes the given module visitor visit this export declaration.
 *
 * @param moduleVisitor
 *          a module visitor.
 */
public void accept(final ModuleVisitor moduleVisitor) {
	moduleVisitor.visitExport(packaze, access, modules == null ? null : modules.toArray(new String[0]));
}
 
Example 5
Source File: ModuleExportNode.java    From Concurnas with MIT License 2 votes vote down vote up
/**
 * Makes the given module visitor visit this export declaration.
 *
 * @param moduleVisitor a module visitor.
 */
public void accept(final ModuleVisitor moduleVisitor) {
  moduleVisitor.visitExport(
      packaze, access, modules == null ? null : modules.toArray(new String[0]));
}
 
Example 6
Source File: ModuleExportNode.java    From JByteMod-Beta with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Makes the given module visitor visit this export declaration.
 * 
 * @param mv
 *          a module visitor.
 */
public void accept(final ModuleVisitor mv) {
  mv.visitExport(packaze, access, (modules == null) ? null : modules.toArray(new String[0]));
}
 
Example 7
Source File: ModuleOpenNode.java    From JByteMod-Beta with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Makes the given module visitor visit this open declaration.
 * 
 * @param mv
 *          a module visitor.
 */
public void accept(final ModuleVisitor mv) {
  mv.visitExport(packaze, access, (modules == null) ? null : modules.toArray(new String[0]));
}
 
Example 8
Source File: ModuleExportNode.java    From JReFrameworker with MIT License 2 votes vote down vote up
/**
 * Makes the given module visitor visit this export declaration.
 *
 * @param moduleVisitor a module visitor.
 */
public void accept(final ModuleVisitor moduleVisitor) {
  moduleVisitor.visitExport(
      packaze, access, modules == null ? null : modules.toArray(new String[0]));
}
 
Example 9
Source File: ModuleExportNode.java    From JReFrameworker with MIT License 2 votes vote down vote up
/**
 * Makes the given module visitor visit this export declaration.
 *
 * @param moduleVisitor a module visitor.
 */
public void accept(final ModuleVisitor moduleVisitor) {
  moduleVisitor.visitExport(
      packaze, access, modules == null ? null : modules.toArray(new String[0]));
}