Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to return from the method ?

Hi,

Yes you need around advice, only that advice can avoid executing the
original join point.  Here you go:

public class A {
  public static void main(String[] argv) {
    new A().run("abc");
    new A().run(null);
  }

  public void run(String s) {
    System.out.println(s);
  }
}

aspect X {
  void around(Object o): execution(public void run(String)) && args(o) {
    if (o!=null) {
      proceed(o);
    }
  }
}

Andy

On 15 April 2010 05:48, Rajat Gupta <innocent_person1@xxxxxxxxx> wrote:
> Hi All,
>
> I had a aspect, and java file.
>
> If input is null then i want to return from method.
> currently i am just returning from the aspect.
>
> so basically, i want that following line should not execute.
>  System.out.println("Printing .... ");
>
> It should be equivalent to following code.
>     public void jsSet_print(String xyz) throws Exception, IOException {
>         if(xyz!= null){
>              System.out.println("Printing .... ");
>         }
>     }
>
> If it is not possible using before, how can i do this?
>
> Is this is possible by around ?
>
> File attached.
>
> Thanks a lot.
> Rajat
>
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top