Search in sources :

Example 26 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodVariableAccessOfMethodArgumentsTest method testNonStaticMethodWithPrepending.

@Test
public void testNonStaticMethodWithPrepending() throws Exception {
    StackManipulation stackManipulation = MethodVariableAccess.allArgumentsOf(methodDescription).prependThisReference();
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(PARAMETER_STACK_SIZE + 1));
    assertThat(size.getMaximalSize(), is(PARAMETER_STACK_SIZE + 1));
    verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
    verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 1);
    verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 2);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 27 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodVariableAccessOfMethodArgumentsTest method testStaticMethodWithPrepending.

@Test
public void testStaticMethodWithPrepending() throws Exception {
    when(methodDescription.isStatic()).thenReturn(true);
    StackManipulation stackManipulation = MethodVariableAccess.allArgumentsOf(methodDescription).prependThisReference();
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(PARAMETER_STACK_SIZE));
    assertThat(size.getMaximalSize(), is(PARAMETER_STACK_SIZE));
    verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
    verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 1);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 28 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class AssignerEqualTypesOnlyTest method testAssignmentErausreEqual.

@Test
public void testAssignmentErausreEqual() throws Exception {
    StackManipulation stackManipulation = Assigner.EqualTypesOnly.ERASURE.assign(first, first, Assigner.Typing.of(dynamicallyTyped));
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verify(first, times(2)).asErasure();
    verifyNoMoreInteractions(first);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 29 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class AssignerEqualTypesOnlyTest method testAssignmentGenericEqual.

@Test
public void testAssignmentGenericEqual() throws Exception {
    StackManipulation stackManipulation = Assigner.EqualTypesOnly.GENERIC.assign(first, first, Assigner.Typing.of(dynamicallyTyped));
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verifyZeroInteractions(first);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 30 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class AssignerEqualTypesOnlyTest method testAssignmentGenericNotEqual.

@Test
public void testAssignmentGenericNotEqual() throws Exception {
    StackManipulation stackManipulation = Assigner.EqualTypesOnly.GENERIC.assign(first, second, Assigner.Typing.of(dynamicallyTyped));
    assertThat(stackManipulation.isValid(), is(false));
    verifyZeroInteractions(first);
    verifyZeroInteractions(second);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Aggregations

StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)88 Test (org.junit.Test)85 TypeDescription (net.bytebuddy.description.type.TypeDescription)18 Implementation (net.bytebuddy.implementation.Implementation)5 Assigner (net.bytebuddy.implementation.bytecode.assign.Assigner)5 MethodDescription (net.bytebuddy.description.method.MethodDescription)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4 JavaConstant (net.bytebuddy.utility.JavaConstant)2 Handle (org.objectweb.asm.Handle)2 Field (java.lang.reflect.Field)1 MethodAccessorFactory (net.bytebuddy.implementation.MethodAccessorFactory)1 ElementMatcher (net.bytebuddy.matcher.ElementMatcher)1