This appears to work:
public aspect ModelCheck {
declare error:
within (@Entity mypackage.*) &&
!within(mypackage.MyInterface+): "Must implement
MyInterface";
}
but note that this doesn't:
declare error:
within (@Entity !mypackage.mypackage.MyInterface+):
"Must implement
MyInterface";
As an alternative, you could be more more optimistic: ;)
declare parents: (@Entity *) implements MyInterface
Then you'll get a regular compiler error for those
classes that
"forget" to implement the interfaces methods. This may
not meet your
needs if the interface is an empty marker interface, in
which case
you'll get no errors!
dean
On 1/8/06, Jeppe Cramon <jeppe@xxxxxxxxx> wrote:
Hi
I've stumbled across the need to enforce a contract,
using declare error,
that all classes that have the @Entity annotation also
needs to implement a
certain interface (here called MyInterface). Since
this() can't be used with
declare, I've tried to use staticinitialization()
instead, but it doesn't
work.
Does any one have a suggestion on how to implement
such a check?
Here's the sample aspect:
package com.betchallenge.model;
import com.myproject.MyInterface;
import javax.persistence.Entity;
public aspect ModelCheck {
declare error: within(@Entity *) &&
!staticinitialization(MyInterface):
"An Entity must implement MyInterface";
}
Thanks in advance :)
Best regards
Jeppe
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
Dean Wampler
http://www.aspectprogramming.com
http://www.newaspects.com
http://www.contract4j.org
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users