Developer’s self-help guide to building apparatus above AJDT and AspectJ

January 20, 2022 Off By Virgil Olson

Developer’s self-help guide to building apparatus above AJDT and AspectJ

This site is intended to assist anybody establishing equipment to extend or work with AJDT/AspectJ. Be sure to play a role in these pages with any relevant suggestions, such as for example instance code utilizing the AJDT and/or AspectJ APIs.

These pages may be out of time. All of our intention should update these pages for AJDT 1.6.1, but we now have perhaps not got time because of this yet. Be sure to recognize that the what’s on this subject page may no longer getting proper. When you have any questions, be sure to submit them to the subscriber list ajdt-dev.

Information

  • 1 buying crosscutting union ideas from AJDT
  • 2 Compilation Products in AJDT
    • 2.1 having the belongings in an AJCompilationUnit
  • 3 Making use of the AspectJ AST parser
  • 4 Known restrictions, bugs, and outstanding dilemmas
  • 5 The program apparatus are anticipated to use to push the AspectJ compiler

Obtaining crosscutting partnership ideas from AJDT

If you are developing an eclipse plug-in and need access to crosscutting suggestions whenever a task is made, you are able to 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. In org.eclipse.ajdt.core plug-in there is an IAdviceChangedListener software with one adviceChanged() means.

Register this together with the AJBuilder course such as this (inside plug-in’s start() method for instance):

Currently (AJDT 1.6) this will be also known as after every acquire of an AspectJ project (i.e. every *potential* pointers change). In another launch this might be enhanced to get just labeled as if the guidance possess really altered. AJDT/UI uses this device to upgrade the lime arrow graphics decorator.

Crosscutting records can then getting obtained from the AJProjectModelFacade lessons. Here is an illustration which includes pseudo code you are able to adapt:

A number of notes about that:

  1. The API have some slight changes in tomorrow. Kindly submit a note to the ajdt-dev subscriber list if something about this page is beyond time.
  2. The AJProjectModelFacade item was a light entrance inside AspectJ world. It is simply good through to the further build. So, you shouldn’t put all of them. Make use of them and dispose as needed.
  3. AJProjectModelFacade stuff best consist of facts following the basic successful build. You’ll call the possessModel() solution to see if an AspectJ unit is available for any project.
  4. As you can tell, you receive the connection in both guidelines. Discover AJRelationshipManager for christian cupid complete set of interactions, so you’re able to merely inquire about the connection kinds you’re interested in.
  5. IRelationship.getSourceHandle() and IRelationship.getobjectives() return chain that express AspectJ element manages. You need to use the following AJProjectModelFacade solutions to convert to model elements:
    • toProgramElement(sequence) — profits IProgramElement. From here you can easily acquire information regarding the pointcut, intertype factor, or declare aspect.
    • programElementToJavaElement(sequence) or programElementToJavaElement(IProgramElement) — comes back IJavaElement. From this point you can hook into JDT tooling.
  6. There’s no prerequisite to join up an advice changed listener. You will get the means to access the crosscutting unit anytime (so long as your panels has received an effective build) with the following laws:

Compilation Units in AJDT

JDT creates compilation models (cases of ICompilationproduct) for .java documents. AJDT produces compilation products for .aj records, which have been cases of AJCompilationUnit (which implements ICompilationUnit). The course AJCompilationUnitManager (inside org.eclipse.ajdt.core plug-in) have some of use methods relating to this, such as for example:

From an AJCompilationUnit you can get various structural details for example getAllTypes(). The primary sort for “.aj” documents is typically an element, which will be symbolized by AspectElement lessons, containing aspect-specific methods such as for example getPointcuts() and getAdvice(). These return further aspect-specific items instance PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we utilize the Eclipse weaving solution to incorporate into JDT. One collection of join information which can be urged are the ones related to the development of CompilationUnit objects. If file has actually was *.aj file, AJCompilationUnit is generated rather than a regular Java collectionproduct.

Obtaining contents of an AJCompilationUnit

Because JDT expects that origin it works with holds true coffee laws, JDT can not work really with AspectJ. In order to get around this, AJCompilationUnits uphold two buffers that contain origin materials. The very first is a java appropriate buffer while the second may be the initial content buffer. The java appropriate buffer could be the buffer that will be returned automatically whenever AJCompilationUnit.getContents() is known as. This buffer provides the AspectJ code with all aspect-specific syntax removed . The original content buffer consists of (just like you would expect) the first content in the file.

Like in the event the original articles buffer appears like:

the coffee suitable buffer becomes

Observe that the foundation places in the identifiers are identical in buffers. This ensures that reference researching and hyperlinking work not surprisingly.

Should you need working with the initial articles of an AspectJ CompilationUnit ajproduct, you certainly can do the annotated following:

What this method does requests for the AJCU to temporarily switch the buffer on AJ buffer from coffee buffer. It’s always best to do that in a synchronized block to make sure you you shouldn’t risk various other threads coming by and accidentally utilising the incorrect buffer (AJDT by itself doesn’t make use of a synchronized block with this, nonetheless it should).

Making use of the AspectJ AST parser

Standard instance, extracted from insect 88861

Make the aforementioned and work it:

Recognized restrictions, bugs, and exceptional problems

Constraint: Discover at this time no AST help for solving type bindings: insect 146528