Bug 296501 - support optimized binding for execution join points and annotation string values
Summary: support optimized binding for execution join points and annotation string values
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.6   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: 1.6.7   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-30 13:19 EST by Andrew Clement CLA
Modified: 2010-05-20 11:20 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2009-11-30 13:19:41 EST
pointcut p(String s): execution(* *(..)) && @annotation(Log(s))

should be possible.  Currently it is only supported for enums
Comment 1 Andrew Clement CLA 2009-11-30 16:01:48 EST
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.
Comment 2 Stephen Smith CLA 2010-05-19 11:55:42 EDT
(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?
Comment 3 Stephen Smith CLA 2010-05-19 12:06:55 EDT
(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
Comment 4 Andrew Clement CLA 2010-05-19 12:15:46 EDT
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.
Comment 5 Stephen Smith CLA 2010-05-19 12:29:25 EDT
(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.
Comment 6 Andrew Clement CLA 2010-05-19 13:05:30 EDT
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)
Comment 7 Stephen Smith CLA 2010-05-20 04:36:35 EDT
(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?
Comment 8 Andrew Clement CLA 2010-05-20 11:20:22 EDT
If you don't need the annotation, you just want to make sure it is there, then move it into execution:

> @Pointcut("execution(@Log * *(..))")