@DeclareParents [message #63097] |
Thu, 23 March 2006 23:42 |
Eclipse User |
|
|
|
Originally posted by: skingdon.mmm.com
I am using @AspectJ annotation style development. Thumbs up to whomever
decided to do it this way. I like it. However I think I might be way to
early in trying to use it. @DeclareParents does not appear to be working.
I found this
( http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01841.ht ml) posting
and its related messages. I am wondering if this is still not in? Or am I
missing something?
Here is the code I am running. It was taken from
http://static.springframework.org/spring/docs/2.0-m2/referen ce/ataspectj.html
and was slightly modified. It assumes an implementation of a Lockable
interface which has three methods: void lock(), void unlock(), boolean
locked(). It also assumes you have a class (HelloAnnotetedAOP - just a
hello world type class) to weave into.
@Aspect
public class AnnotatedAspect {
@DeclareParents(value="HelloAnnotetedAOP",
defaultImpl=DefaultLockable.class)
public static Lockable mixin;
@Pointcut("execution(* *())")
void anyExecution() {}
@Before(value="anyExecution() && this(mixin)")
public void checkNotLocked(Lockable mixin) {
if (mixin.locked()) System.out.println("Locked!...");
else System.out.println("Not locked!...");
}
@Before("anyExecution()")
public void doBefore() {
System.out.println("Hello before!...");
}
@After("anyExecution()")
public void doAfter() {
System.out.println("Hello after!...");
}
}
This prints out:
Hello before!...
Hello after!...
|
|
|
|
|
Powered by
FUDForum. Page generated in 6.88054 seconds