Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] intercept Class but not SubClass

Ok.  Starting to answer my own question but actually _reading_ the FAQ.

http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq.html#q:adviseconstructors

Little bit down the page it tell of using "returning" instead of getTarget()
because you are still outside the object creation.

Tested it out, works great.


Charlie



Charles N. Harvey III said the following on 6/10/2004 9:40 AM:

Ron,
First, thanks for the tip yesterday, very slick. Every day that I learn more AspectJ
I marvel at how code can be written so elegantly.

Second, I have a question about the difference between call and execution. I want to be using call because I want my aspect to intercept into the calling class, not the class that is getting executed. That said, does call return the instantiated object?
I tried running:

public aspect MyAspect
{
   pointcut myIntercept() : call( MyClass.new() ) &&
                            !within( MyAspect ) &&
                            !this( MySubClass.new() );

   after() : myIntercept()
   {
       MyClass mc = (MyClass)thisJoinPoint.getTarget();
   }
}

But when I "getTarget()" the object is null. Is this because only the call has been made and the object hasn't actually been created yet. That is what I am lead to believe. I used execution but after reading the FAQ entry I see that my intercept is going into
MyClass and not the class that is calling MyClass.

Should I be using "initialization" instead? I want the aspect placed in the calling class but I need to use the instance of the object that I am making a call to. Does this make
sense?  I think I am confusing myself.

Thanks again.


Charlie




Ron Bodkin said the following on 6/9/2004 7:45 PM:

See also the a FAQ entry on the differences between call and execution join points to determine which is the right one to use in a given scenario: http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/faq.html#q:comparecallandexecution

------------Original Message------------
From: Wes Isberg <wes@xxxxxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Wed, Jun-9-2004 4:10 PM
Subject: Re: [aspectj-users] intercept Class but not SubClass

To add to what's said,

  call(MyClass.new())

will pick out a constructor-call join point
but not the corresponding constructor-execution join point,
which as Ron points out runs when subclasses are being
initialized.

(As for what the pointcuts mean, I encourage you{/me/everyone}
to closely read the programming guide semantics appendix.
30-90 minutes spent really absorbing those definitions will
pay off a lot in avoiding common mistakes.)

Wes

Charles N. Harvey III wrote:
Hello.
I have written a simple aspect to run after MyClass.new is executed.
Thing is, I also have MySubClass which extends MyClass. And the aspect
seems to be intercepting that as well.

public pointcut myCutting() : execution( MyClass.new() ) && !execution( MySubClass.new() );


That doesn't seem to be doing it. Is that correct or is there some other
way to make sure that no sub-classes get intercepted?

Thanks a lot.


Charlie

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


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



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


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




Back to the top