package lawOfDemeter; import org.aspectj.lang.*; /** * The ArgumentBin aspect is part of a Law of Demeter Checker - a set of * classes and aspects that verify a given program does not violate * the Law of Demeter. This aspect gathers the arguments to methods for later * examination by the Checker aspect. * * @author Paul Freeman */ public aspect ArgumentBin extends TargetBinStack { /** * What this bin contains. */ public String contains(){ return "argument objects"; } /** * This is the pointcut used by the before and after advice to stack the * target bins. */ pointcut EventToStack(): Any.Execution(); /** * This is the pointcut used by the around advice to gather the objects. */ pointcut EventToGather(): Any.Execution(); /** * The method that gathers arguments to methods. Must occur before the * execution of the method. */ void gatherBefore(JoinPoint thisJoinPoint){ // store the arguments of the method addAll(thisJoinPoint.getArgs(), argument + at(thisJoinPoint)); // arguments include this/self - store the object currently executing add(thisJoinPoint.getThis(), receiver + at(thisJoinPoint)); } /** * There is nothing to gather after the EventToGather join point executes. */ void gatherAfter(JoinPoint thisJoinPoint, Object returnValue){ // do nothing } }