Search in sources :

Example 1 with ClassWriter

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.jar.asm.ClassWriter in project mockito by mockito.

the class ModuleUtil method moduleInfo.

private static byte[] moduleInfo(boolean isExported, boolean isOpened) {
    ClassWriter classWriter = new ClassWriter(OpenedClassReader.ASM_API);
    classWriter.visit(Opcodes.V9, Opcodes.ACC_MODULE, "module-info", null, null, null);
    ModuleVisitor mv = classWriter.visitModule("mockito.test", 0, null);
    mv.visitRequire("java.base", Opcodes.ACC_MANDATED, null);
    mv.visitPackage("sample");
    if (isExported) {
        mv.visitExport("sample", 0);
    }
    if (isOpened) {
        mv.visitOpen("sample", 0);
    }
    mv.visitEnd();
    classWriter.visitEnd();
    return classWriter.toByteArray();
}
Also used : ModuleVisitor(net.bytebuddy.jar.asm.ModuleVisitor) ClassWriter(net.bytebuddy.jar.asm.ClassWriter)

Example 2 with ClassWriter

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.jar.asm.ClassWriter in project powermock by powermock.

the class ClassFactory method create.

static byte[] create(String className) throws Exception {
    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;
    cw.visit(49, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", null);
    cw.visitSource("Hello.java", null);
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("hello");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
    }
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : ClassWriter(net.bytebuddy.jar.asm.ClassWriter) MethodVisitor(net.bytebuddy.jar.asm.MethodVisitor)

Example 3 with ClassWriter

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.jar.asm.ClassWriter in project powermock by powermock.

the class DefinalizingClassTransformer method transform.

public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
    if (loader == null || shouldIgnore(className)) {
        return null;
    }
    final ClassReader reader = new ClassReader(classfileBuffer);
    final ClassWriter writer = new ClassWriter(NO_FLAGS_OR_OPTIONS);
    reader.accept(new DefinalizingClassVisitor(writer), NO_FLAGS_OR_OPTIONS);
    return writer.toByteArray();
}
Also used : ClassReader(net.bytebuddy.jar.asm.ClassReader) ClassWriter(net.bytebuddy.jar.asm.ClassWriter)

Aggregations

ClassWriter (net.bytebuddy.jar.asm.ClassWriter)3 ClassReader (net.bytebuddy.jar.asm.ClassReader)1 MethodVisitor (net.bytebuddy.jar.asm.MethodVisitor)1 ModuleVisitor (net.bytebuddy.jar.asm.ModuleVisitor)1