Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » AspectJ declare annotation issue
AspectJ declare annotation issue [message #596507] Wed, 14 November 2007 15:50
louie liu is currently offline louie liuFriend
Messages: 2
Registered: July 2009
Junior Member
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
Previous Topic:AspectJ declare annotation issue
Next Topic:VerifyError in instantiation
Goto Forum:
  


Current Time: Fri Apr 19 20:51:20 GMT 2024

Powered by FUDForum. Page generated in 0.03333 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top