Chapter 10. Using the AspectJ API

Chapter 7, Section 7.3.1, discussed the use of the special variables thisJoinPoint, thisJoinPointStaticPart, and thisEnclosingJoinPoint StaticPart inside advice bodies. In this chapter, we explore the API provided by AspectJ’s runtime library (aspectjrt.jar), and show how you can make full use of these variables.

Listing 10.1 shows a very simple application, MyApp, which we will use as the basis of the exploration.

Example 10.1. MyApp

 package business; public class MyApp { private String mostRecentCmd; private void repeat() { repeat(1); } private void repeat(int attempts) { if (this.mostRecentCmd != null) { doSomething(mostRecentCmd, attempts); } else { System.out.println("Nothing to repeat."); } } private void ...

Get Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools 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.