Hi Matthew, >From a quick look you don't appear to be using the right syntax for parameter annotations:
pointcut executingValidatedConstructorParameters() : execution(*.new(.., @javax.validation.constraints..* *, ..)); That means any constructor with a parameter *whose type* is annotated with an annotation from @javax.validation.constraints..*. The syntax is: execution(* *(..,@ParamAnnotation (@TypeAnnotation *),..)) so if you are leaving out the TypeAnnotation, you still need the parens: execution(*.new(..,@javax.validation.constraints..* (*),..)) so that the compiler can tell you mean param annotations and not type annotations. does that help? cheers, Andy On 10 September 2012 12:17, Matthew Adams <matt...@matthewadams.me> wrote: > Hi all, > > I'm trying to use a JSR-303 ValidationProvider (Apache BVal, to be > exact) along with an aspect to do POJO method & constructor > validation. I'd like to apply before advice to validated constructors > & methods, and after advice to validated return values, where > "validated" means the following. > > Constructors: > * Any parameter is annotated with any javax.validation.constraints annotation > > Methods (all must be true): > * Nonstatic method > * Any parameter is annotated with any javax.validation.constraints annotation > > Return value (all must be true): > * Nonstatic method > * Method annotated with any javax.validation.constraints annotation > > Here are my pointcuts. > > pointcut executingValidatedConstructorParameters() : > execution(*.new(.., @javax.validation.constraints..* *, ..)); > > pointcut executingInstanceMethod() : execution(!static * *(..)); > > pointcut executingValidatedReturnValue() : > executingInstanceMethod() && > execution((@javax.validation.constraints..* !void) *(..)); > > pointcut executingValidatedMethodParameters() : > executingInstanceMethod() && > execution(* *(.., @javax.validation.constraints..* *, ..)); > > They don't match anything. > > If I add a criterion "execution(@Valid *.new(..))" to > executingValidatedConstructorParameters, and "execution(@Valid * > *(..))" to executingValidatedMethodParameters & > executingValidatedReturnValue, then they match ok, but require me to > put the @Valid annotation on the method or constructor **in addition > to** whatever other constraint annotations (like @NotNull) are there, > which I feel is redundant. The presence of the actual constraint > annotation should be sufficient to trigger validation. > > Further, I noticed that if I change "@javax.validation.constraints..*" > to one of the actual constraint annotations, > "@javax.validation.constraints.NotNull", I get a new warning about > unmatched aspects: > > 'does not match because annotation > @javax.validation.constraints.NotNull has > @Target{ElementType.FIELD,ElementType.ANNOTATION_TYPE,ElementType.CONSTRUCTOR,ElementType.METHOD,ElementType.PARAMETER} > [Xlint:unmatchedTargetKind]' > > Then, I tried to change the annotation expression to match where > elementType includes ElementType.PARAMETER (and ElementType.METHOD for > executingValidatedReturnValue), but I couldn't figure out the syntax. > > So, how can I match constructors & methods where any parameter is > annotated with any javax.validation.constraints..* annotation, and > return values where the method is annotated with any > javax.validation.constraints..* annotation? > > Thanks, > Matthew > -- > mailto:matt...@matthewadams.me > skype:matthewadams12 > googletalk:matt...@matthewadams.me > http://matthewadams.me > http://www.linkedin.com/in/matthewadams > _______________________________________________ > aspectj-users mailing list > aspectj-users@eclipse.org > https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users