Creator’s guide to design knowledge over AJDT and AspectJ


Event blog


Hunter Thornton

25 september 2018

Creator’s guide to design knowledge over AJDT and AspectJ

This site is intended to aid people establishing methods to increase or work with AJDT/AspectJ. Be sure to contribute to these pages with any appropriate info, instance sample laws utilising the AJDT and/or AspectJ APIs.

This site is out of day. Our very own intent is to upgrade these pages for AJDT 1.6.1, but we now have maybe not got energy because of this yet. Kindly recognize that a number of something on this subject web page may no much longer feel proper. If you have any questions, be sure to deliver them to the subscriber list ajdt-dev.


  • 1 getting crosscutting relationship details from AJDT
  • 2 Compilation Devices in AJDT
    • 2.1 obtaining items in an AJCompilationUnit
  • 3 by using the AspectJ AST parser
  • 4 recognized limits, pests, and exceptional dilemmas
  • 5 The software knowledge are required to use to push the AspectJ compiler

Obtaining crosscutting partnership details from AJDT

If you should be creating an eclipse plugin and require usage of crosscutting ideas whenever a task is created, you can easily enroll a listener with AJDT. Your plug-in will need 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 there is certainly an IAdviceChangedListener user interface with one adviceChanged() means.

Join this using AJBuilder course like this (inside plug-in’s start() way for example):

Currently (AJDT 1.6) this is called after each and every acquire of an AspectJ project (i.e. every *potential* guidance changes). In the next production this might be optimized becoming only called if pointers have really changed. AJDT/UI utilizes this method to upgrade the orange arrow picture decorator.

Crosscutting ideas can then feel extracted from the AJProjectModelFacade lessons. Listed here is an illustration with some pseudo code it is possible to adapt:

A few records concerning this:

  1. The API possess some minor changes in the future. Kindly deliver a message with the ajdt-dev subscriber list if everything on this subject page is out of day.
  2. The AJProjectModelFacade item was a lightweight access in to the AspectJ globe. It is simply good through to the further acquire. Thus, don’t shop them. Make use of them and dispose as required.
  3. AJProjectModelFacade stuff only consist of information after the basic winning build. You can easily name the hasModel() approach to see if an AspectJ unit is available when it comes to task.
  4. Clearly, you receive the connection in instructions. Discover AJRelationshipManager for the complete selection of interactions, so you can simply request the partnership sort you are interested in.
  5. IRelationship.getSourceHandle() and IRelationship.getgoals() return Strings that represent AspectJ element manages. You can utilize this amazing AJProjectModelFacade ways to convert to model details:
    • toProgramElement(sequence) — returns IProgramElement. From here you can easily obtain details about the pointcut, intertype aspect, or declare factor.
    • programElementToJavaElement(sequence) or programElementToJavaElement(IProgramElement) — profits IJavaElement. From here you can catch into JDT tooling.
  6. There is absolutely no criteria to join up a suggestions changed listener. You could get usage of the crosscutting design whenever you want (provided your panels has experienced a fruitful develop) making use of the preceding laws:

Compilation Units in AJDT

JDT creates collection devices (cases of ICompilationproduct) for .java files. AJDT produces collection products for .aj data files, which have been cases of AJCompilationUnit (which implements ICompilationproduct). The category AJCompilationUnitManager (in org.eclipse.ajdt.core plug-in) consists of some useful means relating to this, including:

From an AJCompilationUnit it is possible to obtain various structural records like getAllTypes(). The principal type for “.aj” records is typically a piece, which is symbolized by the AspectElement lessons, containing aspect-specific methods such getPointcuts() and getAdvice(). These return furthermore aspect-specific factors such as PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we utilize the Eclipse weaving provider to incorporate into JDT. One collection of join factors that are suggested are the ones about the development of CompilationUnit stuff. In the event that file possess is *.aj document, AJCompilationUnit is made instead of a standard Java Compilationproduct.

Having the belongings in an AJCompilationUnit

Because JDT anticipates that resource it functions with does work Java code, JDT does not work better with AspectJ. In order to get for this, AJCompilationUnits uphold two buffers that contain supply materials. The foremost is a java suitable buffer and the 2nd may be the earliest content material buffer. The java suitable buffer could be the buffer that’s came back by default whenever AJCompilationUnit.getContents() is called. This buffer provides the AspectJ code with all of aspect-specific syntax stripped out. The initial articles buffer includes (when you would count on) the initial material of this document.

For instance when the original material buffer looks like:

the coffee suitable buffer becomes

Realize that the source stores regarding the identifiers are the same in both buffers. This makes sure that research acquiring and hyperlinking really works not surprisingly.

Should you need using the initial content of an AspectJ CompilationUnit ajdevice, you could do the following:

Just what this technique does requests for the AJCU to temporarily change singles dating sites free their buffer on the AJ buffer from the coffee buffer. It’s always best to do this in a synchronized block to make sure you you should not chance some other posts coming by and unintentionally by using the incorrect buffer (AJDT itself does not make use of a synchronized block for this, nevertheless should).

Utilizing the AspectJ AST parser

Practical example, extracted from insect 88861

Compile the aforementioned and manage they:

Identified restrictions, pests, and outstanding dilemmas

Restriction: You will find currently no AST assistance for fixing sort bindings: insect 146528

Hunter Thornton

25 September 2016 | 20:42

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of

Madison Saunder

25 September 2016 | 20:42

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of

Hunter Thornton

25 September 2016 | 20:42

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with


Add comment