2.7 Showing Advice In AJDT
AJDT contains a lot of features designed to help you understand and be aware of the effects of advice in your program. The primary means are the editor and Outline view, but there is also a visualization view and the capability to generate documentation.
2.7.1 The Outline View
Let's look at the Outline view for the PolicyChangeNotification aspect. This is shown in Figure 2.33, with the node for the after returning advice fully expanded. Notice how the Outline view shows us all the places that the advice advises. To be slightly more precise, the Outline view is showing us all the places in the program source code that will give rise to a join point at runtime that will be matched by the pointcut expression associated with the advice. Just like the declare warning matches in the Outline view, these matches are links, too. If you click one, it will take you to the corresponding source location.
Figure 2.33 Showing the effect of advice in the Outline view.
If we click the first match in the list, HousePolicyImpl.setWorth (double), the editor opens on the source file containing the definition of the HousePolicyImpl class, at the setWorth method. The Outline view updates to display the outline for the HousePolicyImpl class, as shown in Figure 2.34. The node for the setWorth method has been expanded, and we can see that it has been "advised by" the after returning advice in the PolicyChangeNotification aspect. The setAddress method has also been advised, the plus sign (+) next to its node in the tree view gives us a cue, and if we expanded it we would see the "advised by" relationship as we do for setWorth. Once again the entries shown under "advised by" are hyperlinks that can be used to navigate to the definition of the advice affecting the method, simply by clicking.
Figure 2.34 An advised method in the Outline view.
2.7.2 The Editor
Now let's look at the editor buffer we just opened on HousePolicyImpl.java. This is shown in Figure 2.35. There are two key points to note in this figure. First, in the left margin next to the setWorth and setAddress methods, we see an advice marker (the arrow pointing down and to the right). This tells us that there is after advice in place on these methods. In other words, after returning from the execution of the setWorth and setAddress methods, some advice will run.
Figure 2.35 Advised methods in the editor.
In the right margin, we see the overview ruler for the whole source file. In this margin, there are check marks indicating the presence of advice (and also the warnings generated by the declare warning statement). You can click these check marks to navigate to the corresponding location in the source file.
Returning our attention to the advice markers in the left margin once more, they tell us that the method has after returning advice, but not which advice. As we have already seen, we can use the Outline view to find that out. Another option is to right-click the advice marker to bring up the context menu, as shown in Figure 2.36.
Figure 2.36 Using the context menu to discover advice.
Selecting the Advised by option in the menu brings up a list of all the advice affecting the method. Selecting one of the items in the list (in Figure 2.36 there is only one) opens the editor on the advice declaration.
2.7.3 Documentation and Visualization
AJDT also provides a visualization view that gives you an overview of the source files in your application and where the advice defined in aspects matches lines of source code that will give rise to advised join points at runtime. Figure 2.37 shows an example of the kind of views it produces.
Figure 2.37 Visualization view.
Each vertical bar represents an individual source file. The highlighted bars contain lines of code that will give rise to join points matched by advice at runtime. The stripes on the highlighted bars indicate the places that advice applies. You can click these to navigate. In this example, the Visualiser is highlighting the classes in the policy hierarchy. Chapter 12 provides more detail on using the Visualiser.
A final way of understanding the effects of advice is through the documentation that AJDT produces via the ajdoc tool (ajdoc is AspectJ's version of the javadoc tool). We show you how to use AJDT to generate documentation in Chapter 4.