// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
aspect Check {
    pointcut mathcheck() :
        call(public * *.divide(*, *));
    before() : mathcheck() {
        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");
            }
        }
    }
}
