Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Adding field with Annotation in ModelInferer
Adding field with Annotation in ModelInferer [message #1740319] Thu, 11 August 2016 11:05 Go to next message
Eclipse UserFriend
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 11:21 Go to previous messageGo to next message
Eclipse UserFriend
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()
			]
Re: Adding field with Annotation in ModelInferer [message #1740322 is a reply to message #1740319] Thu, 11 August 2016 11:23 Go to previous messageGo to next message
Eclipse UserFriend
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 14:17 Go to previous messageGo to next message
Eclipse UserFriend
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 14:57 Go to previous message
Eclipse UserFriend
have a look at org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedFeatures
Previous Topic:Serialization of unordered group yields invalid model code
Next Topic:Xtext Project from or with Ecore model
Goto Forum:
  


Current Time: Sat Apr 26 18:24:54 EDT 2025

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

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

Back to the top