concept program element in category aspectj

appears as: program elements, program elements, program element, program element
AspectJ in Action, Second Edition

This is an excerpt from Manning's book AspectJ in Action, Second Edition.

AOP acts on classes in the same way that CSS acts on documents. AOP lets you separate crosscutting logic from the main-line logic. AOP’s pointcuts have the same selection role as CSS selectors. Whereas CSS selectors select structural elements in a document, pointcuts select program elements. Similarly, the blocks describing the formatting information are analogous to AOP advice in functionality.

Often, the selection mechanism requires more information than merely using the inherent characteristics of a structure such as body p. It’s common practice to supplement content elements with additional metadata through the class attribute. For example, you can mark an HTML paragraph element as menu by using the tag <p class="menu">. Then, in the stylesheet, you can select such an element by using the p.menu selector and apply appropriate presentation characteristics. In AOP, practitioners face the same problem—selection through a pointcut often requires information beyond merely relying on inherent characteristics of the program elements such as class and method names. The use of Java annotations plays a role similar to the class attribute in HTML documents. You can, for example, mark a method as @Transactional and utilize it in a pointcut expression.

In Java, all program elements have signatures. Pointcuts use patterns for these signatures to specify the selected join points. Figure 3.2 shows the relationship between program elements, signature, join points, and pointcuts.

Figure 3.2. Relationship between join points, signature patterns, and pointcuts. Types, methods, and fields all have a signature pattern associated with them (shown with a gray background); it’s a way to identify a program element. Pointcuts use signature patterns to select the associated join points.

Signature patterns can specify a few wildcards to match a wide range of program elements. We’ll examine signature patterns in section 3.5.