package lawOfDemeter; import java.util.*; /** * The Any class 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 class contains all of the pointcuts that * need to be examined in an application to verify it meets the law of demeter. * * @author David H. Lorenz * @author Modifications made by Paul Freeman */ abstract class Any { // we encapsulate all pointcuts we need in a class and // refer to them later as Any.* // not in this package and either // - not within the controlflow of a call in this package // OR // - within the control flow of a method call in the Tests aspect of this package private pointcut scope(): !within(lawOfDemeter..*) && (!cflow(execution(* lawOfDemeter..*(..))) || cflow(execution(* lawOfDemeter.Tests.*(..)))); // capturing method calls. pointcut ConstructorCall(): scope() && call(*.new(..)); pointcut MethodCall(): scope() && call(* *(..)); // capturing method executions pointcut MainMethodExecution(): scope() && execution(void *.main(String[])); pointcut MethodExecution(): scope() && execution(* *(..)); pointcut ConstructorExecution(): scope() && execution(*.new (..)); pointcut Execution(): ConstructorExecution() || MethodExecution(); // capturing assignments to data members pointcut Set(): scope() && set(* *.*) ; // capturing accesses of data members pointcut Get(): scope() && get(* *.*); //Modify the pointcuts below to exclude join points from being checked by the application // denotes classes to avoid checking pointcut ToAvoid(): !Stable() && !(call(static * testcase..*(..)) || get(static testcase..* *)); // NOTE: With the following pointcuts, to nullify the pointcut, i.e. // have it pick out no join points, use: // Nothing() // as the sole designation // denotes all globally preferred static members // NOTE: scope() must always remain and be &&'ed with any further // pointcuts added. Multiple pointcuts added should be placed in parenteses // and separated with ||, i.e. scope() && (pointcut1() || pointcut2()) pointcut GlobalPreferred(): scope() && Nothing(); // denotes stable classes calls to which should not be checked; // multiple pointcuts should be separated with || pointcut Stable(): AllJavaPackageAccesses() ; // // what follows is a series of useful predefined pointcuts // // denotes the opposite of all classes // !within(*) can be read as not within any package. // It can be used to represent the empty set private pointcut Nothing(): !within(*); //denotes all statically accessed immediate parts and methods private pointcut AllStaticAccesses(): scope() && call(static * *.*(..)) || get(static * *); private pointcut AllJavaPackageAccesses(): scope() && call(* java..*(..)) || get(java..* *); }