[aspectc-user] inheritance of advice code

Panu Bloigu panu.bloigu at gmail.com
Thu Oct 4 10:15:55 CEST 2007


Hello.

I wonder I anyone would care to suggest an approach to solve the 
following problem I have.

In short, what I want to do is to prevent an execution advice from 
affecting the descendant classes. The longer version of the problem follows.

Let's consider, for instance, that I have a class named A with a method 
m() defined in it. Then I have an aspect with the following advice:

advice execution("void A::m()") : before() {/* code here */}

The problem here is that now, if I derive a class from the class A 
without overriding the method m(), every time I call the method m() on 
an instance of the derived class, the code in the above advice gets 
executed. My question is that how do I prevent this from happening (or, 
is it even possible) without having to override the method m() in the 
descendant classes?

I would think that using that() pointcut function would do the trick:

advice execution("void A::m()") && that("A") : before(){/* code here */}

but, alas, that's not the case, as that("A") selects every join point 
where 'this' pointer points to an instance of the class A *or any of 
it's descendants*. Also, using the pointcut function derived() doesn't work:

advice execution("void A::m()") && that(!derived("A")) : before(){/* 
code here */}

as it considers the class A to be a descendant of itself, i.e. the above 
pointcut description will exclude the execution of the method m() in the 
class A too, which is not what I want. Of course this could probably be 
solved by inserting some RTTI code in the execution advice to make sure 
that the advice code is executed only in the (runtime) context of class 
A, and none of its descendants, but I would like to know if this can be 
done with AspectC++ code only.

Thanks in advance,

-- Panu.








More information about the aspectc-user mailing list