org.objectweb.asm.ModuleVisitor Java Examples

The following examples show how to use org.objectweb.asm.ModuleVisitor. 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: ModuleNode.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * Makes the given class visitor visit this module.
 *
 * @param classVisitor a class visitor.
 */
public void accept(final ClassVisitor classVisitor) {
  ModuleVisitor moduleVisitor = classVisitor.visitModule(name, access, version);
  if (moduleVisitor == null) {
    return;
  }
  if (mainClass != null) {
    moduleVisitor.visitMainClass(mainClass);
  }
  if (packages != null) {
    for (int i = 0, n = packages.size(); i < n; i++) {
      moduleVisitor.visitPackage(packages.get(i));
    }
  }
  if (requires != null) {
    for (int i = 0, n = requires.size(); i < n; i++) {
      requires.get(i).accept(moduleVisitor);
    }
  }
  if (exports != null) {
    for (int i = 0, n = exports.size(); i < n; i++) {
      exports.get(i).accept(moduleVisitor);
    }
  }
  if (opens != null) {
    for (int i = 0, n = opens.size(); i < n; i++) {
      opens.get(i).accept(moduleVisitor);
    }
  }
  if (uses != null) {
    for (int i = 0, n = uses.size(); i < n; i++) {
      moduleVisitor.visitUse(uses.get(i));
    }
  }
  if (provides != null) {
    for (int i = 0, n = provides.size(); i < n; i++) {
      provides.get(i).accept(moduleVisitor);
    }
  }
}
 
Example #2
Source File: ModuleNode.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
public void accept(final ClassVisitor cv) {
  ModuleVisitor mv = cv.visitModule(name, access, version);
  if (mv == null) {
    return;
  }
  if (mainClass != null) {
    mv.visitMainClass(mainClass);
  }
  if (packages != null) {
    for (int i = 0; i < packages.size(); i++) {
      mv.visitPackage(packages.get(i));
    }
  }

  if (requires != null) {
    for (int i = 0; i < requires.size(); i++) {
      requires.get(i).accept(mv);
    }
  }
  if (exports != null) {
    for (int i = 0; i < exports.size(); i++) {
      exports.get(i).accept(mv);
    }
  }
  if (opens != null) {
    for (int i = 0; i < opens.size(); i++) {
      opens.get(i).accept(mv);
    }
  }
  if (uses != null) {
    for (int i = 0; i < uses.size(); i++) {
      mv.visitUse(uses.get(i));
    }
  }
  if (provides != null) {
    for (int i = 0; i < provides.size(); i++) {
      provides.get(i).accept(mv);
    }
  }
}
 
Example #3
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 #4
Source File: SAXClassAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  AttributesImpl att = new AttributesImpl();
  att.addAttribute("", "name", "name", "", name);
  StringBuilder sb = new StringBuilder();
  appendAccess(access | ACCESS_MODULE, sb);
  att.addAttribute("", "access", "access", "", sb.toString());
  if (version != null) {
    att.addAttribute("", "version", "version", "", encode(version));
  }
  sa.addStart("module", att);
  return new SAXModuleAdapter(sa);
}
 
Example #5
Source File: CheckClassAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ModuleVisitor visitModule(String name, int access, String version) {
  checkState();
  if (module) {
    throw new IllegalStateException("visitModule can be called only once.");
  }
  module = true;
  if (name == null) {
    throw new IllegalArgumentException("Illegal module name (null)");
  }
  checkAccess(access, Opcodes.ACC_OPEN | Opcodes.ACC_SYNTHETIC);
  return new CheckModuleAdapter(super.visitModule(name, access, version), (access & Opcodes.ACC_OPEN) != 0);
}
 
Example #6
Source File: CheckClassAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  checkState();
  if (visitModuleCalled) {
    throw new IllegalStateException("visitModule can be called only once.");
  }
  visitModuleCalled = true;
  checkFullyQualifiedName(this.version, name, "module name");
  checkAccess(access, Opcodes.ACC_OPEN | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_MANDATED);
  CheckModuleAdapter checkModuleAdapter =
      new CheckModuleAdapter(
          api, super.visitModule(name, access, version), (access & Opcodes.ACC_OPEN) != 0);
  checkModuleAdapter.classVersion = this.version;
  return checkModuleAdapter;
}
 
Example #7
Source File: ModuleNode.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * Makes the given class visitor visit this module.
 *
 * @param classVisitor a class visitor.
 */
