Search in sources :

Example 1 with ParameterDescription

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)));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test)

Example 2 with ParameterDescription

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));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test)

Example 3 with ParameterDescription

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));
}
Also used : ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test)

Example 4 with ParameterDescription

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;
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) ParameterDescription(net.bytebuddy.description.method.ParameterDescription)

Example 5 with ParameterDescription

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);
}
Also used : AnnotationDescription(net.bytebuddy.description.annotation.AnnotationDescription) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test) AnnotationDescriptionBuilderTest(net.bytebuddy.description.annotation.AnnotationDescriptionBuilderTest)

Aggregations

ParameterDescription (net.bytebuddy.description.method.ParameterDescription)14 Test (org.junit.Test)12 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)6 AnnotationDescriptionBuilderTest (net.bytebuddy.description.annotation.AnnotationDescriptionBuilderTest)6 AnnotationList (net.bytebuddy.description.annotation.AnnotationList)6 TypeDescription (net.bytebuddy.description.type.TypeDescription)5 MethodDescription (net.bytebuddy.description.method.MethodDescription)1 ParameterList (net.bytebuddy.description.method.ParameterList)1