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

Hi

Thanks again Wes!
I could do what I wanted and get my understanding about aspectj deeper.

Logging weaver info may enough to get information about join point signatures.
I couldn't get the information using option "showWeaveInfo", so wrote an aspect
below.
-----
public aspect SignaturePrintAspect {
	after(Member m, World w) returning(boolean matched):
		execution(boolean SignaturePattern.matches(..))
		&& args(m, w, ..)
	{
		if(!matched || (matchedSig == null)) return;
		System.out.println("signatures for metched(*) join point \"" + m + "\"");
		Iterator i = m.getJoinPointSignatures(w);
		while(i.hasNext()){
			Object sig = i.next();
			System.out.println("signature"
					+ ((matchedSig == sig) ? "(*)" : "")
					+ ": \"" + sig + "\"");
		}
		matchedSig = null;
	}

	after(JoinPointSignature sig) returning(FuzzyBoolean matched):
		call(FuzzyBoolean SignaturePattern.matchesExactly(..))
		&& withincode(boolean SignaturePattern.matches(..))
		&& args(sig, ..)
	{
		if(matched.alwaysTrue()){
			matchedSig = sig;
		}
	}

	private JoinPointSignature matchedSig;
}
----
Using both this aspect and showWeaveInfo option, I could get
the log below:
----
    [iajc] signatures for metched(*) join point "void test.Derived.func()"
    [iajc] signature: "void test.Derived.func()"
    [iajc] signature(*): "void test.Base.func()"
    [iajc] weaveinfo Join point 'method-execution(void
test.Derived.func())' in Type 'test.Derived' (Test.aj:18) advised by
before advice from 'test.Test' (Test.aj:4)
----

And the behavior for private modifier could be easily confirmed by above aspect.
(Actually Base class extends BaseBase class which has method "private
void func(){}")

regards
takao.

2006/8/11, Wes <wes@xxxxxxxxxxxxxx>:
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
>

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top