1

I came across an answer from @kriegaex , which I am unable to comprehend.

The pointcut expression I am trying to understand is the following

@Around("execution(* (@MyAnnotation *).*(..)) || execution(@MyAnnotation * *(..))")

As I understand , this expression will advice any class or method annotated with @MyAnnotation

From the reference documentation , the format of an execution expression is as follows:

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern)
            throws-pattern?)

Based on this format , the following expression

execution(* (@MyAnnotation *).*(..))

can be explained as

ret-type-pattern is * 
declaring-type-pattern is any type with @MyAnnotation
name-pattern is *
param-pattern is ..

to advice any method call in a class annotated with @MyAnnotation. Please correct me if I am wrong .

And for this expression

execution(@MyAnnotation * *(..))

I am unable to understand how modifiers-pattern can be @MyAnnotation ? How does this work ?

R.G
  • 6,436
  • 3
  • 19
  • 28

1 Answers1

3

That is an interesting question. Someone is reading documentation, wow! :)

Documentation maintenance is kind of a problem in AspectJ because nowadays development is mainly a one man show performed by Andrew (Andy) Clement. He is mostly busy keeping up with the Java release cycle and the new language features, e.g. there already is a developer version out with Java 14 support (record classes).

The syntax description on the Spring website has been taken from the AspectJ Programming Guide which it also points to. While the definition is still valid, the programming guide has been written in the pre Java 5 era, i.e. long ago, and IMO not updated since then. You might notice that it does not even mention annotations at all.

Everything related to annotations is written in the so-called The AspectJ 5 Development Kit Developer's Notebook and there you find a small paragraph mentioning:

Every join point has a single set of modifiers - these include the standard Java modifiers such as public, private, static, abstract etc., any annotations, and the throws clauses of methods and constructors. These modifiers are the modifiers of the subject of the join point.

So for AspectJ, method or class annotations are part of their group of modifiers, as you correctly noted already.


Update: You might want to think about investing in the book "AspectJ in Action" by Ramnivas Laddad. It is also old (2nd edition from 2009), but covers the basics of both AspectJ and Spring AOP in a solid way. Here is a screenshot, I hope Ramnivas and/or the publisher don't sue me for that. It is meant to be an incentive to buy the book:

Method and constructor signature patterns


Update 2: It looks as if now the complete book can even be read online for free. The chapter from the screenshot is here, for example.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • I would never have found that information on my own. A construct like `execution(* *.(@MyAnnotation)*(..))` is what might have made it easier for me to understand .Thank you ! – R.G Apr 27 '20 at 03:19
  • 1
    LOL, don't you think I didn't have to search for it. Some of my favourite tools like Spock and Geb have optional single-page versions of the documentation, AspectJ does not. The whole scattered set of manual-like and tutorial-like information needs to be refactored and spiced up by a lot of information only to be found in release notes, unit tests and Bugzilla tickets. That would be a hell of a job, especially in combination with making the whole structure easier to browse and search. When you are on one sub-page of the documentation, it is like a rabbit hole: Where am I? How to get out again? – kriegaex Apr 27 '20 at 03:53
  • 1
    Please note my update with info from and about the book "AspectJ in Action". – kriegaex Apr 27 '20 at 04:00
  • 1
    Much appreciated ! To be honest , my main source for Spring AOP related information are your posts in this forum :) . Thanks a lot !! – R.G Apr 27 '20 at 04:19