Search in sources :

Example 31 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 PrimitiveBoxingDelegateTest method testBoxing.

@Test
public void testBoxing() throws Exception {
    StackManipulation boxingStackManipulation = PrimitiveBoxingDelegate.forPrimitive(primitiveTypeDescription).assignBoxedTo(targetType, chainedAssigner, Assigner.Typing.STATIC);
    assertThat(boxingStackManipulation.isValid(), is(true));
    StackManipulation.Size size = boxingStackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(sizeChange));
    assertThat(size.getMaximalSize(), is(0));
    verify(primitiveTypeDescription).represents(primitiveType);
    verify(primitiveTypeDescription, atLeast(1)).represents(any(Class.class));
    verifyNoMoreInteractions(primitiveTypeDescription);
    verify(chainedAssigner).assign(referenceTypeDescription.asGenericType(), targetType, Assigner.Typing.STATIC);
    verifyNoMoreInteractions(chainedAssigner);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, referenceTypeDescription.getInternalName(), VALUE_OF, boxingMethodDescriptor, false);
    verifyNoMoreInteractions(methodVisitor);
    verify(stackManipulation, atLeast(1)).isValid();
    verify(stackManipulation).apply(methodVisitor, implementationContext);
    verifyNoMoreInteractions(stackManipulation);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 32 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 PrimitiveTypeAwareAssignerBoxingTest method testBoxingAssignment.

@Test
public void testBoxingAssignment() {
    StackManipulation stackManipulation = primitiveAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(assignable));
    verify(chainedStackManipulation).isValid();
    verifyNoMoreInteractions(chainedStackManipulation);
    verify(sourceTypeDescription, atLeast(0)).represents(any(Class.class));
    verify(sourceTypeDescription).represents(sourceType);
    verify(sourceTypeDescription, atLeast(1)).isPrimitive();
    verifyNoMoreInteractions(sourceTypeDescription);
    verify(targetTypeDescription, atLeast(1)).isPrimitive();
    verifyNoMoreInteractions(targetTypeDescription);
    verify(chainedAssigner).assign(new TypeDescription.Generic.OfNonGenericType.ForLoadedType(targetType), targetTypeDescription, Assigner.Typing.STATIC);
    verifyNoMoreInteractions(chainedAssigner);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 33 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 PrimitiveTypeAwareAssignerPrimitiveTest method testPrimitiveToPrimitiveAssignment.

@Test
public void testPrimitiveToPrimitiveAssignment() throws Exception {
    StackManipulation stackManipulation = primitiveAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(assignable));
    verify(sourceTypeDescription, atLeast(0)).represents(any(Class.class));
    verify(sourceTypeDescription).represents(sourceType);
    verify(sourceTypeDescription, atLeast(1)).isPrimitive();
    verifyNoMoreInteractions(sourceTypeDescription);
    verify(targetTypeDescription, atLeast(0)).represents(any(Class.class));
    verify(targetTypeDescription).represents(targetType);
    verify(targetTypeDescription, atLeast(1)).isPrimitive();
    verifyNoMoreInteractions(targetTypeDescription);
    verifyZeroInteractions(chainedAssigner);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 34 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 PrimitiveTypeAwareAssignerUnboxingTest method testUnboxingAssignment.

@Test
public void testUnboxingAssignment() throws Exception {
    StackManipulation stackManipulation = primitiveAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(assignable));
    verify(sourceTypeDescription, atLeast(0)).represents(any(Class.class));
    verify(sourceTypeDescription).represents(sourceType);
    verify(sourceTypeDescription, atLeast(1)).isPrimitive();
    verifyNoMoreInteractions(sourceTypeDescription);
    verify(targetTypeDescription, atLeast(0)).represents(any(Class.class));
    verify(targetTypeDescription).represents(targetType);
    verify(targetTypeDescription, atLeast(1)).isPrimitive();
    verifyNoMoreInteractions(targetTypeDescription);
    verifyZeroInteractions(chainedAssigner);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 35 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 FieldConstantTest method testConstantCreationLegacy.

@Test
public void testConstantCreationLegacy() throws Exception {
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(false);
    when(declaringType.isVisibleTo(instrumentedType)).thenReturn(true);
    StackManipulation stackManipulation = new FieldConstant(fieldDescription);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(2));
    verify(methodVisitor).visitLdcInsn(BAZ);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Class.class), "forName", Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)), false);
    verify(methodVisitor).visitLdcInsn(BAR);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;", false);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : 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