package lawOfDemeter;

import org.aspectj.lang.*;

/**
 * The LocallyConstructedBin 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 locally constructed objects
 * for later examination by the Checker aspect.
 *
 * @author Paul Freeman
 */

public aspect LocallyConstructedBin extends TargetBinStack {

  /**
   * What this bin contains.
   */
  public String contains(){ return "locally constructed 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.ConstructorCall();

  /**
   * There is nothing to gather before the EventToGather join point executes.
   */
  void gatherBefore(JoinPoint thisJoinPoint){
    // do nothing
  }

  /**
   * The method that gathers the locally constructed objects.  Must occur after
   * the constructor has executed.
   */
  void gatherAfter(JoinPoint thisJoinPoint, Object newLocalObj){
    add(newLocalObj, local + at(thisJoinPoint));
  }
}