0

For example I have following methods:

public void method1(@MyAnnotation Object a, Object b..) { ... } public void method1(Object a, Object b..., @MyAnnotation Object n, ...) { ... } 

What is AspectJ pointcut that targets only methods that have parameters annotated with @MyAnnotation?

This annotation can be applied for ANY argument of the method.

1 Answer 1

3

The following pointcut should match the execution of methods in your question. I also provided a second pointcut which is only a slight modification of the first one, but you might find it useful if you need to match specific types annotated with an annotation.

public aspect AnnotatedMethodParameterMatchingAspect { /** * Matches the execution of any method having a parameter annotated with the * {@link MyAnnotation} annotation. */ pointcut executionOfMethodWithAnnotatedParameter(): execution(* *(.., @MyAnnotation (*), ..)); /** * Matches the execution of any method having a parameter annotated with the * {@link MyAnnotation} annotation where the parameter type is a {@link MyType} * (or a subtype). */ pointcut executionOfMethodWithAnnotatedTypeRestrictedParameter(): execution(* *(.., @MyAnnotation (MyType+), ..)); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.