Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to add annotations to generated class
How to add annotations to generated class [message #880616] Sat, 02 June 2012 12:53 Go to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Hi,

I just started to learn Xtext and decided to build a DSL to generate JPA entities. The first problem I encountered is how to add the @Entity annotation to the generated source ?

   	def dispatch void infer(Entity element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
   	    acceptor.accept(   			
   		buildClass(element)
   	    ).initializeLater([type |
		// do something
	    ])
   	}
   	def buildClass(Entity element) {
	   val result = element.toClass(element.name)   			   		
	   result.setDocumentation("Generated JPA entity")
           ??????? how to add an annotation ?????
	   result
   	}


Regards
Roger

[Updated on: Sat, 02 June 2012 12:54]

Report message to a moderator

Re: How to add annotations to generated class [message #880642 is a reply to message #880616] Sat, 02 June 2012 14:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

does the straight forward solution not work. e.g.

acceptor.accept(
			e.toClass( e.fullyQualifiedName ) [
				annotations += e.toAnnotation("org.eclipse.xtext.example.domainmodel.Entity")
]


please note: that api (annotation class) - in your case jpa
must be on the classpath of the model
project.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to add annotations to generated class [message #880944 is a reply to message #880642] Sun, 03 June 2012 12:55 Go to previous messageGo to next message
Roger Gilliar is currently offline Roger GilliarFriend
Messages: 40
Registered: March 2010
Member
Thanks it is working now. I was looking for something like addAnnotation or setAnnotation. Fortunately the Xtend syntax is so much nicer.

Regards
Roger
Re: How to add annotations to generated class [message #880948 is a reply to message #880944] Sun, 03 June 2012 13:08 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

just a hint: since ecore use lists you have to call getList.add() Smile
so in your case getAnnotations.add(....)
- the xtend syntax if nicer of course ;-I

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Objects' types in outline
Next Topic:Whats the meaning of isPreIndexingPhase
Goto Forum:
  


Current Time: Thu Oct 22 18:15:29 GMT 2020

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

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

Back to the top