how to refer to pointcut defined in other aspects which extend the same parent aspect?

View: New views
4 Messages — Rating Filter:   Alert me  

how to refer to pointcut defined in other aspects which extend the same parent aspect?

by ppkluk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

  i want to refer to pointcut defined in other aspects (say AspectA, AspectB) which extend the same parent aspect (say ParentAspect), without prior knowning the existence of AspectA and AspectB?

public abstract aspect ParentAspect {
   public abstract pointcut monitorPoint();
}

public aspect AspectA extends ParentAspect {
   public pointcut monitorPoint(): execution(* *..*.main(..));
}

public aspect AspectB extends ParentAspect {
   public pointcut monitorPoint(): execution(* *..*.sayHello(..));
}

i want to write an advice to match the "ParentAspect+.monitorPoint()"

public aspect InterceptAspect{

  //this advice don't compile, with error message: Syntax error on token ".", "name pattern" expected
  void around(): ParentAspect+.monitorPoint(){
      //do something
      proceed();
  }

}


could anybody tell me how to archieve my goal?

thank you

ppk


Re: how to refer to pointcut defined in other aspects which extend the same parent aspect?

by Andrew Eisenberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think that your best bet is to write the advice in the base aspect,
which then delegates to a method in the parent abstract.  I.e.-

public abstract aspect ParentAspect {
   public abstract pointcut monitorPoint();
}

public aspect AspectA extends ParentAspect {
  public pointcut monitorPoint(): execution(* *..*.main(..));

  void around(): monitorPoint(){
      //do nothing
      proceed();
  }
}

And then capture this advice in the interceptor
public aspect InterceptAspect{
  void around(): adviceexecution() && within(ParentAspect+) {
      //do something
      proceed();
  }
}

You may need to add some extra parts to the pointcut on intercept's
around advice in order to exclude other advice defined in ParentAspect
or its children.



On Fri, Aug 14, 2009 at 11:19 PM, ppkluk<imperfectluk-ppk@...> wrote:

>
> Dear all,
>
>  i want to refer to pointcut defined in other aspects (say AspectA,
> AspectB) which extend the same parent aspect (say ParentAspect), without
> prior knowning the existence of AspectA and AspectB?
>
> public abstract aspect ParentAspect {
>   public abstract pointcut monitorPoint();
> }
>
> public aspect AspectA extends ParentAspect {
>   public pointcut monitorPoint(): execution(* *..*.main(..));
> }
>
> public aspect AspectB extends ParentAspect {
>   public pointcut monitorPoint(): execution(* *..*.sayHello(..));
> }
>
> i want to write an advice to match the "ParentAspect+.monitorPoint()"
>
> public aspect InterceptAspect{
>
>  //this advice don't compile, with error message: Syntax error on token
> ".", "name pattern" expected
>  void around(): ParentAspect+.monitorPoint(){
>      //do something
>      proceed();
>  }
>
> }
>
>
> could anybody tell me how to archieve my goal?
>
> thank you
>
> ppk
>
>
> --
> View this message in context: http://www.nabble.com/how-to-refer-to-pointcut-defined-in-other-aspects-which-extend-the-same-parent-aspect--tp24981874p24981874.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: how to refer to pointcut defined in other aspects which extend the same parent aspect?

by ppkluk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andrew,

   why i want to reference to pointcut defined in other aspects is that,
i want to be able to " capture the joinpoint that is not captured by any other pointcut defined in a set of aspects".

   maybe my i have to revise the InterceptAspect as following:

public aspect InterceptAspect{

 //this advice don't compile, with error message: Syntax error on token ".", "name pattern" expected

 // ==> try to capture the method execution in classes in a packages "test.mycode" ,
 //which is not captured by other pointcut defined in ParentAspect and its sub-aspects.

 void around(): execution(* test.mycode..*(..)) && !ParentAspect+.monitorPoint(){
   
    //do something interested
    System.out.println("This method execution is not captured by other aspect, except InterceptAspect");

     proceed();
}

  i don't know how to achieve this..

  thank you.

ppk
     


Andrew Eisenberg wrote:
I think that your best bet is to write the advice in the base aspect,
which then delegates to a method in the parent abstract.  I.e.-

public abstract aspect ParentAspect {
   public abstract pointcut monitorPoint();
}

public aspect AspectA extends ParentAspect {
  public pointcut monitorPoint(): execution(* *..*.main(..));

  void around(): monitorPoint(){
      //do nothing
      proceed();
  }
}

And then capture this advice in the interceptor
public aspect InterceptAspect{
  void around(): adviceexecution() && within(ParentAspect+) {
      //do something
      proceed();
  }
}

You may need to add some extra parts to the pointcut on intercept's
around advice in order to exclude other advice defined in ParentAspect
or its children.



On Fri, Aug 14, 2009 at 11:19 PM, ppkluk<imperfectluk-ppk@yahoo.com.hk> wrote:
>
> Dear all,
>
>  i want to refer to pointcut defined in other aspects (say AspectA,
> AspectB) which extend the same parent aspect (say ParentAspect), without
> prior knowning the existence of AspectA and AspectB?
>
> public abstract aspect ParentAspect {
>   public abstract pointcut monitorPoint();
> }
>
> public aspect AspectA extends ParentAspect {
>   public pointcut monitorPoint(): execution(* *..*.main(..));
> }
>
> public aspect AspectB extends ParentAspect {
>   public pointcut monitorPoint(): execution(* *..*.sayHello(..));
> }
>
> i want to write an advice to match the "ParentAspect+.monitorPoint()"
>
> public aspect InterceptAspect{
>
>  //this advice don't compile, with error message: Syntax error on token
> ".", "name pattern" expected
>  void around(): ParentAspect+.monitorPoint(){
>      //do something
>      proceed();
>  }
>
> }
>
>
> could anybody tell me how to archieve my goal?
>
> thank you
>
> ppk
>
>
> --
> View this message in context: http://www.nabble.com/how-to-refer-to-pointcut-defined-in-other-aspects-which-extend-the-same-parent-aspect--tp24981874p24981874.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: how to refer to pointcut defined in other aspects which extend the same parent aspect?

by Andrew Eisenberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Again, I don't think there is any direct way of doing this, but
something that comes to my mind is the following:

* this only works if all other advice used are around() with proceed()
* set the InterceptAspect to the lowest precendence (ie- runs last)
* then set your pointcut to capture all method executions that are
!(cflow(adviceexecution()) && within(ParentAspect+)
* Also, this will not work if you have advice being applied more than
once in your stack.

I haven't tried this, but it might work for you.

On Sun, Aug 16, 2009 at 9:47 AM, ppkluk<imperfectluk-ppk@...> wrote:

>
> Hi Andrew,
>
>   why i want to reference to pointcut defined in other aspects is that,
> i want to be able to " capture the joinpoint that is not captured by any
> other pointcut defined in a set of aspects".
>
>   maybe my i have to revise the InterceptAspect as following:
>
> public aspect InterceptAspect{
>
>  //this advice don't compile, with error message: Syntax error on token ".",
> "name pattern" expected
>
>  // ==> try to capture the method execution in classes in a packages
> "test.mycode" ,
>  //which is not captured by other pointcut defined in ParentAspect and its
> sub-aspects.
>
>  void around(): execution(* test.mycode..*(..)) &&
> !ParentAspect+.monitorPoint(){
>
>    //do something interested
>    System.out.println("This method execution is not captured by other
> aspect, except InterceptAspect");
>
>     proceed();
> }
>
>  i don't know how to achieve this..
>
>  thank you.
>
> ppk
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users