1

I am trying to write an advice to intercept the calls to constructors of a class with my custom annotation:

@MyCustomAnnotation
public class SomeClass {

   public SomeClass(Foo a, Bar b){
      ...
   }

   public SomeClass(Foo a){
      this(a, null);
   }

}

I see an example of how to intercept constructor calls, in general:

@Before("execution(*.new(..))")

How do I update this to only execute for classes that are annotated with my @MyCustomAnnotation annotation

user1154644
  • 4,491
  • 16
  • 59
  • 102

1 Answers1

1

I use this for method invocation:

within(@MyCustomAnnotation *)

So, the resulting aspect code would be:

@Before("execution(*.new(..)) && within(@MyCustomAnnotation *)")

Alternatively, try this:

@Pointcut("execution(@MyCustomAnnotation *.new(..))")

I am referring to the documentation here: https://blog.espenberntsen.net/2010/03/20/aspectj-cheat-sheet/

and, it should work in theory, but I am not having any luck.

Walter
  • 1,290
  • 2
  • 21
  • 46