AspectJUltimate
AspectJ support in IntelliJ IDEA Ultimate is enabled by default and includes the following features:
Ability to create aspects in two forms: as .aj files and java files containing classes annotated with
@Aspect
.Coding assistance (including code completion) when writing aspect code. For annotation-style aspects, coding assistance is provided in full; for code-style aspects, assistance is limited to inter-type declarations.
Ability to perform basic aspect refactorings such as Rename and Move, and also the Push ITDs In refactoring for inter-type declarations.
Integration with the AcpectJ compiler ajc, which you can run right from the IDE. This compiler is part of the AspectJ distribution which you can download from the AspectJ website.
Ability to configure ajc at the project level with an option of fine-tuning its use at the level of individual modules.
Add a library with the AspectJ runtime to your project
Download and install AspectJ as described on the Downloads page. The AspectJ runtime aspectjrt.jar should be located in the installation directory under /lib.
Open the Project Structure dialog Ctrl+Alt+Shift+S and select Libraries.
note
If you want to add the new library for all projects, select Global Libraries.
Click
and select Java.
note
You can also select From Maven and search for aspectjrt.jar to add the AspectJ runtime from Maven Repository.
Specify the location of aspectjrt.jar in the file system.
Select the modules to which this library should be added and click OK.
Add AspectJ dependencies
Open the Project Structure dialog Ctrl+Alt+Shift+S and select Facets.
Click
and select AspectJ.
Select the modules for which you want to use this facet and click OK.
Select the new AspectJ facet for the relevant module and add dependencies as paths to corresponding aspects.
Create an aspect
After you add the necessary AspectJ library and dependencies, you can start developing your aspects.
In the Project tool window, select the directory where you want to create the aspect, press Alt+Insert, and select Aspect.
Specify the name and type of the aspect file, and click OK.
Aspect creates an .aj file with the specified name.
@Aspect creates a .java file containing a class annotated with
@Aspect
.
If necessary, you can refactor the source code of your aspects.
To compile your aspects using the AspectJ compiler ajc
, select it as the project compiler. ajc
is in aspectjtools.jar, which is located in the installation directory under /lib.