Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding field with Annotation in ModelInferer
Adding field with Annotation in ModelInferer [message #1740319] Thu, 11 August 2016 15:05 Go to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
Hello everyone,

I want to add an field to the ModeInferer which has an Annotation like

@Extension MathuUtil util = new MathUtil();

How this can be done?

model.toField('util', typeRef('MathUtil'))[
//addAnnotation()
initializer='''new MathUtil();'''
]

How can I put the Extension Annotation in this?

Thanks a lot.

Best regards
Dim
Re: Adding field with Annotation in ModelInferer [message #1740321 is a reply to message #1740319] Thu, 11 August 2016 15:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi the straight forward way is not working

members += model.toField("xxxxx", String.typeRef) [
				initializer = '''"Hello World!"'''
				annotations += "javax.inject.Inject".annotationRef()
//or                         annotations += javax.inject.Inject.annotationRef()
			]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Adding field with Annotation in ModelInferer [message #1740322 is a reply to message #1740319] Thu, 11 August 2016 15:23 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear Dim.

Have you tried?
model.toField('util', typeRef('MathUtil'))[
annotations.addAnnotation(_annotationTypesBuilder.annotationRef(YourAnnotationType.class))
initializer='''new MathUtil();'''


The field _annotationTypesBuilder is inherited from AbstractModelInferrer.

Stéphane.
Re: Adding field with Annotation in ModelInferer [message #1740334 is a reply to message #1740322] Thu, 11 August 2016 18:17 Go to previous messageGo to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
Thanks all for the solution!

Another question is, how to add static extension imports eg.

import extension static de.hello.world.MathUtil.*

Dim
Re: Adding field with Annotation in ModelInferer [message #1740337 is a reply to message #1740334] Thu, 11 August 2016 18:57 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
have a look at org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedFeatures

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:Serialization of unordered group yields invalid model code
Next Topic:Xtext Project from or with Ecore model
Goto Forum:
  


Current Time: Sat Dec 14 19:57:37 GMT 2024

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

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

Back to the top