Reputation: 28423
I'd like to match a method like this:
@Foo
public void boo(@Baz Bar bar) { ... }
Basically:
@Foo
annotation (which I match with execution(@Foo * *(..)) && @annotation(foo)
),@Baz
annotation,bar
).If a method has a @Foo annotation but is missing a @Baz
annotation, I want to get an error as early as possible, if possible when weaving and not at runtime.
How can I do that?
Upvotes: 2
Views: 846
Reputation: 2208
public pointcut annArg(): execution(@Foo * *(.., @Baz (*),..));
declare error :execution(@Foo * *(..))&&!annArg() :"error";
Unfortunatly it is impossible to grab matched argument by args(..,arg,..). But you can use thisJoinPoint.getArgs() and reflection API to get the annotated argument. Or if you know the position of the argument you can use something like args(..,arg);
Upvotes: 2