Search in sources :

Example 71 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 PrimitiveTypeAwareAssignerImplicitUnboxingTest method testImplicitUnboxingAssignment.

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

Example 72 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 testPrimitiveAssignabilityWhenNotEqual.

@Test(expected = IllegalStateException.class)
public void testPrimitiveAssignabilityWhenNotEqual() throws Exception {
    // Note: cannot mock equals
    TypeDescription.Generic primitiveType = new TypeDescription.Generic.OfNonGenericType.ForLoadedType(int.class);
    // Note: cannot mock equals
    TypeDescription.Generic otherPrimitiveType = new TypeDescription.Generic.OfNonGenericType.ForLoadedType(long.class);
    StackManipulation stackManipulation = ReferenceTypeAwareAssigner.INSTANCE.assign(primitiveType, otherPrimitiveType, Assigner.Typing.DYNAMIC);
    assertThat(stackManipulation.isValid(), is(false));
    stackManipulation.apply(methodVisitor, implementationContext);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 73 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 ClassConstantPrimitiveTest method testClassConstant.

@Test
public void testClassConstant() throws Exception {
    StackManipulation stackManipulation = ClassConstant.of(primitiveType);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(1));
    verify(methodVisitor).visitFieldInsn(Opcodes.GETSTATIC, wrapperType.getInternalName(), "TYPE", "Ljava/lang/Class;");
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 74 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 testClassConstantModernVisible.

@Test
public void testClassConstantModernVisible() throws Exception {
    when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(true);
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
    when(typeDescription.getDescriptor()).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).getDescriptor();
    verify(typeDescription).isVisibleTo(instrumentedType);
    verify(typeDescription, times(9)).represents(any(Class.class));
    verifyNoMoreInteractions(typeDescription);
    verify(methodVisitor).visitLdcInsn(Type.getType(FOO));
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 75 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 testClassConstantModernInvisible.

@Test
public void testClassConstantModernInvisible() throws Exception {
    when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(false);
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
    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).isVisibleTo(instrumentedType);
    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)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