Search in sources :

Example 6 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 ReferenceTypeAwareAssignerTest method testPrimitiveAssignabilityWhenEqual.

@Test
public void testPrimitiveAssignabilityWhenEqual() throws Exception {
    // Note: cannot mock equals
    TypeDescription.Generic primitiveType = new TypeDescription.Generic.OfNonGenericType.ForLoadedType(int.class);
    StackManipulation stackManipulation = ReferenceTypeAwareAssigner.INSTANCE.assign(primitiveType, primitiveType, Assigner.Typing.DYNAMIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verifyZeroInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 7 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 ReferenceTypeAwareAssignerTest method testTargetToSourceAssignableRuntimeType.

@Test
public void testTargetToSourceAssignableRuntimeType() throws Exception {
    defineAssignability(false, false);
    when(rawTarget.getInternalName()).thenReturn(FOO);
    StackManipulation stackManipulation = ReferenceTypeAwareAssigner.INSTANCE.assign(source, target, Assigner.Typing.DYNAMIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verify(methodVisitor).visitTypeInsn(Opcodes.CHECKCAST, FOO);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 8 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 AbstractArrayFactoryTest method testCreationUsing.

protected void testCreationUsing(Class<?> componentType, int storageOpcode) throws Exception {
    defineComponentType(componentType);
    CollectionFactory arrayFactory = ArrayFactory.forType(this.componentType);
    StackManipulation arrayStackManipulation = arrayFactory.withValues(Collections.singletonList(stackManipulation));
    assertThat(arrayStackManipulation.isValid(), is(true));
    verify(stackManipulation, atLeast(1)).isValid();
    StackManipulation.Size size = arrayStackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(3 + StackSize.of(componentType).toIncreasingSize().getSizeImpact()));
    verify(methodVisitor).visitInsn(Opcodes.ICONST_1);
    verifyArrayCreation(methodVisitor);
    verify(methodVisitor).visitInsn(Opcodes.DUP);
    verify(methodVisitor).visitInsn(Opcodes.ICONST_0);
    verify(stackManipulation).apply(methodVisitor, implementationContext);
    verify(methodVisitor).visitInsn(storageOpcode);
    verifyNoMoreInteractions(methodVisitor);
    verifyNoMoreInteractions(stackManipulation);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation)

Example 9 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 ArrayAccessOtherTest method testForEach.

@Test
public void testForEach() throws Exception {
    StackManipulation stackManipulation = mock(StackManipulation.class);
    assertThat(ArrayAccess.REFERENCE.forEach(Collections.singletonList(stackManipulation)), is((StackManipulation) new StackManipulation.Compound(new StackManipulation.Compound(Duplication.SINGLE, IntegerConstant.forValue(0), ArrayAccess.REFERENCE.new Loader(), stackManipulation))));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 10 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 ClassConstantReferenceTest method testClassConstantLegacy.

@Test
public void testClassConstantLegacy() throws Exception {
    when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(true);
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(false);
    when(typeDescription.getName()).thenReturn(FOO);
    StackManipulation stackManipulation = ClassConstant.of(typeDescription);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(1));
    verify(typeDescription).getName();
    verify(typeDescription, times(9)).represents(any(Class.class));
    verifyNoMoreInteractions(typeDescription);
    verify(methodVisitor).visitLdcInsn(FOO);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Class.class), "forName", Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)), false);
    verifyNoMoreInteractions(methodVisitor);
}
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