XAspects: Extensible Plug-ins for
Aspect-Oriented Programming
Design Specifications - AspectJ Plugin

Macneil Shonle
Ankit Shah
Version 1.1
12 March 2003

Download Source Code of AspecJ Plugin

public class AspectJ extends AspectPlugin{

    public AspectJ ();
    public void init (CompilationEnvironment ce);

    public void receiveBody(String aspectID, String body);

    public File[] generateExternalInterfaces();
    public File[] generateCode(File[] classFiles);

    public void cleanup();

    private File[] generatedFiles();
}

Constructors and Initialization

Since, parameterized constructors cannot be called, init is implemented to initialize the plugin so that it can have a reference to the CompilationEnvironment instance that helps communications during the proces. Since, no additional initialization is necessary, these methods pass on the calls to the corresponding methods of the super classes.

Implementing the receiveBody() method

Implementation of AspectJ plugin is more simple than perhaps any other plugin. All the received code is to be stored in a .java file without ANY checking. The only issues that remain while doing so is, generating name for the aspect, other information relating to packages, importing, modifiers and inheritence and generating a filename.
The aspectID is the aspect name for the new aspect.
From the AspectInfo class, extract all the supplementary information and include it at appropriate places.
aspectID is used as a filename, provided it is atmost 3 letters long.
The parser will generate the body wherein all tokens are separated by space. As a result, the pointcut declaration appears as follows:

	pointcut pName ( Type1 arg1 , Type2 arg2 ) : call ( * Classname . methodName ( . . ) );
							      ^^^^^^^^^^^^^^^^^^^^^^

However, spaces around dots are not acceptable at the marked position, hence the whole body is corrected by a correct method.
This methods returns nothing, but as far as processing goes, all of it is done and completed here itself!

generateExternalInterfaces()

All the work to process an AspectJ type aspect has been done in the previous call. So simply return the list returned by generatedFiles()

generateCode()

All the work to process an AspectJ type aspect has been done in the previous call. So simply return the list returned by generatedFiles()

cleanup()

No specific cleanup to be done. As per AspectPlugin requirements, call cleanup of superclass.

Helper Methods

generatedFiles()

This method scans the working Directory for all .java files, collects them in an array of File objects are returns the array. It returns null if no .java files are found

correct()

Removes extra spaces around the dots to correct the parser generated body string and avoid compilation errors.

References

XAspects Project Home Page, <http://www.ccs.neu.edu/research/demeter/xaspects/>.

AspectJ, <http://www.aspectj.org>.

Author: Ankit Shah. Copyright © 2003. All rights reserved.