[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [aspectj-users] newbie question about after returning
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Fri, 25 May 2012 09:02:13 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=q7EoTabwrBWm0ND4weQwZ198/TT4RIQEB6gBmhwe8lQ=; b=PgsFlxh26dJDKjY5IpPacrpJVS29HzurE7fLmy/pPRd4IrmTSpMNwtrNYU44AYQT+A /zpw/xqdR+a2dydLJMnEvEEgnVzDCacFtYxHJuqFp2WtpPXkp+Gdrv06v5VUhdhL5lIT xCPAVPmXn8LlUPtgPq6t4Wp4/1JzBI1FB9qQXrxFlCogFavlMwojBH5NptK3q5yghFsA kBIHKcpBJiZEm4i8DSEbJOxS5pYFqqiidzRHzpJbP2Orc+ACv2BIPRktwo3GJhIaIUqY Lm2nifCPiP7Hq1Bvu4hVBH/GRUuIUxw0h7cnHrVmU64REJOrngQVANdr4aWPGOkAdheZ aK3Q==
Your advice works for me - are you sure you have a method that matches
it? Here is a complete program that works:
====8<==== B.java
package com.mycom.mypack;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
public class B {
public static void main(String[] argv) {
System.out.println(myclass.myMethod());
}
}
@Aspect
class Azpect {
@Pointcut("within(com.mycom.mypack.myclass)")
public void withinMyPackage() {
}
@AfterReturning(pointcut = "execution(public static * myMethod ( .. )) "
+ " && withinMyPackage() ", returning = "myResult")
public void provideAdviseAfterReturning(MyType myResult, JoinPoint jp) {
// do something with returned results
System.out.println("advice handling "+myResult);
}
}
class myclass {
public static MyType myMethod() {
return new MyType();
}
}
class MyType {
}
====8<=====
when I run it:
advice handling com.mycom.mypack.MyType@24a37368
com.mycom.mypack.MyType@24a37368
Andy
On 25 May 2012 08:33, Srinivas S Tamvada <tssrinivas@xxxxxxxxx> wrote:
> Hi
> I have a very simple point cut, but the method return does not seem to be
> intercepted.
> Is the syntax wrong ?
>
> Thanks !
>
> @Pointcut("within(com.mycom.mypack.myclass)")
> public void withinMyPackage() {}
>
> @AfterReturning(pointcut = "execution(public static * myMethod ( .. )) "
> + " && withinMyPackage() " , returning = "myResult"
> )
> public void provideAdviseAfterReturning( MyType myResult , JoinPoint jp
> ) {
>
> // do something with returned results
>
> }
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>