use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class MethodInvocationGenericTest method testGenericMethod.
@Test
public void testGenericMethod() throws Exception {
TypeDescription genericErasure = mock(TypeDescription.class);
when(methodReturnType.asErasure()).thenReturn(genericErasure);
StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription);
assertThat(stackManipulation.isValid(), is(true));
assertThat(stackManipulation, is((StackManipulation) new MethodInvocation.OfGenericMethod(genericErasure, MethodInvocation.invoke(declaredMethod))));
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class MethodInvocationHandleTest method testExactHandleStatic.
@Test
public void testExactHandleStatic() throws Exception {
when(methodDescription.isStatic()).thenReturn(true);
StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).onHandle(MethodInvocation.HandleType.EXACT);
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", BAZ, false);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class MethodInvocationHandleTest method testExactHandleNonStatic.
@Test
public void testExactHandleNonStatic() throws Exception {
StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).onHandle(MethodInvocation.HandleType.EXACT);
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", "(" + BAR + BAZ.substring(1), false);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class MethodInvocationHandleTest method testExactHandleConstructor.
@Test
public void testExactHandleConstructor() throws Exception {
when(methodDescription.isConstructor()).thenReturn(true);
StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).onHandle(MethodInvocation.HandleType.EXACT);
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", BAZ, false);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class MethodVariableAccessOfMethodArgumentsTest method testBridgeMethodWithoutCasting.
@Test
public void testBridgeMethodWithoutCasting() throws Exception {
when(bridgeMethod.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(bridgeMethod, Arrays.asList(firstParameterType, secondParameterType)));
StackManipulation stackManipulation = MethodVariableAccess.allArgumentsOf(methodDescription).asBridgeOf(bridgeMethod);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(PARAMETER_STACK_SIZE));
assertThat(size.getMaximalSize(), is(PARAMETER_STACK_SIZE));
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 1);
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 2);
verifyNoMoreInteractions(methodVisitor);
}
Aggregations