Creator’s guide to creating technology in addition to AJDT and AspectJ

January 15, 2022

This site is meant to support anybody building equipment to extend or use AJDT/AspectJ. Kindly subscribe to these pages with any related suggestions, such as for instance sample rule by using the AJDT and/or AspectJ APIs.

These pages is beyond day. The purpose is update this page for AJDT 1.6.1, but we have perhaps not have opportunity because of this yet. Be sure to realize that a number of understanding about this webpage may no longer become proper. For those who have any queries, kindly send these to the email list ajdt-dev.

Information

  • 1 getting crosscutting connection suggestions from AJDT
  • 2 Compilation Units in AJDT
    • 2.1 obtaining the contents of an AJCompilationUnit
  • 3 utilizing the AspectJ AST parser
  • 4 Known limits, insects, and outstanding problems
  • 5 The program methods are expected to make use of to push the AspectJ compiler

Acquiring crosscutting relationship info from AJDT

In case you are establishing an eclipse plugin and require usage of crosscutting details whenever a project is created, possible sign up a listener with AJDT. The plug-in should rely on org.eclipse.ajdt.core, org.eclipse.core.resources and org.eclipse.jdt.core, and org.aspectj.weaver. In the org.eclipse.ajdt.core plug-in you will find an IAdviceChangedListener software with an individual adviceChanged() means.

Join this making use of AJBuilder class like this (within plug-in’s start() way for example):

Currently (AJDT 1.6) this might be also known as after every create of an AspectJ venture (in other words. every *potential* information modification). In a future launch this might be enhanced are best called if suggestions features actually altered. AJDT/UI uses this process to revise the tangerine arrow image decorator.

Crosscutting records are able to end up being obtained from the AJProjectModelFacade course. Listed here is a good example with a few pseudo code it is possible to adapt:

A number of notes about any of it:

  1. The API have some slight alterations in tomorrow. Be sure to deliver a note to the ajdt-dev mailing list if things with this web page may be out of go out.
  2. The AJProjectModelFacade object is a lightweight entrances in to the AspectJ industry. It can be valid through to the subsequent create. Very, do not save all of them. Make use of them and dispose as needed.
  3. AJProjectModelFacade objects merely incorporate information after the first effective build. You can phone the possessModel() approach to find out if an AspectJ design is present for your project.
  4. As you can see, you get the relationship both in information. Discover AJRelationshipManager for the complete directory of connections, to just request the partnership sort you find attractive.
  5. IRelationship.getSourceHandle() and IRelationship.getgoals() return Strings that express AspectJ component manages. You can use the following AJProjectModelFacade techniques to become model areas:
    • toProgramElement(String) — returns IProgramElement. From here you’ll be able to receive information on the pointcut, intertype factor, or declare element.
    • programElementToJavaElement(sequence) or programElementToJavaElement(IProgramElement) — comes back IJavaElement. From here you’ll hook into JDT tooling.
  6. There is absolutely no necessity to join up a recommendations changed listener. You may get accessibility the crosscutting design whenever you want (as long as your panels has already established an effective develop) utilising the following code:

Compilation Devices in AJDT

JDT produces compilation models (cases of ICompilationUnit) for .java files. AJDT creates compilation devices for .aj data, which are instances of AJCompilationUnit (which implements ICompilationdevice). The course AJCompilationUnitManager (inside the org.eclipse.ajdt.core plug-in) consists of some of good use means relating to this, such as for instance:

From an AJCompilationUnit you are able to acquire different structural info like getAllTypes(). The principal type for “.aj” documents is usually a piece, in fact it is symbolized from the AspectElement class, containing aspect-specific techniques particularly getPointcuts() and getAdvice(). These return furthermore aspect-specific areas such PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we use the Eclipse weaving services to weave into JDT. One pair of join factors which can be instructed are the ones about the production of CompilationUnit items. If file have are *.aj file, AJCompilationUnit is created in place of a regular Java Compilationproduct.

Acquiring the items in an AJCompilationUnit

Because JDT needs that most source it functions with holds true Java signal, JDT does not work better with AspectJ. To get with this, AJCompilationUnits uphold two buffers which contain provider items. The very first is a java compatible buffer together with 2nd may be the initial material buffer. The java compatible buffer will be the buffer that’s returned automagically when AJCompilationUnit.getContents() is known as. This buffer contains the AspectJ signal with aspect-specific syntax removed out. The original articles buffer contains (because would anticipate) the initial articles for the document.

Eg if the earliest content material buffer appears like:

the coffee compatible buffer becomes

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

If you need using the services of the original contents of an AspectJ CompilationUnit ajproduct, you can do the immediate following:

What this method do asks for the AJCU to temporarily change their buffer towards AJ buffer from the Java buffer. It is best to try this in a synchronized block so you never risk other threads coming by and accidentally utilizing the incorrect buffer (AJDT by itself does not make use of a synchronized block because of this https://datingranking.net/loveroulette-review/, but it should).

Utilizing the AspectJ AST parser

Basic example, extracted from insect 88861

Compile the above mentioned and operate it:

Understood limits, pests, and outstanding problem

Constraint: There is presently no AST support for fixing means bindings: insect 146528