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 public pointcut scope(): !within(lawOfDemeter..*) && (!cflow(execution(* lawOfDemeter..*(..))) ); // 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 (..)) || Initialization() || StaticInitialization()); pointcut Execution(): ConstructorExecution() || MethodExecution(); // capturing staticInitializations pointcut Initialization(): scope() && initialization(*.new(..)); pointcut StaticInitialization(): scope() && staticinitialization(*); // capturing assignments to data members pointcut Set(): scope() && set(* *.*); // capturing accesses of data members pointcut Get(): scope() && get(* *.*); // denotes all the join points to check in the code being examined pointcut ToCheck(): AnyDynamic.ToCheck(); // denotes all globally preferred static members pointcut GlobalPreferred(): scope() && AnyDynamic.GlobalPreferred(); // // what follows is a series of usefull predefined pointcuts to be used in // the AnyDynamic class to define the dynamic 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 pointcut Nothing(): !within(*); //denotes all statically accessed immediate parts and methods pointcut StaticAccesses(): scope() && (StaticCall() || StaticGet()); pointcut StaticCall(): scope() && call(static * *.*(..)); pointcut StaticGet(): scope() && get(static * *); //denotes all java package method and immediate part calls pointcut JavaPackageAccesses(): scope() && (JavaPackageCall() || JavaPackageGet()); pointcut JavaPackageCall(): scope() && call(* java..*(..)); pointcut JavaPackageGet(): scope() && get(java..* *); }