Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to create annotations with attributes
How to create annotations with attributes [message #903858] Sun, 26 August 2012 16:32 Go to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Hi, I would like to create some JPA annotations. For example @Column(name="name"). So far I create the @Column annotation like this:

val field = f.toField(f.name, f.type) [
	annotations += f.toAnnotation("javax.persistence.Column") => [
            //?
	]
]


One of the seven language examples uses createJvmStringAnnotationValue. But I couldn't find this method anywhere.

Regards
Roger
Re: How to create annotations with attributes [message #903859 is a reply to message #903858] Sun, 26 August 2012 16:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

have a look at the class org.eclipse.xtext.common.types.TypesFactory


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to create annotations with attributes [message #904083 is a reply to message #903859] Mon, 27 August 2012 18:06 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
I tried but I can make no sense of this API. So far I get @Column("Name") but I would like tot get @Column(test="Name"). My code looks like this:

val field = f.toField(f.name, f.type) [		
	annotations += f.toAnnotation("javax.persistence.Column") => [
	values += createJvmStringAnnotationValue() => [
	    values += "Name"
	]
   ]
]


I would have expected that the following code should work:

val field = f.toField(f.name, f.type) [		
	annotations += f.toAnnotation("javax.persistence.Column") => [
	values += createJvmStringAnnotationValue() => [
	    values += "Name"
            valueName = "test"   // but valueName ist read only
	]
   ]
]


But valueName is read only.

Regards
Roger

[Updated on: Mon, 27 August 2012 18:06]

Report message to a moderator

Re: How to create annotations with attributes [message #904091 is a reply to message #904083] Mon, 27 August 2012 18:28 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Ok,

the following works:

val a = f.toAnnotation("javax.persistence.Column")
val v = createJvmStringAnnotationValue
val op = a.annotation.members.filter(typeof(JvmOperation)).filter(o|o.simpleName == "name").head
v.operation = op
v.values += f.name
a.values += v

Must it really be that complicated ?

Regards
Roger
Re: How to create annotations with attributes [message #904094 is a reply to message #904091] Mon, 27 August 2012 18:31 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
http://www.eclipse.org/forums/index.php/mv/msg/271349/773704/#msg_773704

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:mwe-file not found building with fornax-tools
Next Topic:Runtime instance error after upgrading to Juno + xtext 2.3
Goto Forum:
  


Current Time: Thu Mar 28 17:39:31 GMT 2024

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

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

Back to the top