Designer’s self-help guide to constructing knowledge on top of AJDT and AspectJ

Designer’s self-help guide to constructing knowledge on top of AJDT and AspectJ

This page is meant to assist individuals developing resources to increase or assist AJDT/AspectJ. Be sure to play a role in this site with any pertinent information, particularly instance code utilizing the AJDT and/or AspectJ APIs.

This page is out of big date. Our purpose will be update this page for AJDT 1.6.1, but we’ve not got energy with this yet. Be sure to keep in mind that a few of what’s on this subject web page might no lengthier end up being correct. For those who have questions, be sure to submit these to the mailing list ajdt-dev.


  • 1 getting crosscutting relationship suggestions from AJDT
  • 2 Compilation Products in AJDT
    • 2.1 obtaining the belongings in an AJCompilationUnit
  • 3 Using the AspectJ AST parser
  • 4 recognized limitations, pests, and exceptional dilemmas
  • 5 The interface knowledge are anticipated to make use of to operate a vehicle the AspectJ compiler

Getting crosscutting relationship suggestions from AJDT

If you find yourself developing an eclipse plugin and call for the means to access crosscutting info whenever a venture is built, you’ll sign up a listener with AJDT. Your plug-in will have to depend on org.eclipse.ajdt.core, org.eclipse.core.resources and org.eclipse.jdt.core, and org.aspectj.weaver. For the org.eclipse.ajdt.core plug-in you will find an IAdviceChangedListener screen with a single adviceChanged() technique.

Enroll this making use of AJBuilder class like this (in your plug-in’s start() way of sample):

At this time (AJDT 1.6) this will be labeled as after each and every build of an AspectJ venture (i.e. every *potential* advice changes). In another release this can be optimized to be only called in the event that advice enjoys actually altered. AJDT/UI utilizes this process to modify the tangerine arrow image decorator.

Crosscutting info can then become extracted from the AJProjectModelFacade course. Listed here is an illustration with some pseudo-code you’ll be able to adapt:

Several notes about this:

  1. The API possess some lesser changes in the long term. Kindly send a message to the ajdt-dev subscriber list if things on this page may be out of day.
  2. The AJProjectModelFacade item is actually a lightweight entrance into the AspectJ business. It is only valid before the further develop. So, you shouldn’t store them. Utilize them and dispose as needed.
  3. AJProjectModelFacade stuff just have information following first winning acquire. You can easily call the hasModel() approach to find out if an AspectJ design prevails for venture.
  4. As you can see, you can get the relationship in directions. Discover AJRelationshipManager when it comes to complete set of interactions, so you can merely request the relationship type you are interested in.
  5. IRelationship.getSourceHandle() and IRelationship.getTargets() return Strings that express AspectJ element manages. You can make use of the next AJProjectModelFacade ways to convert to model aspects:
    • toProgramElement(sequence) — returns IProgramElement. From this point you’ll get information about the pointcut, intertype aspect, or declare component.
    • programElementToJavaElement(sequence) or programElementToJavaElement(IProgramElement) — comes back IJavaElement. From this point you are able to catch into JDT tooling.
  6. There is no need to join up a recommendations altered listener. You could get the means to access the crosscutting product at any time (so long as your panels has received a successful acquire) with the next code:

Compilation Products in AJDT

JDT produces collection devices (cases of ICompilationUnit) for .java data files. AJDT creates compilation models for .aj files, which are instances of AJCompilationUnit (which implements ICompilationUnit). The class AJCompilationUnitManager (into the org.eclipse.ajdt.core plug-in) has some beneficial techniques relating to this, instance:

From an AJCompilationUnit it is possible to receive different architectural records eg getAllTypes(). The principal type for “.aj” files is usually a piece, which will be represented of the AspectElement course, containing aspect-specific strategies eg getPointcuts() and getAdvice(). These return more aspect-specific elements like PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we utilize the Eclipse weaving service to weave into JDT. One collection of join factors which can be urged are the ones linked to the production of CompilationUnit items. In the event that document features is *.aj file, AJCompilationUnit is generated in the place of a standard coffee Compilationproduct.

Acquiring the contents of an AJCompilationUnit

Because JDT needs that all supply it functions with is true coffee rule, JDT doesn’t work well with AspectJ. In order to get with this, AJCompilationUnits keep two buffers containing provider materials. The foremost is a java suitable buffer therefore the 2nd could be the initial material buffer. The coffee suitable buffer will be the buffer that will be came back automagically when AJCompilationUnit.getContents() is called. This buffer offers the AspectJ rule with aspect-specific syntax stripped aside. The first content material buffer contains (while you would count on) the original contents associated with file.

Eg in the event that earliest material buffer looks like:

the coffee suitable buffer becomes

Observe that the source stores of identifiers are identical in buffers. This ensures that research getting and hyperlinking performs as expected.

If you call for working with the first content material of an AspectJ CompilationUnit ajdevice, you can do the following:

What this process do wants the AJCU to briefly turn its buffer to the AJ buffer through the coffee buffer. It’s always best to repeat this in a synchronized block so that you will you shouldn’t risk some other threads coming by and accidentally using the wrong buffer (AJDT by itself doesn’t incorporate a synchronized block with this, nevertheless should).

Utilizing the AspectJ AST parser

Simple instance, obtained from insect 88861

Make the above mentioned and operated they:

Known limitations, pests, and exceptional issues

Constraint: You will find at this time no AST help for fixing sort bindings: insect 146528

Leave a Comment