// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.lang.reflect.*;

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

@Aspect
public class Check {
    @Pointcut("call(public * *.divide(*, *))")
    public void mathcheck() { };
    @Before("mathcheck()")
    public void check(JoinPoint thisJoinPoint) {
        Object[] o = thisJoinPoint.getArgs();
        String divtyp = o[1].getClass().getName();
        if(divtyp.equals("java.lang.Integer")) {
            if(((Integer)o[1]).intValue() == 0) {
                System.out.println("About to divide by zero");
            }
        }
        if(divtyp.equals("java.lang.Double")) {
            if(((Double)o[1]).doubleValue() == 0.0) {
                System.out.println("About to divide by zero");
            }
        }
    }
}
