Search in sources :

Example 1 with LocalVariablesSorter

use of org.objectweb.asm.commons.LocalVariablesSorter 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);
}
Also used : MethodList(net.bytebuddy.description.method.MethodList) FieldList(net.bytebuddy.description.field.FieldList) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AsmVisitorWrapper(net.bytebuddy.asm.AsmVisitorWrapper) TypeDescription(net.bytebuddy.description.type.TypeDescription) LocalVariablesSorter(org.objectweb.asm.commons.LocalVariablesSorter) TypePool(net.bytebuddy.pool.TypePool) AbstractDynamicTypeBuilderTest(net.bytebuddy.dynamic.AbstractDynamicTypeBuilderTest) Test(org.junit.Test)

Aggregations

AsmVisitorWrapper (net.bytebuddy.asm.AsmVisitorWrapper)1 FieldList (net.bytebuddy.description.field.FieldList)1 MethodList (net.bytebuddy.description.method.MethodList)1 TypeDescription (net.bytebuddy.description.type.TypeDescription)1 AbstractDynamicTypeBuilderTest (net.bytebuddy.dynamic.AbstractDynamicTypeBuilderTest)1 TypePool (net.bytebuddy.pool.TypePool)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 LocalVariablesSorter (org.objectweb.asm.commons.LocalVariablesSorter)1