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

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.AfterReturning;

// work with Spring DI
@Component("trace1")
// aspect
@Aspect
public class Trace1 {
    // pointcut:
    //   public visibility, any return type, class dynamic.IntMath, any method name, any arguments
    //   public visibility, any return type, class dynamic.DoubleMath, any method name, any arguments
    @Pointcut("execution(public * dynamic.IntMath.*(..)) || execution(public * dynamic.DoubleMath.*(..))")
    public void mathtrace() { };
    // advice:
    //    before
    @Before("mathtrace()")
    public void enter(JoinPoint thisJoinPoint) {
        System.out.println("AOP> Enter " + thisJoinPoint.getSignature());
    }
    // advice:
    //   after returning
    @AfterReturning("mathtrace()")
    public void leave(JoinPoint thisJoinPoint) {
        System.out.println("AOP> Exit " + thisJoinPoint.getSignature());
    }
}
