[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Overriding pointcuts

That?s not how I read the programmer?s guide. From

"Pointcuts that are not final may be declared abstract, and defined without
a body. Abstract pointcuts may only be declared within abstract aspects. 
  abstract aspect A {
      abstract pointcut publicCall(int i);

In such a case, an extending aspect may override the abstract pointcut. 
  aspect B extends A {
      pointcut publicCall(int i): call(public Foo.m(int)) && args(i);
For completeness, a pointcut with a declaration may be declared final. 

Though named pointcut declarations appear somewhat like method declarations,
and can be overridden in subaspects, they cannot be overloaded. It is an
error for two pointcuts to be named with the same name in the same class or
aspect declaration. "

Notice that pointcut declarations can be overridden in subaspects. The
sentence does not limit them to abstract pointcuts.

Moreover, the feature works as I read the description and I have found it
useful as in my earlier posting about how I used pointcut overriding for the
glassbox inspector. Here is a simple xample:

public abstract aspect Base {
    public pointcut methodExec();
    before() : methodExec() {
	System.out.println("advised by "+this);

    public static void main(String args[]) {}

aspect Derived1 extends Base {
    public pointcut methodExec() : execution(* main(..));

aspect Derived2 extends Base {}

C:\devel\scratch\override>ajc Base.aj

C:\devel\scratch\override>java Base
advised by Derived1@12c1c0

From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Wes Isberg
Sent: Friday, October 21, 2005 10:56 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Overriding pointcuts

Also, Pointcuts are like static methods: they can be hidden but not
And you cannot overload a pointcut name (e.g., with more or fewer
In this case the advice in the abstract aspect will run only on the join
points picked out
by the pointcut in the abstract aspect.  the pointcut in the subaspect does
not override
but hides the superaspect pointcut of the same name (indeed, I thought we
had an 
XLint warning for this.)
Normally the pointcut in the abstract aspect is itself abstract, for just
this reason.  
Some people use the convention of another  pointcut titled {name}_default to

offer reusable pointcut for subaspects to consider.
------------Original Message------------
From: Thiago Bartolomei <thiagobart@xxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Fri, Oct-21-2005 3:54 AM
Subject: Re: [aspectj-users] Overriding pointcuts

try to append target to your pointcut:

pointcut log(Fifo fifo) : Logging.log(fifo) || execution(* Fifo.Get(..)) &&

I think the problem is that the compiler needs to know what to do with your
fifo variable in all cases . Without the target, the second part of the "or"
would have no context exposure..

Thiago T. Bartolomei
On 10/21/05, Sven Apel <apel@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 

I have a problem with overriding and reusing pointcuts. I want to extend the
set of join points captured by the "log" pointcut in the aspect "Logging":

abstract public aspect Logging 
        pointcut log(Fifo fifo) : execution(* Fifo.Put(..)) && target(fifo);

        before(Fifo fifo) : log(fifo)
                System.out.println("---> Fifo method called");

For that I want to use a further aspect that inherits from "Logging":

public aspect ExtLogging extends Logging
        pointcut log(Fifo fifo) : Logging.log(fifo) || execution(*

The above example does not work because ajc cannot bind "fifo" (inconsistent

The following example also does not work:

public aspect ExtLogging extends Logging 
        pointcut log() : Logging.log(Fifo) || execution(* Fifo.Get(..));

This is because "ExtLogging.log" must have the same signature than
"Logging.log". Other variants that declare an argument list in 
"ExtLogging.log" but do not pass "fifo" to "Logging.log" also do not work

Is there a possibility to override and reuse parent pointcuts that expect
arguments? Without arguments the above example works! 

Thanks in advance


Dipl.-Inf. Sven Apel
Institute for Technical and Business Information Systems
P.O. Box 4120, D-39016 Magdeburg, Germany
Phone: ++49 (391) 67-11899, Fax: ++49 (391) 67-12020 
Room: 29/108
E-Mail: apel@xxxxxxxxxxxxxxxxxxxxxxx

aspectj-users mailing list

aspectj-users mailing list