Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] How can I use 'declare' to verify that a class implements a certain interface?

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


Back to the top