AspectJ declare annotation issue [message #70867] |
Wed, 14 November 2007 10:50 |
Eclipse User |
|
|
|
I have issue with the AspectJ declare annotation. The use case is that I
would like to add annotation to a given class field and the attribute
value of this annotation need to be evaluated at runtime, in another words
not a constant expression. For example:
import javax.persistence.ManyToOne;
import org.aspectj.lang.*;
import org.aspectj.lang.reflect.*;
import org.hibernate.annotations.ForeignKey;
public aspect AnnotationAspect {
declare @field: @ManyToOne * *: @ForeignKey(name="key" + "_key");
//working
declare @field: @ManyToOne * *: @ForeignKey(name="key" + getKey());
//not working
private String getKey() {
// some logic...
return "_key";
}
}
In the case of @ForeignKey(name="key" + getKey()), I got the following
compilation error:
compile:
[echo] compiling ...
[iajc] error at declare @field: @ManyToOne * *: @ForeignKey(name="key" +
this);
[iajc] ^^^^^^^^^^
[iajc] U:\projects\srm\wam-aspectJ\src\AnnotationAspect.java:17:0:: 0 The
value for annotation attribute ForeignKey.name must be a constant
expression
[iajc] MessageHolder: (19 info) (1 error)
[iajc] [error 0]: error at declare @field: @ManyToOne * *:
@ForeignKey(name="key" + this);
[iajc] ^^^^^^^^^^
[iajc] U:\projects\srm\wam-aspectJ\src\AnnotationAspect.java:17:0:: 0 The
value for annotation attribute ForeignKey.name must be a constant
expression
BUILD FAILED
I would like to know if there is some other way to make it work. The
important of this issue is that I would like to know in aspectJ, if there
is a way to evaluate the value of the annotation value before making the
assignment.
Thanks a lot.
Louie
|
|
|
Powered by
FUDForum. Page generated in 0.04017 seconds