Search in sources :

Example 16 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 PrimitiveWideningDelegateTrivialTest method testNoOpAssignment.

@Test
public void testNoOpAssignment() throws Exception {
    StackManipulation stackManipulation = PrimitiveWideningDelegate.forPrimitive(sourceTypeDescription).widenTo(targetTypeDescription);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verify(sourceTypeDescription, atLeast(1)).represents(sourceType);
    verify(targetTypeDescription, atLeast(1)).represents(sourceType);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 17 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 VoidAwareAssignerNonVoidToVoidTest method testAssignDefaultValue.

private void testAssignDefaultValue(boolean dynamicallyTyped) throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(source, target, Assigner.Typing.of(dynamicallyTyped));
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(-1 * StackSize.of(sourceType).getSize()));
    assertThat(size.getMaximalSize(), is(0));
    verify(methodVisitor).visitInsn(opcode);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation)

Example 18 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 testAssignNoDefaultValue.

@Test(expected = IllegalStateException.class)
public void testAssignNoDefaultValue() throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(source, target, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(false));
    stackManipulation.apply(methodVisitor, implementationContext);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 19 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 MethodInvocationGenericTest method testGenericMethodDynamic.

@Test
public void testGenericMethodDynamic() throws Exception {
    TypeDescription genericErasure = mock(TypeDescription.class);
    when(methodReturnType.asErasure()).thenReturn(genericErasure);
    when(declaredMethod.isBootstrap()).thenReturn(true);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList());
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(MethodInvocation.invoke(declaredMethod).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList())));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 20 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 MethodInvocationGenericTest method testGenericMethodDynamicErasureEqual.

@Test
public void testGenericMethodDynamicErasureEqual() throws Exception {
    when(methodReturnType.asErasure()).thenReturn(declaredErasure);
    when(declaredMethod.isBootstrap()).thenReturn(true);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList());
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(MethodInvocation.invoke(declaredMethod).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList())));
}
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