Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Combination of Class Annotation and Method Annotation matching

Hello Takao -

Yours is a wonderful question beautifully stated.

There is more than one signature for func() (void Base.func() and void Derived.func()). 

  http://www.eclipse.org/aspectj/doc/released/adk15notebook/join-point-signatures.html#method-execution-join-point-signatures


One pointcut picks out one signature, and the other pointcut picks out the other signature.

We use multiple signatures because most users targeting a method also want to pick
out overrides of the method.  However, when the overriding method changes 
something about the signature (e.g., increasing access or refining the return type 
(in Java 5)),  then the different signatures of the one join point can match apparently 
disjoint pointcuts.  This violates the language principle of "least surprise" 
(particularly when coupled with uninherited annotations) and is one of the 
few subtleties of AspectJ.  

To pick out annotated method-execution in unannotated classes, try within(..):
  
  execution(@Annot * *(..)) && !within(@Annot *)

That worked, though it might be better style to use '!@within(Annot)' (untested by me).  
Using annotations in type patterns is not listed in the AspectJ 5 quick reference 
syntax but is discussed here:

  http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-pointcuts-and-advice.html#type-patterns

However, note that 'within(!@Annot *)' fails without warning, which I believe is a bug.

Thanks for the question!
Wes


> ------------Original Message------------
> From: "Takao Nakaguchi" <takao-n@xxxxxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Thu, Aug-10-2006 0:23 AM
> Subject: [aspectj-users] Combination of Class Annotation and Method Annotation matching
>
> Hi.
> 
> I have a question about annotation matching.
> Here is my test code.
> -----
> public aspect TestAspect {
> 	declare warning : execution(@Annot * (@Annot *).*(..)) : "ok!";
> 	declare warning : execution(@Annot * (!@Annot *).*(..)) : "ng!";
> }
> 
> @interface Annot{};
> 
> class Base{
> 	void func(){}
> }
> 
> @Annot
> class Derived extends Base{
> 	// ok! and ng!
> 	@Annot
> 	void func(){}
> }
> 
> class NoAnnotClass{
> 	// ng!
> 	@Annot
> 	void func(){}
> }
> -----
> See the message of Derived.func2.  This method seems to be affected by
> two inconsistent "declare warning" of TestAspect.
> Is that correct behavior? If so, how can I write a pointcut matching 
> for
> NoAnnotClass.func and not matching for Derived.func?
> 
> I'm using AJDT1.4.0(AspectJ1.5.2)
> 
> best regards.
> takao.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top