public void accept(final ClassVisitor classVisitor) {
  ModuleVisitor moduleVisitor = classVisitor.visitModule(name, access, version);
  if (moduleVisitor == null) {
    return;
  }
  if (mainClass != null) {
    moduleVisitor.visitMainClass(mainClass);
  }
  if (packages != null) {
    for (int i = 0, n = packages.size(); i < n; i++) {
      moduleVisitor.visitPackage(packages.get(i));
    }
  }
  if (requires != null) {
    for (int i = 0, n = requires.size(); i < n; i++) {
      requires.get(i).accept(moduleVisitor);
    }
  }
  if (exports != null) {
    for (int i = 0, n = exports.size(); i < n; i++) {
      exports.get(i).accept(moduleVisitor);
    }
  }
  if (opens != null) {
    for (int i = 0, n = opens.size(); i < n; i++) {
      opens.get(i).accept(moduleVisitor);
    }
  }
  if (uses != null) {
    for (int i = 0, n = uses.size(); i < n; i++) {
      moduleVisitor.visitUse(uses.get(i));
    }
  }
  if (provides != null) {
    for (int i = 0, n = provides.size(); i < n; i++) {
      provides.get(i).accept(moduleVisitor);
    }
  }
}
 
Example #8
Source File: ModuleNode.java    From Concurnas with MIT License 5 votes vote down vote up
/**
 * Makes the given class visitor visit this module.
 *
 * @param classVisitor a class visitor.
 */
public void accept(final ClassVisitor classVisitor) {
  ModuleVisitor moduleVisitor = classVisitor.visitModule(name, access, version);
  if (moduleVisitor == null) {
    return;
  }
  if (mainClass != null) {
    moduleVisitor.visitMainClass(mainClass);
  }
  if (packages != null) {
    for (int i = 0, n = packages.size(); i < n; i++) {
      moduleVisitor.visitPackage(packages.get(i));
    }
  }
  if (requires != null) {
    for (int i = 0, n = requires.size(); i < n; i++) {
      requires.get(i).accept(moduleVisitor);
    }
  }
  if (exports != null) {
    for (int i = 0, n = exports.size(); i < n; i++) {
      exports.get(i).accept(moduleVisitor);
    }
  }
  if (opens != null) {
    for (int i = 0, n = opens.size(); i < n; i++) {
      opens.get(i).accept(moduleVisitor);
    }
  }
  if (uses != null) {
    for (int i = 0, n = uses.size(); i < n; i++) {
      moduleVisitor.visitUse(uses.get(i));
    }
  }
  if (provides != null) {
    for (int i = 0, n = provides.size(); i < n; i++) {
      provides.get(i).accept(moduleVisitor);
    }
  }
}
 
Example #9
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 #10
Source File: CheckClassAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  checkState();
  if (visitModuleCalled) {
    throw new IllegalStateException("visitModule can be called only once.");
  }
  visitModuleCalled = true;
  checkFullyQualifiedName(this.version, name, "module name");
  checkAccess(access, Opcodes.ACC_OPEN | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_MANDATED);
  CheckModuleAdapter checkModuleAdapter =
      new CheckModuleAdapter(
          api, super.visitModule(name, access, version), (access & Opcodes.ACC_OPEN) != 0);
  checkModuleAdapter.classVersion = this.version;
  return checkModuleAdapter;
}
 
Example #11
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 #12
Source File: CheckClassAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  checkState();
  if (visitModuleCalled) {
    throw new IllegalStateException("visitModule can be called only once.");
  }
  visitModuleCalled = true;
  checkFullyQualifiedName(this.version, name, "module name");
  checkAccess(access, Opcodes.ACC_OPEN | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_MANDATED);
  CheckModuleAdapter checkModuleAdapter =
      new CheckModuleAdapter(
          api, super.visitModule(name, access, version), (access & Opcodes.ACC_OPEN) != 0);
  checkModuleAdapter.classVersion = this.version;
  return checkModuleAdapter;
}
 
Example #13
Source File: ModuleNode.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Makes the given class visitor visit this module.
 *
 * @param classVisitor
 *          a class visitor.
 */
