Community
Participate
Working Groups
!within(@Annot *) works to exclude annotated classes, but within(!@Annot *) does not, though permitted syntactically in the AspectJ 5 developers guide. http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-pointcuts-and-advice.html#type-patterns (Taken from excellent user-list email "Combination of Class Annotation and Method Annotation matching" by Takao Nakaguchi.) -------------------------------------------------- package ajsandbox; public class AnnotTest { public static aspect TestAspect { // works - Derived.func() omitted //declare warning : execution(@Annot * *(..)) && !within(@Annot *): "hi!"; // fails - Derived.func() not omitted declare warning : execution(@Annot * *(..)) && within(!@Annot *) : "unexpected warning"; } @interface Annot { }; class Base { void func() { } } @Annot class Derived extends Base { // ok! and ng! @Annot void func() { } } class NoAnnotClass { // ng! @Annot void func() { } } }
interesting program. The reason this pointcut execution(@Annot * *(..)) && within(!@Annot *) matches against the first type is because of the use of an inner type. class AnnotTest { @Annot class Derived extends Base { @Annot void func() { } } } the method-execution of func() does kind of occur 'within' a non-annotated type, the AnnotTest type. If we annotate AnnotTest like this: @Annot class AnnotTest { @Annot class Derived extends Base { @Annot void func() { } } } then the pointcut no longer matches. So we have to think about the difference between: "!within(@Annot *)" and "within(!Annot *)". The first says "match join points that are not within an @Annot annotated type", the second says "match joinpoints that are within a non-@Annot annotated type".
testcase is committed but commented out