Search in sources :

Example 1 with Assigner

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.assign.Assigner in project byte-buddy by raphw.

the class VoidAwareAssignerNonVoidToVoidTest method testAssignDefaultValue.

private void testAssignDefaultValue(boolean dynamicallyTyped) throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(source, target, Assigner.Typing.of(dynamicallyTyped));
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(-1 * StackSize.of(sourceType).getSize()));
    assertThat(size.getMaximalSize(), is(0));
    verify(methodVisitor).visitInsn(opcode);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation)

Example 2 with Assigner

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.assign.Assigner in project byte-buddy by raphw.

the class VoidAwareAssignerVoidToNonVoidTest method testAssignNoDefaultValue.

@Test(expected = IllegalStateException.class)
public void testAssignNoDefaultValue() throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(source, target, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(false));
    stackManipulation.apply(methodVisitor, implementationContext);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 3 with Assigner

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.assign.Assigner in project byte-buddy by raphw.

the class VoidAwareAssignerTest method testAssignNonVoidToNonVoid.

@Test
public void testAssignNonVoidToNonVoid() throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation chainedStackManipulation = mock(StackManipulation.class);
    when(chainedAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC)).thenReturn(chainedStackManipulation);
    StackManipulation stackManipulation = voidAwareAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation, is(chainedStackManipulation));
    verify(chainedAssigner).assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    verifyNoMoreInteractions(chainedAssigner);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 4 with Assigner

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.assign.Assigner in project byte-buddy by raphw.

the class VoidAwareAssignerTest method testAssignVoidToVoid.

@Test
public void testAssignVoidToVoid() throws Exception {
    when(sourceTypeDescription.represents(void.class)).thenReturn(true);
    when(targetTypeDescription.represents(void.class)).thenReturn(true);
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verifyZeroInteractions(chainedAssigner);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 5 with Assigner

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.assign.Assigner in project byte-buddy by raphw.

the class VoidAwareAssignerVoidToNonVoidTest method testAssignDefaultValue.

@Test
public void testAssignDefaultValue() throws Exception {
    Assigner voidAwareAssigner = new VoidAwareAssigner(chainedAssigner);
    StackManipulation stackManipulation = voidAwareAssigner.assign(source, target, Assigner.Typing.DYNAMIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(StackSize.of(targetType).getSize()));
    assertThat(size.getMaximalSize(), is(StackSize.of(targetType).getSize()));
    verify(methodVisitor).visitInsn(opcode);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : Assigner(net.bytebuddy.implementation.bytecode.assign.Assigner) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Aggregations

StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)5 Assigner (net.bytebuddy.implementation.bytecode.assign.Assigner)5 Test (org.junit.Test)4