Community
Participate
Working Groups
pointcut p(String s): execution(* *(..)) && @annotation(Log(s)) should be possible. Currently it is only supported for enums
whoa this is fast! Manually fetching annotation with getAnnotation(): 645ms Binding annotation with @annotation(Marker): 445ms Binding annotation value with @annotation(Marker(message)): 3ms see Perf.java in the pr296484 folder as the example that gives these numbers.
(In reply to comment #0) > pointcut p(String s): execution(* *(..)) && @annotation(Log(s)) > > should be possible. Currently it is only supported for enums Andy, what would this look example look like in Spring @After -> @Pointcut syntax?
(In reply to comment #2) > (In reply to comment #0) > > pointcut p(String s): execution(* *(..)) && @annotation(Log(s)) > > > > should be possible. Currently it is only supported for enums > > Andy, what would this look example look like in Spring @After -> @Pointcut > syntax? Argh, forgot to say - Spring 2.5.4
Annotation style is like this: @Pointcut("execution(* *(..)) && @annotation(Log(s))") public void p(String s) {} @After("p(s)") public void foo(String s) { System.out.println(s); } I presumed that this would just work for Spring (I'll admit I haven't tried it)- but you will need to be using a more up to date weaver than the one included in 2.5.4 I think. I think the most recent 2.5 release (is it 2.5.6?) includes AspectJ 1.6.8.
(In reply to comment #4) > Annotation style is like this: > > @Pointcut("execution(* *(..)) && @annotation(Log(s))") > public void p(String s) {} > > @After("p(s)") > public void foo(String s) { > System.out.println(s); > } > > I presumed that this would just work for Spring (I'll admit I haven't tried > it)- but you will need to be using a more up to date weaver than the one > included in 2.5.4 I think. I think the most recent 2.5 release (is it 2.5.6?) > includes AspectJ 1.6.8. I will try the above, thanks. Am I right in saying that the name of the Log annotation property ("message" in your Perf.java example) is unimportant, and that Log needs to be package qualified if it is outside the class? 2.5.4 is bundled with 1.6.0, I have manually upgraded to 1.6.8 but encountered #298786. Have updated that bug and am working around that.
Yes, the annotation type (eg. Log) would need to be fully qualified inside the pointcut text if not in the same package (or default package)
(In reply to comment #6) > Yes, the annotation type (eg. Log) would need to be fully qualified inside the > pointcut text if not in the same package (or default package) What if I don't need the annotated field (In reply to comment #4) > Annotation style is like this: > > @Pointcut("execution(* *(..)) && @annotation(Log(s))") > public void p(String s) {} > > @After("p(s)") > public void foo(String s) { > System.out.println(s); > } > > I presumed that this would just work for Spring (I'll admit I haven't tried > it)- but you will need to be using a more up to date weaver than the one > included in 2.5.4 I think. I think the most recent 2.5 release (is it 2.5.6?) > includes AspectJ 1.6.8. What if I don't need the annotation field s as a parameter? Can I ignore it and use an args pointcut to obtain bound method parameters as normal?
If you don't need the annotation, you just want to make sure it is there, then move it into execution: > @Pointcut("execution(@Log * *(..))")