I need a pointcut for methods in classes annotated with @X or methods annotated with @X. I also need the annotation object. If both the class and the method are annotated I prefer to get the method annotation as argument.
I tried the following, which creates an "inconsistent binding" warning. (Why not just set them null?)
@Around("@annotation(methodLevelX) || @within(classLevelX)")
public Object advise(ProceedingJoinPoint pjp, X methodLevelX, X classLevelX)
The following creates a "ambiguous binding of parameter(s) x across '||' in pointcut" warning. (Which does not necessarily make sense in my opinion: Why not bind the first short circuited evaluation?)
@Around("@annotation(x) || @within(x)")
public Object advise(ProceedingJoinPoint pjp, X x)
Splitting the previous attempt in two naturally results in two method calls if class and method annotations are present.
I know I could just get the method and class with reflection and my desired annotation with a pointcut like this:
@Around("@annotation(com.package.X) || @within(com.package.X)")
But I'd prefer not to.
Is there any "one pointcut, one method, one annotation argument", solution for my requirement that does not require reflection?