package lawOfDemeter; import java.util.*; /** * The ImmediatePartBin 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 stores the immediate parts, or * instance variables, of objects as they are set for later * examination by the Checker aspect. * * @author David H. Lorenz * @author Modifications made by Paul Freeman */ public aspect ImmediatePartBin extends Supplier perthis(Any.ConstructorExecution()){ /** * Prints the objects currently in the bin. * Used for debugging. */ public void printBin(){ System.out.println("-- immediate part objects --"); printHashMap(targets); System.out.println("----------------------------"); } /** * Advice that stores the immediate part objects, or instance variables, of * the object currently executing. */ before(): // direct parts Any.Set() { // There is only one argument to a set join point. // Becomes a preferred supplier and is therefore added to targets. addAll(thisJoinPoint.getArgs(), direct+at(thisJoinPoint)); // System.out.println("Adding--" + thisJoinPoint + at(thisJoinPoint)); } }