Chapter 10. Capturing Join Points Based on Control Flow

Introduction

The pointcuts described in this chapter support capturing all join points within the scope or context of another initial join point. Every join point has a discrete location in the control flow of a program, and this provides the context for join points that are captured by the pointcut declarations described here.

This may seem confusing at first. If you imagine that a join point is a specific point in your code providing a marker at which a scope can be defined, then these pointcut definitions pick that scope. To understand these pointcuts, you must delve into this chapter’s recipes and try things out. It is particularly worth examining the figures that accompany the recipes as these serve to illustrate what is actually going on when the pointcut’s logic is applied.

These pointcuts can be the hardest to grasp for newcomers to AspectJ, but it is worth persevering because they provide some unique and powerful mechanisms for capturing join points that are often useful once you have added them to your repertoire.

10.1. Capturing All Join Points Within a Program’s Control Flow Initiated by an Initial Join Point

Problem

You want to capture all join points encountered within the program control flow after and including an initiating join point selected by a separate pointcut.

Solution

Use the cflow(Pointcut) pointcut. The syntax of the cflow(Pointcut) pointcut is:

pointcut <pointcut name>(<any values to be picked up>) : cflow( ...

Get AspectJ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.