@Test public void testReadAndWrite_removeOptionalModuleData() { byte[] classFile = PrecompiledClass.JDK9_MODULE.getBytes(); ClassReader classReader = new ClassReader(classFile); ClassWriter classWriter = new ClassWriter(0); ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM7, classWriter) { @Override public ModuleVisitor visitModule( final String name, final int access, final String version) { return new ModuleVisitor(api, super.visitModule(name, access, version)) { @Override public void visitMainClass(final String mainClass) {} @Override public void visitPackage(final String packaze) {} @Override public void visitRequire( final String module, final int access, final String version) { super.visitRequire(module, access, null); } @Override public void visitExport( final String packaze, final int access, final String... modules) { super.visitExport(packaze, access, (String[]) null); } @Override public void visitOpen( final String packaze, final int access, final String... modules) { super.visitOpen(packaze, access, (String[]) null); } }; } }; classReader.accept(classVisitor, null, 0); String classDump = new ClassFile(classWriter.toByteArray()).toString(); assertFalse(classDump.contains("ModulePackage")); assertFalse(classDump.contains("ModuleMainClass")); }
public ModuleVisitor visitModule(final String name, final int access, final String version) { if (api < Opcodes.ASM6) { throw new UnsupportedOperationException("This feature requires ASM6"); } if (cv != null) { return cv.visitModule(name, access, version); } return null; }
ClassVisitor { public ModuleVisitor visitModule(final String name, final int access, final String version) { if (api < Opcodes.ASM6) { throw new UnsupportedOperationException("This feature requires ASM6"); } if (cv != null) { return cv.visitModule(name, access, version); } return null; } }
ClassVisitor { public ModuleVisitor visitModule(final String name, final int access, final String version) { if (api < Opcodes.ASM6) { throw new UnsupportedOperationException("This feature requires ASM6"); } if (cv != null) { return cv.visitModule(name, access, version); } return null; } ClassVisitor(final int api);  ClassVisitor(final int api, final ClassVisitor classVisitor); }
ClassVisitor { public ModuleVisitor visitModule(final String name, final int access, final String version) { if (api < Opcodes.ASM6) { throw new UnsupportedOperationException("This feature requires ASM6"); } if (cv != null) { return cv.visitModule(name, access, version); } return null; } ClassVisitor(final int api);  ClassVisitor(final int api, final ClassVisitor classVisitor); void visit(
      final int version,
      final int access,
      final String name,
      final String signature,
      final String superName,
      final String[] interfaces); void visitSource(final String source, final String debug); ModuleVisitor visitModule(final String name, final int access, final String version); void visitNestHost(final String nestHost); void visitOuterClass(final String owner, final String name, final String descriptor); AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible); AnnotationVisitor visitTypeAnnotation(
      final int typeRef, final TypePath typePath, final String descriptor, final boolean visible); void visitAttribute(final Attribute attribute); void visitNestMember(final String nestMember); void visitInnerClass(
      final String name, final String outerName, final String innerName, final int access); FieldVisitor visitField(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final Object value); MethodVisitor visitMethod(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final String[] exceptions); void visitEnd(); }
ClassVisitor { public ModuleVisitor visitModule(final String name, final int access, final String version) { if (api < Opcodes.ASM6) { throw new UnsupportedOperationException("This feature requires ASM6"); } if (cv != null) { return cv.visitModule(name, access, version); } return null; } ClassVisitor(final int api);  ClassVisitor(final int api, final ClassVisitor classVisitor); void visit(
      final int version,
      final int access,
      final String name,
      final String signature,
      final String superName,
      final String[] interfaces); void visitSource(final String source, final String debug); ModuleVisitor visitModule(final String name, final int access, final String version); void visitNestHost(final String nestHost); void visitOuterClass(final String owner, final String name, final String descriptor); AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible); AnnotationVisitor visitTypeAnnotation(
      final int typeRef, final TypePath typePath, final String descriptor, final boolean visible); void visitAttribute(final Attribute attribute); void visitNestMember(final String nestMember); void visitInnerClass(
      final String name, final String outerName, final String innerName, final int access); FieldVisitor visitField(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final Object value); MethodVisitor visitMethod(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final String[] exceptions); void visitEnd();  }