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