Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] target(object and al extending objects)

Ok, we've fixed your binding mechanism. One way of debugging what's going on is to have your advice print out thisJoinPoint.getTarget(); it will be null. Why? Because the target of a constructor call is always null. I don't think this is explicitly described in the programming guide, but Jim posted on a similar problem (see the thread Re: [aspectj-users] How to use "call pointcut", when using reflection).

One of the following approaches might work for you:
pointcut findConstructors(SuperClass superclass):
    	execution(SuperClass+.new(..)) && this(superclass);

Or:

after() returning (SuperClass obj): findConstructors () {
 	//do something with obj (type SuperClass, but I will cast it)
}

Besides, you undoubtedly want after returning advice, because if your constructor throws there will be no constructed object.

Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895

> ------------Original Message-------------
> From: MisterJ <misterj@xxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Fri, Sep-5-2003 9:08 AM
> Subject: Re: [aspectj-users] target(object and al extending objects)
> 
> Ron Bodkin wrote:
> > You're close:
> > pointcut findConstructors(SomeSuperClass superclass):
> >  	call(SomeSuperClass+.new(..)) && target(superclass);
> 
> This doesn't seem to work. It compiles, bit this pointcut finds nothing.
> 
> I have one superclass "SuperClass" and a few classes extending from that 
> superclass "ClassA", "ClassB", and so on.
> 
> In my application I never construct a SuperClass, I only have
> 
> ClassA a = new ClassA ();
> ClassB b = new ClassB ();
> ...
> so I never have (for example)
> SuperClass something = new ClassA ();
> 
> If I write this:
> 
> pointcut findConstructors () : call (SuperClass+.new(..));
> 
> after () : findConstructors () {
> 	//do something
> }
> 
> Everything works fine (the after advices is executed for every new 
> instance of ClassA, ClassB ...). But in that after advice I want to do 
> something with the object just constructed (of type ClassA, ClassB, ...).
> 
> Your suggestion is:
> 
> pointcut findConstructors(SuperClass superclass):
>    	call(SuperClass+.new(..)) && target(superclass);
> 
> with this advice:
> 
> after (SuperClass obj) : findConstructors (obj) {
> 	//do something with obj (type SuperClass, but I will cast it)
> }
> 
> That does compile, but it doesn't do anything. The after advice never gets 
> executed. My IDE (eclipse) also indicates that that is the case.
> 
> Am I missing something?
> Jan
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 


Back to the top