Search in sources :

Example 41 with StackManipulation

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

the class FieldAccessOtherTest method testEnumerationDescription.

@Test
public void testEnumerationDescription() throws Exception {
    when(fieldDescription.isPublic()).thenReturn(true);
    when(fieldDescription.isStatic()).thenReturn(true);
    when(fieldDescription.isEnum()).thenReturn(true);
    when(fieldDescription.getActualName()).thenReturn(FOO);
    StackManipulation stackManipulation = FieldAccess.forEnumeration(enumerationDescription);
    assertThat(stackManipulation.isValid(), is(true));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 42 with StackManipulation

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

the class FieldAccessOtherTest method testGenericFieldAccessGetterEqualErasure.

@Test
public void testGenericFieldAccessGetterEqualErasure() throws Exception {
    TypeDescription declaredErasure = mock(TypeDescription.class);
    when(genericType.asErasure()).thenReturn(declaredErasure);
    when(declaredType.asErasure()).thenReturn(declaredErasure);
    StackManipulation stackManipulation = FieldAccess.forField(genericField).read();
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(FieldAccess.forField(fieldDescription).read()));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 43 with StackManipulation

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

the class HandleInvocationTest method testInvocationDecreasingStack.

@Test
public void testInvocationDecreasingStack() throws Exception {
    JavaConstant.MethodType methodType = JavaConstant.MethodType.of(void.class, Object.class);
    StackManipulation stackManipulation = new HandleInvocation(methodType);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(-1));
    assertThat(size.getMaximalSize(), is(0));
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact", "(Ljava/lang/Object;)V", false);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) JavaConstant(net.bytebuddy.utility.JavaConstant) Test(org.junit.Test)

Example 44 with StackManipulation

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

the class MethodInvocationDynamicTest method testIllegalBootstrap.

@Test
public void testIllegalBootstrap() throws Exception {
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, returnType, Arrays.asList(firstType, secondType), Collections.singletonList(argument));
    assertThat(stackManipulation.isValid(), is(false));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 45 with StackManipulation

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

the class MethodInvocationDynamicTest method testDynamicConstructorBootstrap.

@Test
public void testDynamicConstructorBootstrap() throws Exception {
    when(methodDescription.isBootstrap()).thenReturn(true);
    when(methodDescription.isConstructor()).thenReturn(true);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, returnType, Arrays.asList(firstType, secondType), Collections.singletonList(argument));
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verify(methodVisitor).visitInvokeDynamicInsn(FOO, "(" + FOO + BAR + ")" + QUX, new Handle(Opcodes.H_NEWINVOKESPECIAL, BAR, QUX, BAZ, false), argument);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Handle(org.objectweb.asm.Handle) 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