oops, sorry, I missed some key pairs of parens about. Parameter annotations being included in the method signatures really pushed the syntax to the limits. There is discussion here: http://andrewclement.blogspot.com/2009/02/aspectj-advising-methods-with-parameter.html
but the problem is that pointcut first(Object o): execution(* *((@NotNull *),..)) && args(o,..); means when the parameter is of a type annotated with @NotNull. Whilst this means a parameter annotated with @NotNull: pointcut first(Object o): execution(* *((@NotNull (*)),..)) && args(o,..); Notice extra parens around the '*' to disassociate the annotation from being attached to the type. my fault, shouldn't write code purely in my email client :) cheers, Andy On 15 December 2011 10:54, Mark <[email protected]> wrote: > Thanks for the reply. Unfortunately, something is wrong with your example. I > am trying to implement it, but it does not work. > > Given the following declarations: > ============================================== > package com.shunra.poc; > > import java.lang.annotation.ElementType; > import java.lang.annotation.Target; > > @Target({ ElementType.PARAMETER }) > public @interface NotNull { > } > ============================================== > package com.shunra.poc; > > public aspect NotNullAspect { > pointcut first(Object o): execution(* *((@NotNull *),..)) && args(o,..); > // line 4 > pointcut second(Object o): execution(* *(*,(@NotNull *),..)) && > args(*,o,..); // line 5 > pointcut third(Object o): execution(* *(*,*,(@NotNull *),..)) && > args(*,*,o,..); // line 6 > > before(Object o): first(o) { > checkNotNull(o); > } > > private void checkNotNull(Object o) { > // TODO Auto-generated method stub > > } > } > ============================================== > > I get the following warnings for the lines 4,5 and 6 respectively: > ============================================== > does not match because annotation @com.shunra.poc.NotNull has > @Target{ElementType.PARAMETER} [Xlint:unmatchedTargetKind] > NotNullAspect.aj > /Server/src/com/shunra/poc line 4 Java Problem > does not match because annotation @com.shunra.poc.NotNull has > @Target{ElementType.PARAMETER} [Xlint:unmatchedTargetKind] > NotNullAspect.aj > /Server/src/com/shunra/poc line 5 Java Problem > does not match because annotation @com.shunra.poc.NotNull has > @Target{ElementType.PARAMETER} [Xlint:unmatchedTargetKind] > NotNullAspect.aj > /Server/src/com/shunra/poc line 6 Java Problem > ============================================== > > What is wrong? > > Thanks. > > -- > View this message in context: > http://aspectj.2085585.n4.nabble.com/Is-it-possible-to-define-a-scope-of-methods-accepting-at-least-one-non-primitive-argument-tp4195341p4201202.html > Sent from the AspectJ - users mailing list archive at Nabble.com. > _______________________________________________ > aspectj-users mailing list > [email protected] > https://dev.eclipse.org/mailman/listinfo/aspectj-users _______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