public void accept(final ClassVisitor classVisitor) {
	ModuleVisitor moduleVisitor = classVisitor.visitModule(name, access, version);
	if (moduleVisitor == null) {
		return;
	}
	if (mainClass != null) {
		moduleVisitor.visitMainClass(mainClass);
	}
	if (packages != null) {
		for (int i = 0, n = packages.size(); i < n; i++) {
			moduleVisitor.visitPackage(packages.get(i));
		}
	}
	if (requires != null) {
		for (int i = 0, n = requires.size(); i < n; i++) {
			requires.get(i).accept(moduleVisitor);
		}
	}
	if (exports != null) {
		for (int i = 0, n = exports.size(); i < n; i++) {
			exports.get(i).accept(moduleVisitor);
		}
	}
	if (opens != null) {
		for (int i = 0, n = opens.size(); i < n; i++) {
			opens.get(i).accept(moduleVisitor);
		}
	}
	if (uses != null) {
		for (int i = 0, n = uses.size(); i < n; i++) {
			moduleVisitor.visitUse(uses.get(i));
		}
	}
	if (provides != null) {
		for (int i = 0, n = provides.size(); i < n; i++) {
			provides.get(i).accept(moduleVisitor);
		}
	}
}
 
Example #14
Source File: TraceClassVisitor.java    From Concurnas with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  Printer modulePrinter = p.visitModule(name, flags, version);
  return new TraceModuleVisitor(super.visitModule(name, flags, version), modulePrinter);
}
 
Example #15
Source File: ClassRemapper.java    From Concurnas with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  ModuleVisitor moduleVisitor = super.visitModule(remapper.mapModuleName(name), flags, version);
  return moduleVisitor == null ? null : createModuleRemapper(moduleVisitor);
}
 
Example #16
Source File: ClassRemapper.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  ModuleVisitor moduleVisitor = super.visitModule(remapper.mapModuleName(name), flags, version);
  return moduleVisitor == null ? null : createModuleRemapper(moduleVisitor);
}
 
Example #17
Source File: TraceClassVisitor.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  Printer modulePrinter = p.visitModule(name, flags, version);
  return new TraceModuleVisitor(super.visitModule(name, flags, version), modulePrinter);
}
 
Example #18
Source File: ClassRemapper.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  ModuleVisitor moduleVisitor = super.visitModule(remapper.mapModuleName(name), flags, version);
  return moduleVisitor == null ? null : createModuleRemapper(moduleVisitor);
}
 
Example #19
Source File: RejectionClassVisitor.java    From AVM with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(String name, int access, String version) {
    throw RuntimeAssertionError.unimplemented("AKI-106: This is never called");
}
 
Example #20
Source File: RemappingClassAdapter.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  throw new RuntimeException("RemappingClassAdapter is deprecated, use ClassRemapper instead");
}
 
Example #21
Source File: ClassNode.java    From Concurnas with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  module = new ModuleNode(name, access, version);
  return module;
}
 
Example #22
Source File: ClassNode.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  return module = new ModuleNode(name, access, version);
}
 
Example #23
Source File: TraceClassVisitor.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  Printer modulePrinter = p.visitModule(name, flags, version);
  return new TraceModuleVisitor(super.visitModule(name, flags, version), modulePrinter);
}
 
Example #24
Source File: CheckModuleAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public CheckModuleAdapter(final ModuleVisitor mv, final boolean isOpen) {
  super(Opcodes.ASM6, mv);
  this.isOpen = isOpen;
}
 
Example #25
Source File: TraceClassVisitor.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(String name, int flags, String version) {
  Printer p = this.p.visitModule(name, flags, version);
  ModuleVisitor mv = super.visitModule(name, flags, version);
  return new TraceModuleVisitor(mv, p);
}
 
Example #26
Source File: TraceModuleVisitor.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public TraceModuleVisitor(final ModuleVisitor mv, final Printer p) {
  super(Opcodes.ASM6, mv);
  this.p = p;
}
 
Example #27
Source File: MethodInfoClassVisitor.java    From sumk with Apache License 2.0 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(String name, int access, String version) {
	return null;
}
 
Example #28
Source File: ClassRemapper.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  ModuleVisitor moduleVisitor = super.visitModule(remapper.mapModuleName(name), flags, version);
  return moduleVisitor == null ? null : createModuleRemapper(moduleVisitor);
}
 
Example #29
Source File: RemappingClassAdapter.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int flags, final String version) {
  throw new RuntimeException("RemappingClassAdapter is deprecated, use ClassRemapper instead");
}
 
Example #30
Source File: ClassNode.java    From JReFrameworker with MIT License 4 votes vote down vote up
@Override
public ModuleVisitor visitModule(final String name, final int access, final String version) {
  module = new ModuleNode(name, access, version);
  return module;
}