Creator’s guide to developing equipment on top of AJDT and AspectJ

Creator’s guide to developing equipment on top of AJDT and AspectJ

This page is intended to support any person establishing gear to give or work with AJDT/AspectJ. Be sure to subscribe to these pages with any appropriate ideas, eg example laws utilizing the AJDT and/or AspectJ APIs.

This page is beyond big date. Our very own purpose should revise these pages for AJDT 1.6.1, but there is maybe not have opportunity for this yet. Please realize that a number of what is on this subject page may no much longer end up being proper. If you have any queries, please deliver them to the mailing list ajdt-dev.

Contents

  • 1 Obtaining crosscutting connection ideas from AJDT
  • 2 Collection Products in AJDT
    • 2.1 Acquiring the contents of an AJCompilationUnit
  • 3 Using the AspectJ AST parser
  • 4 recognized restrictions, bugs, and exceptional problem
  • 5 The software tools are anticipated https://www.datingranking.net/furfling-review/ to make use of to push the AspectJ compiler

Getting crosscutting connection ideas from AJDT

If you should be developing an eclipse plug-in and call for the means to access crosscutting details whenever a venture is made, you can enroll a listener with AJDT. Their plug-in will have to be determined by org.eclipse.ajdt.core, org.eclipse.core.resources and org.eclipse.jdt.core, and org.aspectj.weaver. Into the org.eclipse.ajdt.core plug-in you will find an IAdviceChangedListener program with a single adviceChanged() technique.

Enroll this making use of AJBuilder lessons like this (inside plug-in’s start() method for example):

Presently (AJDT 1.6) this might be called after each create of an AspectJ job (for example. every *potential* recommendations modification). In a future release this might be optimized to be just labeled as when the recommendations provides actually altered. AJDT/UI makes use of this apparatus to upgrade the orange arrow picture decorator.

Crosscutting info are able to getting extracted from the AJProjectModelFacade lessons. Discover a good example with many pseudo code you’ll be able to adjust:

A few records about it:

  1. The API might have some lesser alterations in the long run. Please submit a message for the ajdt-dev email list if anything with this web page may be out of big date.
  2. The AJProjectModelFacade object are a lightweight entry in to the AspectJ world. It is simply appropriate until the after that create. Thus, cannot keep all of them. Use them and dispose as required.
  3. AJProjectModelFacade items only include facts following very first profitable create. You are able to name the hasModel() solution to find out if an AspectJ model prevails for your venture.
  4. As you can see, you can get the relationship in both instructions. Discover AJRelationshipManager when it comes to complete selection of affairs, so you’re able to merely request the connection kinds you are interested in.
  5. IRelationship.getSourceHandle() and IRelationship.getTargets() return Strings that represent AspectJ factor handles. You can utilize these AJProjectModelFacade strategies to become model factors:
    • toProgramElement(sequence) — comes back IProgramElement. From this point it is possible to receive details about the pointcut, intertype factor, or declare aspect.
    • programElementToJavaElement(String) or programElementToJavaElement(IProgramElement) — returns IJavaElement. From this point it is possible to hook into JDT tooling.
  6. There’s absolutely no needs to register an advice altered listener. You may get use of the crosscutting unit whenever you want (assuming that the project has already established a successful build) utilizing the next rule:

Compilation Models in AJDT

JDT produces compilation devices (instances of ICompilationproduct) for .java data. AJDT creates collection devices for .aj documents, which are instances of AJCompilationUnit (which implements ICompilationproduct). The course AJCompilationUnitManager (when you look at the org.eclipse.ajdt.core plug-in) has some of good use practices concerning this, such as for instance:

From an AJCompilationUnit it is possible to receive numerous architectural records particularly getAllTypes(). The primary kind for “.aj” data is typically an aspect, basically displayed because of the AspectElement class, which contains aspect-specific methods like getPointcuts() and getAdvice(). These return more aspect-specific details including PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we utilize the Eclipse weaving provider to weave into JDT. One collection of join information that are urged are the ones connected with the development of CompilationUnit stuff. In the event the document has actually are *.aj document, AJCompilationUnit is generated in place of a typical Java collectiondevice.

Having the contents of an AJCompilationUnit

Because JDT expects that resource it functions with does work Java signal, JDT does not work better with AspectJ. In order to get with this, AJCompilationUnits maintain two buffers containing provider items. The foremost is a java suitable buffer and also the 2nd will be the initial information buffer. The java suitable buffer will be the buffer which returned automagically when AJCompilationUnit.getContents() is named. This buffer offers the AspectJ signal with all of aspect-specific syntax removed on. The original information buffer have (while you would anticipate) the original information from the file.

For instance when the original content buffer looks like:

the coffee suitable buffer is

Realize that the source stores regarding the identifiers are the same in both buffers. This means that resource searching and hyperlinking work as you expected.

In the event that you call for working together with the original content material of an AspectJ CompilationUnit ajUnit, you can do the annotated following:

Just what this technique does asks for the AJCU to briefly change its buffer on the AJ buffer from Java buffer. It is best to try this in a synchronized block so you do not exposure some other posts coming by and accidentally using the wrong buffer (AJDT by itself does not need a synchronized block with this, it should).

Making use of the AspectJ AST parser

Important example, obtained from bug 88861

Gather these and operate it:

Understood limits, insects, and exceptional problem

Constraint: there was currently no AST assistance for resolving sort bindings: insect 146528