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);
}
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);
}
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);
}
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))));
}
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));
}
Aggregations