Creator’s self-help guide to design methods on top of AJDT and AspectJ

Creator’s self-help guide to design methods on top of AJDT and AspectJ

These pages is intended to aid anybody establishing tools to increase or work with AJDT/AspectJ. Please play a role in this site with any pertinent details, such as sample code using the AJDT and/or AspectJ APIs.

These pages is beyond date. The intention is update this page for AJDT 1.6.1, but we now have perhaps not got time because of this yet. Please realize that a few of something with this web page might no lengthier getting appropriate. When you yourself have any queries, kindly submit them to the email list ajdt-dev.


  • 1 getting crosscutting relationship facts from AJDT
  • 2 Compilation Units in AJDT
    • 2.1 Getting the items in an AJCompilationUnit
  • 3 Making use of the AspectJ AST parser
  • 4 recognized limitations, bugs, and exceptional dilemmas
  • 5 The software equipment are anticipated to make use of to operate a vehicle the AspectJ compiler

Acquiring crosscutting relationship details from AJDT

If you find yourself building an eclipse plug-in and need access to crosscutting suggestions whenever a project is created, you’ll register a listener with AJDT. Their plug-in should rely on org.eclipse.ajdt.core, org.eclipse.core.resources and org.eclipse.jdt.core, and org.aspectj.weaver. When you look at the org.eclipse.ajdt.core plug-in there is certainly an IAdviceChangedListener program with one adviceChanged() way.

Enter this with the AJBuilder class in this way (in your plug-in’s start() way of sample):

Currently (AJDT 1.6) this can be also known as after each build of an AspectJ task (i.e. every *potential* information change). In a future launch this may be optimized to-be only known as in the event that advice has actually changed. AJDT/UI uses this procedure to revise the orange arrow image decorator.

Crosscutting facts may then be obtained from the AJProjectModelFacade lessons. Here is an example with pseudo-code it is possible to adapt:

Several records about any of it:

  1. The API could have some lesser changes in tomorrow. Kindly deliver a message towards the ajdt-dev mailing list if such a thing with this web page is out of day.
  2. The AJProjectModelFacade object is a light-weight entrances to the AspectJ business. It can be appropriate before the next build. So, you shouldn’t keep all of them. Make use of totally free dating sites them and dispose as required.
  3. AJProjectModelFacade things just contain information following the earliest effective build. It is possible to contact the hasModel() way to see if an AspectJ design is available the venture.
  4. Clearly, obtain the connection both in information. Read AJRelationshipManager when it comes down to complete set of relationships, so you’re able to merely require the partnership type you have in mind.
  5. IRelationship.getSourceHandle() and IRelationship.getobjectives() return chain that portray AspectJ aspect manages. You need here AJProjectModelFacade ways to become model details:
    • toProgramElement(sequence) — comes back IProgramElement. From here you are able to receive information regarding the pointcut, intertype aspect, or declare element.
    • programElementToJavaElement(String) or programElementToJavaElement(IProgramElement) — returns IJavaElement. From here it is possible to catch into JDT tooling.
  6. There is absolutely no necessity to join up an advice altered listener. You could get the means to access the crosscutting unit at any time (provided that the project has received a fruitful develop) with the following rule:

Compilation Models in AJDT

JDT brings compilation products (instances of ICompilationproduct) for .java files. AJDT produces compilation models for .aj documents, which have been cases of AJCompilationUnit (which implements ICompilationdevice). The class AJCompilationUnitManager (inside the org.eclipse.ajdt.core plug-in) contains some of use methods with this, such as for example:

From an AJCompilationUnit you’ll acquire different architectural suggestions such getAllTypes(). The principal sort for “.aj” data is normally an aspect, that’s displayed by AspectElement course, which contains aspect-specific means such as for example getPointcuts() and getAdvice(). These return furthermore aspect-specific characteristics eg PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we make use of the Eclipse weaving services to weave into JDT. One group of join information which can be informed are those associated with the development of CompilationUnit objects. If document enjoys is *.aj file, AJCompilationUnit is made as opposed to a regular Java collectionproduct.

Obtaining contents of an AJCompilationUnit

Because JDT expects that all resource it functions with does work Java laws, JDT does not work really with AspectJ. To get around this, AJCompilationUnits uphold two buffers which contain supply items. The foremost is a java suitable buffer and also the 2nd is the original contents buffer. The java compatible buffer may be the buffer that is came back automatically when AJCompilationUnit.getContents() is known as. This buffer contains the AspectJ rule along with aspect-specific syntax stripped away. The initial material buffer consists of (just like you would count on) the first content in the document.

As an example when the earliest material buffer looks like:

the Java appropriate buffer is

Realize that the foundation locations associated with identifiers are exactly the same both in buffers. This ensures that guide researching and hyperlinking functions needlessly to say.

Should you call for working together with the original articles of an AspectJ CompilationUnit ajUnit, you certainly can do the annotated following:

What this process does requests the AJCU to temporarily change the buffer into AJ buffer from the Java buffer. It’s always best to do that in a synchronized block so you you should not risk various other posts coming by and inadvertently making use of the incorrect buffer (AJDT by itself doesn’t incorporate a synchronized block for this, however it should).

By using the AspectJ AST parser

Important instance, extracted from bug 88861

Compile the aforementioned and operate it:

Understood limitations, insects, and outstanding issues

Constraint: there’s at this time no AST service for solving means bindings: bug 146528

No comments yet.

Leave a Reply