use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.
the class MethodVariableAccessOtherTest method testIncrementParameter.
@Test
public void testIncrementParameter() throws Exception {
ParameterDescription parameterDescription = mock(ParameterDescription.class);
when(parameterDescription.getType()).thenReturn(new TypeDescription.Generic.OfNonGenericType.ForLoadedType(int.class));
when(parameterDescription.getOffset()).thenReturn(4);
assertThat(MethodVariableAccess.increment(parameterDescription, 42), is(MethodVariableAccess.INTEGER.increment(4, 42)));
}
use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testIsParameterDefinedShape.
@Test
public void testIsParameterDefinedShape() throws Exception {
ParameterDescription parameterDescription = new TypeDescription.ForLoadedType(GenericMethodType.Inner.class).getInterfaces().getOnly().getDeclaredMethods().filter(named(FOO)).getOnly().getParameters().getOnly();
assertThat(ElementMatchers.definedParameter(ElementMatchers.is(parameterDescription.asDefined())).matches(parameterDescription), is(true));
assertThat(ElementMatchers.is(parameterDescription.asDefined()).matches(parameterDescription.asDefined()), is(true));
assertThat(ElementMatchers.is(parameterDescription.asDefined()).matches(parameterDescription), is(true));
assertThat(ElementMatchers.is(parameterDescription).matches(parameterDescription.asDefined()), is(false));
}
use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testIsMandated.
@Test
public void testIsMandated() throws Exception {
ParameterDescription parameterDescription = mock(ParameterDescription.class);
when(parameterDescription.getModifiers()).thenReturn(Opcodes.ACC_MANDATED);
assertThat(ElementMatchers.isMandated().matches(parameterDescription), is(true));
assertThat(ElementMatchers.isMandated().matches(mock(ParameterDescription.class)), is(false));
}
use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.
the class MethodCallProxy method extractFields.
/**
* Creates a linked hash map of field names to their types where each field represents a parameter of the method.
*
* @param methodDescription The method to extract into fields.
* @return A map of fields in the order they need to be loaded onto the operand stack for invoking the original
* method, including a reference to the instance of the instrumented type that is invoked if applicable.
*/
private static LinkedHashMap<String, TypeDescription> extractFields(MethodDescription methodDescription) {
LinkedHashMap<String, TypeDescription> typeDescriptions = new LinkedHashMap<String, TypeDescription>();
int currentIndex = 0;
if (!methodDescription.isStatic()) {
typeDescriptions.put(fieldName(currentIndex++), methodDescription.getDeclaringType().asErasure());
}
for (ParameterDescription parameterDescription : methodDescription.getParameters()) {
typeDescriptions.put(fieldName(currentIndex++), parameterDescription.getType().asErasure());
}
return typeDescriptions;
}
use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.
the class MethodAttributeAppenderForInstrumentedMethodTest method testMethodParameterTypeTypeAnnotationClassFileRetention.
@Test
@SuppressWarnings("unchecked")
public void testMethodParameterTypeTypeAnnotationClassFileRetention() throws Exception {
when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
ParameterDescription parameterDescription = mock(ParameterDescription.class);
when(parameterDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
when(parameterDescription.getType()).thenReturn(simpleAnnotatedType);
when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(parameterDescription));
when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
verify(methodVisitor).visitTypeAnnotation(TypeReference.newFormalParameterReference(0).getValue(), null, Type.getDescriptor(QuxBaz.class), false);
verifyNoMoreInteractions(methodVisitor);
}
Aggregations