Search in sources :

Example 6 with ParameterDescription

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

the class MethodAttributeAppenderForInstrumentedMethodTest method testMethodParameterAnnotationClassFileRetention.

@Test
@SuppressWarnings("unchecked")
public void testMethodParameterAnnotationClassFileRetention() 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 QuxBaz.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(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)

Example 7 with ParameterDescription

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

the class MethodAttributeAppenderForInstrumentedMethodTest method testMethodParameterTypeTypeAnnotationNoRetention.

@Test
@SuppressWarnings("unchecked")
public void testMethodParameterTypeTypeAnnotationNoRetention() 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 Qux.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verifyZeroInteractions(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 8 with ParameterDescription

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

the class MethodAttributeAppenderForInstrumentedMethodTest method testMethodParameterAnnotationNoRetention.

@Test
@SuppressWarnings("unchecked")
public void testMethodParameterAnnotationNoRetention() 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 Qux.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);
    verifyZeroInteractions(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 9 with ParameterDescription

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

the class ArgumentTypeResolverPrimitiveTest method testDominance.

private void testDominance(TypeDescription.Generic leftPrimitive, TypeDescription.Generic rightPrimitive, MethodDelegationBinder.AmbiguityResolver.Resolution expected) throws Exception {
    when(sourceParameterList.size()).thenReturn(2);
    when(sourceType.isPrimitive()).thenReturn(true);
    ParameterDescription leftParameter = mock(ParameterDescription.class);
    when(leftParameter.getType()).thenReturn(leftPrimitive);
    when(leftParameterList.get(0)).thenReturn(leftParameter);
    when(left.getTargetParameterIndex(any(ArgumentTypeResolver.ParameterIndexToken.class))).thenAnswer(new TokenAnswer(new int[][] { { 0, 0 } }));
    ParameterDescription rightParameter = mock(ParameterDescription.class);
    when(rightParameter.getType()).thenReturn(rightPrimitive);
    when(rightParameterList.get(0)).thenReturn(rightParameter);
    when(right.getTargetParameterIndex(any(ArgumentTypeResolver.ParameterIndexToken.class))).thenAnswer(new TokenAnswer(new int[][] { { 0, 0 } }));
    MethodDelegationBinder.AmbiguityResolver.Resolution resolution = ArgumentTypeResolver.INSTANCE.resolve(source, left, right);
    assertThat(resolution, is(expected));
    verify(source, atLeast(1)).getParameters();
    verify(leftMethod, atLeast(1)).getParameters();
    verify(rightMethod, atLeast(1)).getParameters();
    verify(left, atLeast(1)).getTargetParameterIndex(argThat(describesArgument(0)));
    verify(left, atLeast(1)).getTargetParameterIndex(argThat(describesArgument(1)));
    verify(left, never()).getTargetParameterIndex(argThat(not(describesArgument(0, 1))));
    verify(right, atLeast(1)).getTargetParameterIndex(argThat(describesArgument(0)));
    verify(right, atLeast(1)).getTargetParameterIndex(argThat(describesArgument(1)));
    verify(right, never()).getTargetParameterIndex(argThat(not(describesArgument(0, 1))));
}
Also used : ParameterDescription(net.bytebuddy.description.method.ParameterDescription)

Example 10 with ParameterDescription

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

the class ImplementationContextDefaultTest method testFieldGetterRegistration.

@Test
public void testFieldGetterRegistration() throws Exception {
    Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
    MethodDescription firstFieldGetter = implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT);
    assertThat(firstFieldGetter.getParameters(), is((ParameterList) new ParameterList.Empty<ParameterDescription>()));
    assertThat(firstFieldGetter.getReturnType(), is(firstFieldType));
    assertThat(firstFieldGetter.getInternalName(), startsWith(FOO));
    assertThat(firstFieldGetter.getModifiers(), is(accessorMethodModifiers));
    assertThat(firstFieldGetter.getExceptionTypes(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstFieldGetter));
    when(secondField.isStatic()).thenReturn(true);
    MethodDescription secondFieldGetter = implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT);
    assertThat(secondFieldGetter.getParameters(), is((ParameterList) new ParameterList.Empty<ParameterDescription>()));
    assertThat(secondFieldGetter.getReturnType(), is(secondFieldType));
    assertThat(secondFieldGetter.getInternalName(), startsWith(BAR));
    assertThat(secondFieldGetter.getModifiers(), is(accessorMethodModifiers | Opcodes.ACC_STATIC));
    assertThat(secondFieldGetter.getExceptionTypes(), is((TypeList.Generic) new TypeList.Generic.Empty()));
    assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstFieldGetter));
    assertThat(implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT), is(secondFieldGetter));
    implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
    verify(classVisitor).visitMethod(eq(accessorMethodModifiers), Matchers.startsWith(FOO), eq("()" + BAR), isNull(String.class), isNull(String[].class));
    verify(classVisitor).visitMethod(eq(accessorMethodModifiers | Opcodes.ACC_STATIC), Matchers.startsWith(BAR), eq("()" + QUX), isNull(String.class), isNull(String[].class));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) ParameterList(net.bytebuddy.description.method.ParameterList) 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