use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.asm.AsmVisitorWrapper in project byte-buddy by raphw.
the class AbstractDynamicTypeBuilderTest method testWriterHint.
@Test
@SuppressWarnings("unchecked")
public void testWriterHint() throws Exception {
AsmVisitorWrapper asmVisitorWrapper = mock(AsmVisitorWrapper.class);
when(asmVisitorWrapper.wrap(any(TypeDescription.class), any(ClassVisitor.class), any(Implementation.Context.class), any(TypePool.class), any(FieldList.class), any(MethodList.class), anyInt(), anyInt())).then(new Answer<ClassVisitor>() {
@Override
public ClassVisitor answer(InvocationOnMock invocationOnMock) throws Throwable {
return new ClassVisitor(Opcodes.ASM5, (ClassVisitor) invocationOnMock.getArguments()[1]) {
@Override
public void visitEnd() {
MethodVisitor mv = visitMethod(Opcodes.ACC_PUBLIC, FOO, "()Ljava/lang/String;", null, null);
mv.visitCode();
mv.visitLdcInsn(FOO);
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
};
}
});
when(asmVisitorWrapper.mergeWriter(0)).thenReturn(ClassWriter.COMPUTE_MAXS);
Class<?> type = createPlain().visit(asmVisitorWrapper).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
verify(asmVisitorWrapper).mergeWriter(0);
verify(asmVisitorWrapper, atMost(1)).mergeReader(0);
verify(asmVisitorWrapper).wrap(any(TypeDescription.class), any(ClassVisitor.class), any(Implementation.Context.class), any(TypePool.class), any(FieldList.class), any(MethodList.class), anyInt(), anyInt());
verifyNoMoreInteractions(asmVisitorWrapper);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.asm.AsmVisitorWrapper in project byte-buddy by raphw.
the class AbstractDynamicTypeBuilderForInliningTest method testReaderHint.
@Test
@SuppressWarnings("unchecked")
public void testReaderHint() throws Exception {
AsmVisitorWrapper asmVisitorWrapper = mock(AsmVisitorWrapper.class);
when(asmVisitorWrapper.wrap(any(TypeDescription.class), any(ClassVisitor.class), any(Implementation.Context.class), any(TypePool.class), any(FieldList.class), any(MethodList.class), anyInt(), anyInt())).then(new Answer<ClassVisitor>() {
@Override
public ClassVisitor answer(InvocationOnMock invocationOnMock) throws Throwable {
return new ClassVisitor(Opcodes.ASM5, (ClassVisitor) invocationOnMock.getArguments()[1]) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return new LocalVariablesSorter(access, desc, super.visitMethod(access, name, desc, signature, exceptions));
}
};
}
});
when(asmVisitorWrapper.mergeWriter(0)).thenReturn(ClassWriter.COMPUTE_MAXS);
when(asmVisitorWrapper.mergeReader(0)).thenReturn(ClassReader.EXPAND_FRAMES);
Class<?> type = create(StackMapFrames.class).visit(asmVisitorWrapper).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) BAR));
verify(asmVisitorWrapper).mergeWriter(0);
verify(asmVisitorWrapper).mergeReader(0);
verify(asmVisitorWrapper).wrap(any(TypeDescription.class), any(ClassVisitor.class), any(Implementation.Context.class), any(TypePool.class), any(FieldList.class), any(MethodList.class), anyInt(), anyInt());
verifyNoMoreInteractions(asmVisitorWrapper);
}
Aggregations