[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

Hi -

> Is there any way to get actually adviced signature info?

Not in the runtime API.

These are weave-time constructs; the runtime signatures of the join points
are used to identify the join point and don't contain all the information
used at weave-time (e.g., modifiers).  You might try enabling logging for
the weaver (sorry, no pointers on that right now) to see if when it is
working on a join point they log the signatures being matched.   OTW, the
enhancement request would be to log that.

As far as I know, since only methods are overridden, only method-execution 
and method-call have multiple signatures.  The signatures are simply 
the chain of inherited methods.  (e.g., if a method is private and a 
subclass implements the "same" method as public, it's not inherited or
overriding, so that signature is not relevant.)

Hope this helps -
Wes

> ------------Original Message------------
> From: "Takao Nakaguchi" <takao-n@xxxxxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Thu, Aug-10-2006 9:00 AM
> Subject: Re: [aspectj-users] Combination of Class Annotation and Method Annotation matching
>
> Many thanks Wes!
> I could do what I wanted by using !within(@Annot *).
> 
> It is very interesting that one join point can have multiple 
> signatures.
> And I could understand why the expression "@Annot * (@Annot *).*(..)"
> is not suitable for my needs.
> But that brings me another question.
> Is there any way to get actually adviced signature info?
> I checked API, but couldn't find the way.
> ----
> public aspect Test {
> 	before(): execution(void Base.func()){
> 		System.out.println(thisJoinPoint);
> 	}
> 
> 	public static void main(String[] args){
> 		new Derived().func();
> 	}
> }
> 
> class Base{
> 	void func(){}
> }
> 
> class Derived extends Base{
> 	void func(){}
> }
> -----
> Above codes printed "void test.Derived2.func()".
> thisJoinPoint.getSignature() seems to return signature of
> Derived.func(not Base.func).
> If there was no way to get actually adviced signature, I will post
> enhancement request
> such like JoinPoint.getAdvicedSignatures() and
> JoinPoint.StaticPart.getSignatures()
> to bugzilla.
> 
> 
> thanks.
> takao.
> 
> 2006/8/10, Wes <wes@xxxxxxxxxxxxxx>:
> > 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
> > >
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>