Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Intellij show warning if advice advices no method?

In my spring-boot application, I am using @AfterReturning to advice methods to be able to send some asynchronous notifications.

This is an example of the current implementation:

        @AfterReturning(pointcut = 
             "execution(* test.NotificationService.sendNotification(..)) && args(informees, dataList)")
        public void afterSendNotification(Informees informees, List<Data> dataList) {  
            ...
        }

During development the signature of the sendNotification method changed from sendNotification(Informees informees, Data data) to sendNotification(Informees informees, List dataList). The problem is that the pointcut does not advice the method anymore and no error or warning is shown. The gutter icon in intellij is just telling me that the "Advice advices no method". Therefore it is hard to see immediately that the code is not functioning correctly anymore.

  1. Is there a way to get an overview in intellij that shows all adviced methods for the advices?
  2. Can I get a warning if a advice advices no method?
  3. Is there a better way to write the pointcut?
  4. Currently im looking into writing unit tests to make sure that the advices are executed. Is this the way to go?
like image 733
Sebastian Avatar asked Sep 17 '25 11:09

Sebastian


1 Answers

IntelliJ IDEA is lacking such functionality, unfortunately. It also does not fully support the complete AspectJ syntax. There are many shortcomings in this otherwise so brilliant IDE which is my personal favourite compared to others. But whenever I want to do something in AspectJ I switch to Eclipse which is far superior in this regard, maybe because AspectJ is actually an Eclipse project and better maintained IDE-wise. There you have an Xref (cross-reference) view and views for which poinctut is used where in both directions, from aspect to application code and vice versa. See my other answer for a few screenshots. Update: The last one shows the visual indicators in the editor and the problem view for advices that do not match any joinpoints. This is what you asked for.

You get the best of both worlds if you use a Maven project using AspectJ Maven plugin. This can be imported into both IDEA and Eclipse, so you can work in IDEA most of the time, but manage your aspects utilising the better aspect support in Eclipse. Sorry for not having better news for you, but JetBrains is veeeery slow and reluctant with regard to working on AspectJ-related support tickets or feature requests.

like image 89
kriegaex Avatar answered Sep 20 '25 00:09

kriegaex