use of 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);
}
use of 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);
}
use of 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);
}
use of 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);
}
use of 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);
}
Aggregations