Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] [Newbie] Pick out a call / execution only in the hierarchy leafs

Hi all,

I have the following two interfaces:

 /*****************************/
 public Interface OptionHandler{
    ...
    String[] getOptions();
 }

 public Interface Randomizable{
   ...
 }
 /*****************************/

And I want to advice all calls to the OptionHandler.getOptions method within Randomizable & OptionHandler implementing classes. I use the following pointcut and advice:

 /*****************************/
 public pointcut getOptionsPointcut() :
     execution(public String[] OptionHandler.getOptions())
     && within(Randomizable+)
   ;

 String[] around() : getOptionsPointcut(){
   return Utils.appendOptions(getOption(), proceed());
 }
 /*****************************/

Now, given the following hierarchy:

  /*****************************/
 class A implements  OptionHandler, Randomizable{
     String[] getOptions(){
        ...
     }
  }

  class B extends A{
     String[] getOptions(){
        super.getOptions();
        ...
     }
  }
 /*****************************/

The poincut captures both the getOptions() execution in A and B, and I want it to capture only the execution in the "leaf" class of the hierarchy (class B, in this case). In other words, the A.getOptions must be picked out only if it is directly invoked but not if it is called from a redefining method via the super reference. How can I do that?. Is there a better or more elegant way of defining the pointcut to capture these joint points?.

Best Regards

Santi.


Back to the top