Developer’s guide to constructing gear over AJDT and AspectJ

This site is meant to help individuals building apparatus to give or deal with AJDT/AspectJ. Kindly contribute to these pages with any relevant information, such as for instance example rule utilizing the AJDT and/or AspectJ APIs.

These pages may be out of day. Our purpose is to upgrade this page for AJDT 1.6.1, but we’ve not had times with this yet. Kindly keep in mind that a few of what exactly is on this page may no longer feel appropriate. When you have any queries, kindly submit these to the mailing list ajdt-dev.

Contents

  • 1 getting crosscutting union suggestions from AJDT
  • 2 Collection Models in AJDT
    • 2.1 Acquiring the contents of an AJCompilationUnit
  • 3 Using the AspectJ AST parser
  • 4 Known restrictions, insects, and outstanding problem
  • 5 The software technology are anticipated to use to get the AspectJ compiler

Acquiring crosscutting union ideas from AJDT

In case you are establishing an eclipse plug-in and need access to crosscutting records whenever a venture is made, you’ll enter a listener with AJDT. Their plug-in will need to rely on 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 discover an IAdviceChangedListener screen with an individual adviceChanged() method.

Register this with all the AJBuilder course like this (within plug-in’s start() method for instance):

Currently (AJDT 1.6) this really is called after each develop of an AspectJ project (in other words. every *potential* guidance modification). In another production this can be optimized becoming only also known as in the event the information has actually changed. AJDT/UI uses this method to update the tangerine arrow picture decorator.

Crosscutting ideas are able to getting obtained from the AJProjectModelFacade course. Listed here is a good example which includes pseudo code it is possible to adapt:

Several notes concerning this:

  1. The API may have some lesser changes in tomorrow. Be sure to deliver a message toward ajdt-dev email list if everything on this web page is beyond date.
  2. The AJProjectModelFacade object was a light entrance in to the AspectJ industry. It is simply valid till the subsequent develop. Thus, you shouldn’t shop them. Make use of them and dispose as needed.
  3. AJProjectModelFacade items only include data following the first winning build. It is possible to name the possessModel() solution to see if an AspectJ model exists the task.
  4. As you can plainly see, you receive the relationship both in instructions. Discover AJRelationshipManager when it comes down to complete listing of affairs, to help you only require the partnership sort you have in mind.
  5. IRelationship.getSourceHandle() and IRelationship.getobjectives() return chain that represent AspectJ aspect handles. You need listed here AJProjectModelFacade ways to become model aspects:
    • toProgramElement(String) — comes back IProgramElement. From here you’ll be able to obtain information about the pointcut, intertype factor, or declare factor.
    • programElementToJavaElement(sequence) or programElementToJavaElement(IProgramElement) — returns IJavaElement. From here you can hook into JDT tooling.
  6. There is absolutely no needs to register a guidance changed listener. You may get use of the crosscutting unit anytime (so long as the project has already established an effective acquire) with the following laws:

Compilation Products in AJDT

JDT produces compilation units (instances of ICompilationdevice) for .java records. AJDT brings compilation models for .aj records, that are instances of aplikacja catholicmatch AJCompilationUnit (which implements ICompilationproduct). The course AJCompilationUnitManager (in org.eclipse.ajdt.core plug-in) consists of some useful means concerning this, such as for instance:

From an AJCompilationUnit possible receive numerous structural info eg getAllTypes(). The primary sort for «.aj» data is typically an element, that’s displayed by AspectElement course, containing aspect-specific practices including getPointcuts() and getAdvice(). These return more aspect-specific factors such PointcutElement and AdviceElement.

Since AJDT 1.6.2 for Eclispe 3.4, we use the Eclipse weaving solution to weave into JDT. One collection of join factors which can be suggested are those regarding the creation of CompilationUnit items. When the document keeps is *.aj document, AJCompilationUnit is created rather than a regular coffee Compilationproduct.

Getting the items in an AJCompilationUnit

Because JDT anticipates that most supply it really works with does work coffee laws, JDT does not work well with AspectJ. To get with this, AJCompilationUnits uphold two buffers containing supply items. The foremost is a java appropriate buffer additionally the second is the original content buffer. The java appropriate buffer will be the buffer that is came back by default whenever AJCompilationUnit.getContents() is known as. This buffer provides the AspectJ code with all of aspect-specific syntax removed completely. The original content material buffer have (as you would anticipate) the original content associated with the file.

Like when the initial contents buffer seems like:

the Java compatible buffer is

Realize that the foundation areas in the identifiers are exactly the same both in buffers. This makes sure that research getting and hyperlinking performs not surprisingly.

Any time you call for employing the initial contents of an AspectJ CompilationUnit ajUnit, you can do the following:

Just what this technique really does requests for the AJCU to temporarily change the buffer towards the AJ buffer from the coffee buffer. It’s always best to do this in a synchronized block so that you will never risk other threads coming by and accidentally utilising the incorrect buffer (AJDT alone does not make use of a synchronized block for this, nonetheless it should).

Making use of the AspectJ AST parser

Practical example, extracted from insect 88861

Make the above mentioned and operated it:

Recognized limits, bugs, and exceptional issues

Limitation: there can be presently no AST service for fixing kind bindings: insect 146528


Artículos Relacionados