[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Advice on Constructors With Subclasses

In trying to achieve the same results after an object has been
constructed using reflection, I have run into a wall.

I can't use the call joinpoints for this case, since the pointcut
obviously won't match on the newInstance() call, not to mention the
client code weaving that Simone was talking about.

I have tried using initialization joinpoints as Andrew suggested, but
I keep running into the same problems that I had in my original
posting, namely, the advice is being run after every super call.

My first thought was to advise calls to Class.newInstance() as well,
but this is problematic because some of the calls are being made from
an external library that I am using, and I can't advise calls within
that library.  Similarly, I can't advise the execution of
newInstance() because that would be advising the standard library.

My current pointcut looks like this:
after(A a) returning: initialization(A+.new(..)) && this(a) {
    System.out.println(thisJoinPoint.getSourceLocation());
}

And the output is back to the same as it was in my original question,
for both normal construction, and reflection-style construction.

Any suggestions?