1

In my current project I'm working with Java, Spring Boot and .aj files. However, the main problem about work with AspectJ is that there are not a lot of IDEs that supports this feature.

Eclipse (and i think that netbeans too) supports the AspectJ language because I've used it in the past. However, I've worked with IntelliJ and Visual Studio Code IDEs during the last years and I don't really want to come back to Eclipse (or Netbeans). :)

Also, I know that the Ultimate Version of IntelliJ has support to AspectJ. The problem is that you must have an IntelliJ license to use it.

https://www.jetbrains.com/help/idea/enabling-aspectj-support-plugins.html

I started to create a new language server for the Visual Studio Code to manage the .aj files. I'm following this guide.

https://code.visualstudio.com/docs/extensions/example-language-server

The .aj files are now correct colored and shows a valid syntax!

However, I'm getting errors in the Java code. Check this schema about the AspectJ description:

enter image description here

As you could see, I have a .java file called Point and I want to have some methods divided in some .aj files. When the project is compiled, I'll have just one Point.class that includes the methods clone(), compareTo(), etc.

Also, another possible use is that if my .java class implements some interface, I'm able to implements the methods in a .aj file.

Problem: I'm not able to see my Java project without errors because the .java files and the .aj files are not "synchronized", so the .java class says that needs to implements some methods although they're defined in the .aj file.

Someone could help me with tips about language server development?

Regards,

jcgarcia
  • 3,762
  • 4
  • 18
  • 32

1 Answers1

1

I can't help you with VS Code <> AspectJ integration, but I could recommend a work-around with your issue. If my understanding is correct, you get errors because the methods declared through inter-type declarations by your aspects are not visible to your java code.

In that case you might try to create Java 8 interfaces with default methods that declare and implement those methods. I would try to get rid of the aspects altogether and work with just interfaces with default methods, but if - for some reason unknown to me - you really need to use aspects to implement those methods, you can still leave your default methods empty and move the implementation into the aspects. This way you don't need to use inter-type declarations anymore, so VS Code integration might work better.

Nándor Előd Fekete
  • 6,988
  • 1
  • 22
  • 47
  • At first, thank you so much for your reply. I'm one of the responsibles of the Spring Roo project. This tool allows you to generate Spring Boot applications using commands. The generated project uses the .aj files to include the generated code that the tool maintains. If the code is in a .java file means that you have customized that code and Spring Roo should not manage. This was amazing in the past, but seems that AspectJ is not really actual... I thought about to use Java 8 Interfaces to replace the AspectJ in the past. Maybe I'll try it now that I have this issue! Thanks!! – jcgarcia Apr 20 '18 at 18:18
  • As much as I have used AspectJ in many different projects throughout my career, I would also be very cautious on introducing it as a hard dependency in any new project, unless there are *very substantial reasons* to do it. Unfortunately, AspectJ tends to lag behind Java in supporting the latest language features and tooling support as well. With the new Java release cycle shortened to 6 months this will be more and more an issue. If Roo could do the same what it does today with just native Java language features, that would be a future path very much worth considering. – Nándor Előd Fekete Apr 20 '18 at 21:35