// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.lang.reflect.*;

import org.aspectj.lang.*;
import org.aspectj.lang.annotation.*;

@Aspect
public class Fun {
    @Pointcut("call(public void Foobar.test())")
    public void foobarTest() { };
    @Before("foobarTest()")
    public void before(JoinPoint tjp) {
        // increment v
        Foobar o = (Foobar)tjp.getTarget();
        o.setV(o.getV() + 1);
    }
    @Around(value = "foobarTest()")
    public Object around(ProceedingJoinPoint pjp) {
        // call twice instead of once
        pjp.proceed();
        pjp.proceed();
        return null;
    }
    @AfterReturning("foobarTest()")
    public void after(JoinPoint tjp) {
        // increment v
        Foobar o = (Foobar)tjp.getTarget();
        o.setV(o.getV() + 1);
    }
}
