net.bytebuddy.description.method.ParameterList Java Examples
The following examples show how to use
net.bytebuddy.description.method.ParameterList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MethodAttributeAppenderForInstrumentedMethodOtherTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testReceiverTypeTypeAnnotationsNoRetention() throws Exception { when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<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(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(methodDescription.getReceiverType()).thenReturn(simpleAnnotatedType); when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Qux.Instance())); MethodAttributeAppender.ForInstrumentedMethod.INCLUDING_RECEIVER.apply(methodVisitor, methodDescription, annotationValueFilter); verifyZeroInteractions(methodVisitor); verify(methodDescription).getDeclaredAnnotations(); verify(methodDescription).getParameters(); verify(methodDescription).getReturnType(); verify(methodDescription).getExceptionTypes(); verify(methodDescription).getTypeVariables(); verify(methodDescription).getReceiverType(); verifyNoMoreInteractions(methodDescription); }
Example #2
Source File: MethodCall.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * Resolves this appender to a stack manipulation. * * @param instrumentedMethod The instrumented method. * @param invokedMethod The invoked method. * @param targetHandler The resolved target handler to base the stack manipulation upon. * @return A stack manipulation that represents this method call. */ protected StackManipulation toStackManipulation(MethodDescription instrumentedMethod, MethodDescription invokedMethod, TargetHandler.Resolved targetHandler) { List<ArgumentLoader> argumentLoaders = new ArrayList<ArgumentLoader>(); for (ArgumentLoader.ArgumentProvider argumentProvider : argumentProviders) { argumentLoaders.addAll(argumentProvider.resolve(instrumentedMethod, invokedMethod)); } ParameterList<?> parameters = invokedMethod.getParameters(); if (parameters.size() != argumentLoaders.size()) { throw new IllegalStateException(invokedMethod + " does not accept " + argumentLoaders.size() + " arguments"); } Iterator<? extends ParameterDescription> parameterIterator = parameters.iterator(); List<StackManipulation> argumentInstructions = new ArrayList<StackManipulation>(argumentLoaders.size()); for (ArgumentLoader argumentLoader : argumentLoaders) { argumentInstructions.add(argumentLoader.toStackManipulation(parameterIterator.next(), assigner, typing)); } return new StackManipulation.Compound( targetHandler.toStackManipulation(invokedMethod, assigner, typing), new StackManipulation.Compound(argumentInstructions), methodInvoker.toStackManipulation(invokedMethod, implementationTarget), terminationHandler.toStackManipulation(invokedMethod, instrumentedMethod, assigner, typing) ); }
Example #3
Source File: FieldValueBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testGetterNameDiscoveryBoolean() throws Exception { doReturn(void.class).when(annotation).declaringType(); when(annotation.value()).thenReturn(FieldValue.Binder.Delegate.BEAN_PROPERTY); when(instrumentedType.getDeclaredFields()).thenReturn(new FieldList.Explicit<FieldDescription.InDefinedShape>(fieldDescription)); when(fieldDescription.getActualName()).thenReturn(FOO); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); when(target.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(stackManipulation.isValid()).thenReturn(true); when(source.getInternalName()).thenReturn("isFoo"); when(source.getActualName()).thenReturn("isFoo"); when(source.getReturnType()).thenReturn(TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(boolean.class)); when(source.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); MethodDelegationBinder.ParameterBinding<?> binding = FieldValue.Binder.INSTANCE.bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #4
Source File: FieldProxyBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testSetterForExplicitNamedFieldInNamedType() throws Exception { when(target.getType()).thenReturn(genericSetterType); doReturn(Foo.class).when(annotation).declaringType(); when(instrumentedType.isAssignableTo(TypeDescription.ForLoadedType.of(Foo.class))).thenReturn(true); when(annotation.value()).thenReturn(FOO); when(fieldDescription.getActualName()).thenReturn(FOO); when(source.getReturnType()).thenReturn(TypeDescription.Generic.VOID); when(source.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(source, fieldType)); when(source.getName()).thenReturn("setFoo"); when(source.getInternalName()).thenReturn("setFoo"); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); MethodDelegationBinder.ParameterBinding<?> binding = new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #5
Source File: FieldProxyBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testSetterForImplicitNamedFieldInHierarchy() throws Exception { when(target.getType()).thenReturn(genericSetterType); doReturn(void.class).when(annotation).declaringType(); when(annotation.value()).thenReturn(FieldProxy.Binder.BEAN_PROPERTY); when(fieldDescription.getActualName()).thenReturn(FOO); when(source.getReturnType()).thenReturn(TypeDescription.Generic.VOID); when(source.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(source, fieldType)); when(source.getActualName()).thenReturn("setFoo"); when(source.getInternalName()).thenReturn("setFoo"); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); MethodDelegationBinder.ParameterBinding<?> binding = new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #6
Source File: FieldProxyBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testGetterForImplicitNamedFieldInNamedType() throws Exception { when(target.getType()).thenReturn(genericGetterType); doReturn(Foo.class).when(annotation).declaringType(); when(instrumentedType.isAssignableTo(TypeDescription.ForLoadedType.of(Foo.class))).thenReturn(true); when(annotation.value()).thenReturn(FieldProxy.Binder.BEAN_PROPERTY); when(fieldDescription.getInternalName()).thenReturn(FOO); when(source.getReturnType()).thenReturn(genericFieldType); when(source.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); when(source.getName()).thenReturn("getFoo"); when(source.getActualName()).thenReturn("getFoo"); when(source.getInternalName()).thenReturn("getFoo"); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); MethodDelegationBinder.ParameterBinding<?> binding = new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #7
Source File: AllArgumentsBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
private void testLegalStrictBinding(Assigner.Typing typing) throws Exception { when(annotation.value()).thenReturn(AllArguments.Assignment.STRICT); when(stackManipulation.isValid()).thenReturn(true); when(source.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(source, firstSourceType, secondSourceType)); when(source.isStatic()).thenReturn(false); when(targetType.isArray()).thenReturn(true); when(targetType.getComponentType()).thenReturn(componentType); when(componentType.getStackSize()).thenReturn(StackSize.SINGLE); when(target.getType()).thenReturn(targetType); MethodDelegationBinder.ParameterBinding<?> parameterBinding = AllArguments.Binder.INSTANCE .bind(annotationDescription, source, target, implementationTarget, assigner, typing); assertThat(parameterBinding.isValid(), is(true)); verify(source, atLeast(1)).getParameters(); verify(source, atLeast(1)).isStatic(); verify(target, atLeast(1)).getType(); verify(target, never()).getDeclaredAnnotations(); verify(assigner).assign(firstSourceType, componentType, typing); verify(assigner).assign(secondSourceType, componentType, typing); verifyNoMoreInteractions(assigner); }
Example #8
Source File: AllArgumentsBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testIllegalBinding() throws Exception { when(target.getIndex()).thenReturn(1); when(annotation.value()).thenReturn(AllArguments.Assignment.STRICT); when(stackManipulation.isValid()).thenReturn(false); when(source.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(source, firstSourceType, secondSourceType)); when(source.isStatic()).thenReturn(false); when(targetType.isArray()).thenReturn(true); when(targetType.getComponentType()).thenReturn(componentType); when(componentType.getStackSize()).thenReturn(StackSize.SINGLE); when(target.getType()).thenReturn(targetType); when(target.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); MethodDelegationBinder.ParameterBinding<?> parameterBinding = AllArguments.Binder.INSTANCE .bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(parameterBinding.isValid(), is(false)); verify(source, atLeast(1)).getParameters(); verify(source, atLeast(1)).isStatic(); verify(target, atLeast(1)).getType(); verify(target, never()).getDeclaredAnnotations(); verify(assigner).assign(firstSourceType, componentType, Assigner.Typing.STATIC); verifyNoMoreInteractions(assigner); }
Example #9
Source File: FieldProxyBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testGetterForExplicitNamedFieldInHierarchy() throws Exception { when(target.getType()).thenReturn(genericGetterType); doReturn(void.class).when(annotation).declaringType(); when(annotation.value()).thenReturn(FOO); when(fieldDescription.getActualName()).thenReturn(FOO); when(source.getReturnType()).thenReturn(genericFieldType); when(source.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); when(source.getName()).thenReturn("getFoo"); when(source.getInternalName()).thenReturn("getFoo"); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); MethodDelegationBinder.ParameterBinding<?> binding = new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #10
Source File: FieldProxyBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testGetterForImplicitNamedFieldInHierarchy() throws Exception { when(target.getType()).thenReturn(genericGetterType); doReturn(void.class).when(annotation).declaringType(); when(annotation.value()).thenReturn(FieldProxy.Binder.BEAN_PROPERTY); when(fieldDescription.getActualName()).thenReturn(FOO); when(source.getReturnType()).thenReturn(genericFieldType); when(source.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); when(source.getName()).thenReturn("getFoo"); when(source.getActualName()).thenReturn("getFoo"); when(source.getInternalName()).thenReturn("getFoo"); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); MethodDelegationBinder.ParameterBinding<?> binding = new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #11
Source File: TypeProxyCreationTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { for (ModifierContributor modifierContributor : AuxiliaryType.DEFAULT_TYPE_MODIFIER) { modifiers = modifiers | modifierContributor.getMask(); } foo = TypeDescription.ForLoadedType.of(Foo.class); fooMethods = MethodGraph.Compiler.DEFAULT.compile(foo) .listNodes() .asMethodList() .filter(isVirtual().and(not(isFinal())).and(not(isDefaultFinalizer()))); when(proxyMethod.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(proxyMethod, foo, foo, foo)); when(proxyMethod.getDeclaringType()).thenReturn(foo); when(proxyMethod.getInternalName()).thenReturn(FOO); when(proxyMethod.getDescriptor()).thenReturn(FOO); when(proxyMethod.getReturnType()).thenReturn(TypeDescription.Generic.OBJECT); when(proxyMethod.asDefined()).thenReturn(proxyMethod); }
Example #12
Source File: FieldProxyBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testGetterForExplicitNamedFieldInNamedType() throws Exception { when(target.getType()).thenReturn(genericGetterType); doReturn(Foo.class).when(annotation).declaringType(); when(instrumentedType.isAssignableTo(TypeDescription.ForLoadedType.of(Foo.class))).thenReturn(true); when(annotation.value()).thenReturn(FOO); when(fieldDescription.getInternalName()).thenReturn(FOO); when(source.getReturnType()).thenReturn(genericFieldType); when(source.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); when(source.getName()).thenReturn("getFoo"); when(source.getInternalName()).thenReturn("getFoo"); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); MethodDelegationBinder.ParameterBinding<?> binding = new FieldProxy.Binder(getterMethod, setterMethod).bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #13
Source File: FieldValueBinderTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test public void testSetterNameDiscovery() throws Exception { doReturn(void.class).when(annotation).declaringType(); when(annotation.value()).thenReturn(FieldValue.Binder.Delegate.BEAN_PROPERTY); when(instrumentedType.getDeclaredFields()).thenReturn(new FieldList.Explicit<FieldDescription.InDefinedShape>(fieldDescription)); when(fieldDescription.getActualName()).thenReturn(FOO); when(fieldDescription.isVisibleTo(instrumentedType)).thenReturn(true); when(target.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(stackManipulation.isValid()).thenReturn(true); when(source.getInternalName()).thenReturn("setFoo"); when(source.getActualName()).thenReturn("setFoo"); when(source.getReturnType()).thenReturn(TypeDescription.Generic.VOID); when(source.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(source, TypeDescription.Generic.OBJECT)); MethodDelegationBinder.ParameterBinding<?> binding = FieldValue.Binder.INSTANCE.bind(annotationDescription, source, target, implementationTarget, assigner, Assigner.Typing.STATIC); assertThat(binding.isValid(), is(true)); }
Example #14
Source File: MethodInvocationHandleTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { when(methodDescription.asDefined()).thenReturn(methodDescription); when(methodDescription.getReturnType()).thenReturn(returnType); when(methodDescription.getDeclaringType()).thenReturn(declaringType); when(returnType.getStackSize()).thenReturn(StackSize.ZERO); when(firstType.getStackSize()).thenReturn(StackSize.ZERO); when(firstType.getDescriptor()).thenReturn(FOO); when(secondType.getDescriptor()).thenReturn(BAR); when(secondType.getStackSize()).thenReturn(StackSize.ZERO); when(returnType.getStackSize()).thenReturn(StackSize.ZERO); when(methodDescription.getInternalName()).thenReturn(QUX); when(methodDescription.getDescriptor()).thenReturn(BAZ); when(declaringType.getDescriptor()).thenReturn(BAR); when(methodDescription.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(methodDescription, firstType, secondType)); }
Example #15
Source File: MethodAttributeAppenderForInstrumentedMethodOtherTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testReceiverTypeTypeAnnotationsIgnored() throws Exception { when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<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(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(methodDescription.getReceiverType()).thenReturn(simpleAnnotatedType); when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance())); MethodAttributeAppender.ForInstrumentedMethod.EXCLUDING_RECEIVER.apply(methodVisitor, methodDescription, annotationValueFilter); verifyZeroInteractions(methodVisitor); verify(methodDescription).getDeclaredAnnotations(); verify(methodDescription).getParameters(); verify(methodDescription).getReturnType(); verify(methodDescription).getExceptionTypes(); verify(methodDescription).getTypeVariables(); verifyNoMoreInteractions(methodDescription); }
Example #16
Source File: MethodVariableAccessOfMethodArgumentsTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { when(methodDescription.getDeclaringType()).thenReturn(declaringType); when(declaringType.getStackSize()).thenReturn(StackSize.SINGLE); when(firstParameterType.getStackSize()).thenReturn(StackSize.SINGLE); when(firstParameterType.asErasure()).thenReturn(firstRawParameterType); when(firstParameterType.asGenericType()).thenReturn(firstParameterType); when(secondParameterType.asErasure()).thenReturn(secondRawParameterType); when(secondParameterType.getStackSize()).thenReturn(StackSize.SINGLE); when(secondParameterType.asGenericType()).thenReturn(secondParameterType); when(methodDescription.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(methodDescription, firstParameterType, secondParameterType)); when(bridgeMethod.getDeclaringType()).thenReturn(declaringType); when(secondRawParameterType.getInternalName()).thenReturn(FOO); when(firstParameterType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(firstParameterType); when(secondParameterType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(secondParameterType); }
Example #17
Source File: MethodAttributeAppenderForInstrumentedMethodOtherTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testReceiverTypeTypeAnnotationsRuntimeRetention() throws Exception { when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<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(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(methodDescription.getReceiverType()).thenReturn(simpleAnnotatedType); when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance())); MethodAttributeAppender.ForInstrumentedMethod.INCLUDING_RECEIVER.apply(methodVisitor, methodDescription, annotationValueFilter); verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeReference(TypeReference.METHOD_RECEIVER).getValue(), null, Type.getDescriptor(AbstractAttributeAppenderTest.Baz.class), true); verifyNoMoreInteractions(methodVisitor); verify(methodDescription).getDeclaredAnnotations(); verify(methodDescription).getParameters(); verify(methodDescription).getReturnType(); verify(methodDescription).getExceptionTypes(); verify(methodDescription).getTypeVariables(); verify(methodDescription).getReceiverType(); verifyNoMoreInteractions(methodDescription); }
Example #18
Source File: ConstructorStrategyDefaultTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testDefaultConstructorStrategyWithAttributeAppender() throws Exception { when(methodDescription.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InGenericShape>()); MethodAttributeAppender.Factory methodAttributeAppenderFactory = mock(MethodAttributeAppender.Factory.class); ConstructorStrategy constructorStrategy = ConstructorStrategy.Default.DEFAULT_CONSTRUCTOR.with(methodAttributeAppenderFactory); assertThat(constructorStrategy.extractConstructors(instrumentedType), is(Collections.singletonList(new MethodDescription.Token(Opcodes.ACC_PUBLIC)))); assertThat(constructorStrategy.inject(instrumentedType, methodRegistry), is(methodRegistry)); verify(methodRegistry).append(any(LatentMatcher.class), any(MethodRegistry.Handler.class), eq(methodAttributeAppenderFactory), eq(Transformer.NoOp.<MethodDescription>make())); verifyNoMoreInteractions(methodRegistry); verify(instrumentedType).getSuperClass(); verifyNoMoreInteractions(instrumentedType); }
Example #19
Source File: RebaseImplementationTargetTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { when(methodGraph.locate(Mockito.any(MethodDescription.SignatureToken.class))).thenReturn(MethodGraph.Node.Unresolved.INSTANCE); when(instrumentedType.getSuperClass()).thenReturn(superClass); when(superClass.asErasure()).thenReturn(rawSuperClass); when(rawSuperClass.getInternalName()).thenReturn(BAR); when(rebasedMethod.getInternalName()).thenReturn(QUX); when(rebasedMethod.asToken(ElementMatchers.is(instrumentedType))).thenReturn(rebasedToken); when(rebasedMethod.getDescriptor()).thenReturn(FOO); when(rebasedMethod.asDefined()).thenReturn(rebasedMethod); when(rebasedMethod.getReturnType()).thenReturn(genericReturnType); when(rebasedMethod.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); when(rebasedMethod.getDeclaringType()).thenReturn(instrumentedType); when(rebasedMethod.asSignatureToken()).thenReturn(rebasedSignatureToken); super.setUp(); }
Example #20
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@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); }
Example #21
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testMethodReturnTypeTypeAnnotationRuntimeRetention() throws Exception { when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true); when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>()); when(methodDescription.getReturnType()).thenReturn(simpleAnnotatedType); 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.newTypeReference(TypeReference.METHOD_RETURN).getValue(), null, Type.getDescriptor(Baz.class), true); verifyNoMoreInteractions(methodVisitor); }
Example #22
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testMethodReturnTypeTypeAnnotationClassFileRetention() throws Exception { when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true); when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>()); when(methodDescription.getReturnType()).thenReturn(simpleAnnotatedType); 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.newTypeReference(TypeReference.METHOD_RETURN).getValue(), null, Type.getDescriptor(QuxBaz.class), false); verifyNoMoreInteractions(methodVisitor); }
Example #23
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testJdkTypeIsFiltered() throws Exception { when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true); AnnotationDescription annotationDescription = mock(AnnotationDescription.class); TypeDescription annotationType = mock(TypeDescription.class); when(annotationType.getDeclaredMethods()).thenReturn(new MethodList.Empty<MethodDescription.InDefinedShape>()); when(annotationDescription.getRetention()).thenReturn(RetentionPolicy.RUNTIME); when(annotationDescription.getAnnotationType()).thenReturn(annotationType); when(annotationType.getActualName()).thenReturn("jdk.internal.Sample"); when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Explicit(annotationDescription)); when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<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); }
Example #24
Source File: ConstructorStrategyDefaultTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testDefaultConstructorStrategyWithInheritedAnnotations() throws Exception { when(methodDescription.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InGenericShape>()); ConstructorStrategy constructorStrategy = ConstructorStrategy.Default.DEFAULT_CONSTRUCTOR.withInheritedAnnotations(); assertThat(constructorStrategy.extractConstructors(instrumentedType), is(Collections.singletonList(new MethodDescription.Token(Opcodes.ACC_PUBLIC)))); assertThat(constructorStrategy.inject(instrumentedType, methodRegistry), is(methodRegistry)); verify(methodRegistry).append(any(LatentMatcher.class), any(MethodRegistry.Handler.class), eq(MethodAttributeAppender.ForInstrumentedMethod.EXCLUDING_RECEIVER), eq(Transformer.NoOp.<MethodDescription>make())); verifyNoMoreInteractions(methodRegistry); verify(instrumentedType).getSuperClass(); verifyNoMoreInteractions(instrumentedType); }
Example #25
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testMethodExceptionTypeTypeAnnotationClassFileRetention() throws Exception { when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true); when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>()); when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID); when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty()); when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Explicit(simpleAnnotatedType)); when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance())); methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter); verify(methodVisitor).visitTypeAnnotation(TypeReference.newExceptionReference(0).getValue(), null, Type.getDescriptor(QuxBaz.class), false); verifyNoMoreInteractions(methodVisitor); }
Example #26
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@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); }
Example #27
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@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); }
Example #28
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@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); }
Example #29
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testTypeVariableTypeAnnotations() throws Exception { when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance())); when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance())); when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>()); when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID); when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(annotatedTypeVariable)); when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty()); when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter); verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.METHOD_TYPE_PARAMETER, 0).getValue(), null, Type.getDescriptor(QuxBaz.class), false); verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.METHOD_TYPE_PARAMETER_BOUND, 0, 0).getValue(), null, Type.getDescriptor(QuxBaz.class), false); verifyNoMoreInteractions(methodVisitor); }
Example #30
Source File: MethodAttributeAppenderForInstrumentedMethodTest.java From byte-buddy with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testTypeVariableTypeAnnotationRuntimeRetention() throws Exception { when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance())); when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance())); when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>()); when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID); when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(annotatedTypeVariable)); when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty()); when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty()); methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter); verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.METHOD_TYPE_PARAMETER, 0).getValue(), null, Type.getDescriptor(Baz.class), true); verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.METHOD_TYPE_PARAMETER_BOUND, 0, 0).getValue(), null, Type.getDescriptor(Baz.class), true); verifyZeroInteractions(methodVisitor); }