Search in sources :

Example 61 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 PrimitiveUnboxingDelegateWideningTest method testTrivialBoxing.

@Test
public void testTrivialBoxing() throws Exception {
    StackManipulation stackManipulation = PrimitiveUnboxingDelegate.forReferenceType(referenceTypeDescription).assignUnboxedTo(primitiveTypeDescription, chainedAssigner, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(sizeChange));
    assertThat(size.getMaximalSize(), is(interimMaximum));
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(referenceType), unboxingMethodName, unboxingMethodDescriptor, false);
    verify(methodVisitor).visitInsn(wideningOpcode);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 62 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 PrimitiveWideningDelegateIllegalTest method testIllegalBoolean.

@Test(expected = IllegalStateException.class)
public void testIllegalBoolean() throws Exception {
    StackManipulation stackManipulation = PrimitiveWideningDelegate.forPrimitive(sourceTypeDescription).widenTo(targetTypeDescription);
    assertThat(stackManipulation.isValid(), is(false));
    stackManipulation.apply(methodVisitor, implementationContext);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 63 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 VoidAwareAssignerTest method testAssignNonVoidToNonVoid.

@Test
public void testAssignNonVoidToNonVoid() throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation chainedStackManipulation = mock(StackManipulation.class);
    when(chainedAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC)).thenReturn(chainedStackManipulation);
    StackManipulation stackManipulation = voidAwareAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation, is(chainedStackManipulation));
    verify(chainedAssigner).assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    verifyNoMoreInteractions(chainedAssigner);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 64 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 VoidAwareAssignerTest method testAssignVoidToVoid.

@Test
public void testAssignVoidToVoid() throws Exception {
    when(sourceTypeDescription.represents(void.class)).thenReturn(true);
    when(targetTypeDescription.represents(void.class)).thenReturn(true);
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verifyZeroInteractions(chainedAssigner);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 65 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 VoidAwareAssignerVoidToNonVoidTest method testAssignDefaultValue.

@Test
public void testAssignDefaultValue() throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(source, target, Assigner.Typing.DYNAMIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(StackSize.of(targetType).getSize()));
    assertThat(size.getMaximalSize(), is(StackSize.of(targetType).getSize()));
    verify(methodVisitor).visitInsn(opcode);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Aggregations

StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)93 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 Goto (org.curioswitch.common.protobuf.json.bytebuddy.Goto)5 MethodDescription (net.bytebuddy.description.method.MethodDescription)4 ForLoadedType (net.bytebuddy.description.type.TypeDescription.ForLoadedType)4 Label (net.bytebuddy.jar.asm.Label)4 SetJumpTargetLabel (org.curioswitch.common.protobuf.json.bytebuddy.SetJumpTargetLabel)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4 ArrayList (java.util.ArrayList)3 IfTrue (org.curioswitch.common.protobuf.json.bytebuddy.IfTrue)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