5

Consider this method:

@Access(rights = GUEST)
public void foo() {
  doSomething();
}

This pointcut basically matches if the method has an @Access annotation:

pointcut check() : 
execution(@Access * *(..));

But how can I access the field rights of @Access, which stores the particular access level, so that I can work with it?

soc
  • 27,983
  • 20
  • 111
  • 215

1 Answers1

8

Try to use:

pointcut check(Access access) : 
execution(@Access * *(..)) && @annotation(access);

See documentation here.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • Cool! This seems to do it. What's the reason I need both? – soc Jul 20 '11 at 12:28
  • `execution` describes your join point and `@annotation` is a pointcut to collect join point context. You can't collect content without defining join point. So `@annotation` requires `execution` (or `call` or something else). – Constantiner Jul 20 '11 at 12:40
  • Ahh ok. So I need execution, but the argument could be something completely unrelated like a method name, too? – soc Jul 20 '11 at 13:37
  • THere can be a lot of different combinations of join points and context collecting pointcuts. You can collect method arguments, annotations of arguments, `this` or `target` etc. It is better to read documentation carefully. It contains a lot of samples. – Constantiner Jul 20 '11 at 13:42