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();
}
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();
}
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();
}
Aggregations