// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;

// aspect
@Aspect
public class Trace2 {
    // pointcut:
    //   public visibility, any return type, class annotation.IntMath, any method name, any arguments
    //   public visibility, any return type, class annotation.DoubleMath, any method name, any arguments
    @Pointcut("call(public * annotation.IntMath.*(..)) || call(public * annotation.DoubleMath.*(..))")
    public void mathtrace() { };
    // advice:
    //    around
    @Around("mathtrace()")
    public Object trace(ProceedingJoinPoint pjp) {
        System.out.println("AOP> Enter " + pjp.getSignature());
        Object res = null;
        try {
            res = pjp.proceed();
        } catch(Throwable e) {
             throw (RuntimeException)e;
        }
        System.out.println("AOP> Exit " + pjp.getSignature());
        return res;
    }
}
