Search in sources :

Example 26 with StackManipulation

use of org.apache.beam.vendor.bytebuddy.v1_11_0.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 org.apache.beam.vendor.bytebuddy.v1_11_0.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 org.apache.beam.vendor.bytebuddy.v1_11_0.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 org.apache.beam.vendor.bytebuddy.v1_11_0.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 org.apache.beam.vendor.bytebuddy.v1_11_0.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)92 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 ForLoadedType (net.bytebuddy.description.type.TypeDescription.ForLoadedType)4 Goto (org.curioswitch.common.protobuf.json.bytebuddy.Goto)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4 ArrayList (java.util.ArrayList)3 Label (net.bytebuddy.jar.asm.Label)3 SetJumpTargetLabel (org.curioswitch.common.protobuf.json.bytebuddy.SetJumpTargetLabel)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 Type (java.lang.reflect.Type)2 FieldDescription (net.bytebuddy.description.field.FieldDescription)2 JavaConstant (net.bytebuddy.utility.JavaConstant)2 ForLoadedType (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription.ForLoadedType)2 DynamicType (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType)2 StackManipulation (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation)2 IfTrue (org.curioswitch.common.protobuf.json.bytebuddy.IfTrue)2