Debugging pointcuts

Go at it top-down and then bottom-up. Top-down, draft significant aspects by first writing the comments to specify responsibilities. Advice responsibility usually takes the form, "When X, do Y." Pointcut responsibility for "When X" often takes the form, "When [join points] [in locations] [are ...]". These []'s often translate to named pointcuts (like `libraryCalls() && within(Client) && args(Context)`) which form a semantic bridge to the plain-text meaning in a comment (e.g., `// when the client passes only context into the library`). This gets you to a point where you can debug the parts of the pointcut independently.

Bottom up (to build each part), consider each primitive pointcut designator (PCD), then the composition, and then any implicit constraints:

  1. What kinds of join points should it match? (constructor-call? field-get?)? This translates to using the kinded pointcuts (`call(..)`, `get(..)`, etc.).

  2. Are these restricted to being lexically within something? This translates to using `within{code}(..)`. If this is true, it should always be used, to speed up weaving.

  3. What runtime constraints and context should be true and available at each join point? This translates to `this()`, `target()`, `args()`, `cflow{below}()` and `if(..)`.

  4. Are there any advice or implementation limitations at issue? This involves knowing the few constraints on AspectJ imposed by Java bytecode as listed in the AspectJ Programming Guide section on Implementation Notes.

It's much faster to iterate a pointcut at compile-time using declare warning (even better, some errors are identified at parse-time in the latest versions of AJDT). Start with the parts of the pointcut that are staticly-determinable (i.e., they do not involve the runtime PCD's listed above). If compiles themselves take too long because of all the AspectJ weaving, then try to only include the debugging aspect with the prototype pointcut, and limit the scope using within(..).

Some mistakes in primitive pointcuts:

Some mistakes in composition:

Some mistakes in implicit advice constraints:

Some mistakes in implementation requirements: