Search in sources :

Example 11 with ParameterDescription

use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.

the class MethodAttributeAppenderForInstrumentedMethodTest method testMethodParameterAnnotationRuntimeRetention.

@Test
@SuppressWarnings("unchecked")
public void testMethodParameterAnnotationRuntimeRetention() 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.getType()).thenReturn(TypeDescription.Generic.OBJECT);
    when(parameterDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    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());
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitParameterAnnotation(0, Type.getDescriptor(Baz.class), true);
    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)

Example 12 with ParameterDescription

use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.

the class MethodAttributeAppenderForInstrumentedMethodTest method testMethodParameterTypeTypeAnnotationRuntimeRetention.

@Test
@SuppressWarnings("unchecked")
public void testMethodParameterTypeTypeAnnotationRuntimeRetention() 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 Baz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newFormalParameterReference(0).getValue(), null, Type.getDescriptor(Baz.class), true);
    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)

Example 13 with ParameterDescription

use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.

the class MethodVariableAccessOtherTest method testStoreParameter.

@Test
public void testStoreParameter() 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.store(parameterDescription), is(MethodVariableAccess.INTEGER.storeAt(4)));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test)

Example 14 with ParameterDescription

use of net.bytebuddy.description.method.ParameterDescription in project byte-buddy by raphw.

the class MethodVariableAccessOtherTest method testLoadParameter.

@Test
public void testLoadParameter() 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.load(parameterDescription), is(MethodVariableAccess.INTEGER.loadFrom(4)));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) ParameterDescription(net.bytebuddy.description.method.ParameterDescription) Test(org.junit.Test)

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