Search in sources :

Example 16 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class PrimitiveWideningDelegateTrivialTest method testNoOpAssignment.

@Test
public void testNoOpAssignment() throws Exception {
    StackManipulation stackManipulation = PrimitiveWideningDelegate.forPrimitive(sourceTypeDescription).widenTo(targetTypeDescription);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verify(sourceTypeDescription, atLeast(1)).represents(sourceType);
    verify(targetTypeDescription, atLeast(1)).represents(sourceType);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 17 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation 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 18 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation 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 19 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodInvocationGenericTest method testGenericMethodDynamic.

@Test
public void testGenericMethodDynamic() throws Exception {
    TypeDescription genericErasure = mock(TypeDescription.class);
    when(methodReturnType.asErasure()).thenReturn(genericErasure);
    when(declaredMethod.isBootstrap()).thenReturn(true);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList());
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(MethodInvocation.invoke(declaredMethod).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList())));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 20 with StackManipulation

use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodInvocationGenericTest method testGenericMethodDynamicErasureEqual.

@Test
public void testGenericMethodDynamicErasureEqual() throws Exception {
    when(methodReturnType.asErasure()).thenReturn(declaredErasure);
    when(declaredMethod.isBootstrap()).thenReturn(true);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList());
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(MethodInvocation.invoke(declaredMethod).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList())));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Aggregations

StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)88 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 MethodVisitor (org.objectweb.asm.MethodVisitor)4 JavaConstant (net.bytebuddy.utility.JavaConstant)2 Handle (org.objectweb.asm.Handle)2 Field (java.lang.reflect.Field)1 MethodAccessorFactory (net.bytebuddy.implementation.MethodAccessorFactory)1 ElementMatcher (net.bytebuddy.matcher.ElementMatcher)1