Develop Aspect-Oriented Java Applications with Eclipse and AJDT
By Matt Chapman, Dr. Helen Hawkins
2005-05-16
The Outline view and editor markers
Now that we've written and run our simple AspectJ application, let's have a look at how AJDT helps you to understand and work with it. With the
Cache aspect open in the editor, take a look at the Eclipse Outline view, which should look like Figure 2.
Figure 2. Outline view of the Cache aspect

The Outline view shows the structure of the current document. In the case of our Cache aspect, we have an import declaration, and then, instead of a class, we have an aspect called Cache. You will notice that directly underneath Cache there are four different nodes, each corresponding to a feature within the aspect. The first of these is the valueCache private field -- remember, aspects can contain methods and fields, just like classes. Next we have something a little different: a lightning bolt icon labelled calculate(int). This signifies a pointcut; click on it and the editor will jump to the appropriate line. Things get more interesting with the next node, representing the around advice. Expand this node, and you'll see an "advises" node, which itself expands to reveal a private static method called Application.calculateSquare(int). Here, the AspectJ-enhanced Outline view takes us beyond the basic structure of the current source file, showing us the relationship this construct (the around advice) has with another construct in the system -- a method that is being advised, in this case. Furthermore, the target of the relationship is a hyperlink -- simply click on the Application.calculateSquare(int) node, and the editor will switch to the containing source file (Application.java) and highlight the method that is being advised.
Now that we have Application.java open in the editor, the Outline view should look like Figure 3.
Figure 3. Outline view of Application class

Initially, the Outline view for this source files looks pretty much as it would in the normal Java world, without AJDT. But notice that the node for the calculateSquare() method can be expanded to reveal an "advised by" node, and then a node showing the source of the advice -- in this case, the around advice in the Cache aspect (which is a link, as before).
Now, go back to the editor itself, which is showing the Application class. In the left edge of the window (known as the gutter), there is a marker next to the calculateSquare() method declaration, with the same icon as in the Outline view. There is also an orange block marking the same method declaration in the right-hand bar of the editor. Both show that some advice is taking effect here. Move your mouse arrow over these indicators; you'll get a message that tells you that they are marking a location advised by the around advice in the Cache aspect. Finally, you can right-click on the advice marker and open the "Advised by" menu to see the appropriate advice. Select this advice to navigate to it, as shown in Figure 4.
Figure 4. Advised by menu

That's all it takes to create, run, and explore the crosscutting structure of a simple AspectJ project using AJDT!
Tutorial Pages:
»
Updated tools make AOP easier for beginners and veterans alike
»
Installing AJDT
»
First steps
» The Outline view and editor markers
»
The Spacewar example
»
Build configurations
»
Aspect Visualization perspective
»
Debugging
»
Generating documentation
»
Further options
»
Conclusion
»
Resources
First published by IBM DeveloperWorks
|
