Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Generating Objects(Generating objects with additional properties)
Generating Objects [message #953886] Mon, 22 October 2012 16:08 Go to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
Hi,

I want to know how (if possible) to generate more properties on objects in xtext.

I have xtext file similar to the xtext describe in here:
(www.ebpml.org/blog2/index.php/2010/11/05/mde-xtext-and-json)

JSONDataSource: root = Object ;
Object: '{' firstObject=TerminalObject (',' objects+=TerminalObject)* '}';
Array: '['firstItem=ObjectValue (',' items+=ObjectValue)* ']';
EmptyObject: isEmpty?= '{}' ;
EmptyArray: isEmpty?= '[]' ;
ObjectValue: value=STRING | Object | Array | EmptyObject | EmptyArray ;
TerminalObject: element=STRING ':' (content = ObjectValue) ;

So after generating the code I have all the objects generated in java and now in order to get into a TerminalObject content ("b" -> such as "a":"b") i need to iterate the object until i get there, so what i'm asking exactly can I generate more properties than the basic one?
Re: Generating Objects [message #954806 is a reply to message #953886] Tue, 23 October 2012 09:05 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
Should it be done by xtend? if so, can you please provide an example how to implement the doGenerate method for the Q above..
Re: Generating Objects [message #955955 is a reply to message #954806] Wed, 24 October 2012 05:57 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13607
Registered: July 2009
Senior Member
Hi I am not sure if I get your question. Could you please elaborate
what you want to do if you speak of generate? Do you mean the Xtext
generator that generates the ecore (and the ecore java classes) or do
you mean your code generator? If you mean the latter you might find
useful methods in the class ecoreutil2 to navigate and filter your
object tree.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


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: Generating Objects [message #956109 is a reply to message #955955] Wed, 24 October 2012 08:47 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
My goal is to take out of json file, the relevant schema name.

1) by simply calling a method which being generated in TerminalObjectImpl (e.g.)
2) or by iterating the json file until i got the schema name.

a.json
------
"json_schema" : {
"schema_name" : "my_schema.json"
}

the my_schema.json is the schema which i want for a.json file.

have any suggestions how to do so?
thank you very much!
Re: Generating Objects [message #956236 is a reply to message #956109] Wed, 24 October 2012 10:41 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13607
Registered: July 2009
Senior Member
Depending where you need a simple Xtend extension should the trick.
Alternatively you can use a post processor to add a operation to the
derived metamodel or use a manually maintained metamodel to add the
operation there. You might find topics on both in the forum

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


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: Generating Objects [message #961611 is a reply to message #956236] Sun, 28 October 2012 12:30 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
Hi Christian,

thank you very much.
I mixed two Q. Embarrassed
therefore the misunderstanding.

the thing is, I want to know if it is possible to add more methods to a generated class of xtext.
for example in the xtext describe in here:
(www.ebpml.org/blog2/index.php/2010/11/05/mde-xtext-and-json)

you can see that there is an array object which the generator will generate 'Array' and 'ArrayImpl' objects
I want to add some method to the 'ArrayImpl', is that possible?
(attached is the 'ArrayImpl' class)
if yes, what are the options in order to do so?
Re: Generating Objects [message #961681 is a reply to message #961611] Sun, 28 October 2012 13:51 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13607
Registered: July 2009
Senior Member
Hi,

yes this is. there are several possibilities

(1) use a manually maintained metamodel
(2) postprocess the metamodel as described
http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/


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: Generating Objects [message #961787 is a reply to message #961681] Sun, 28 October 2012 15:52 Go to previous message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
great! Thank you so much! Smile
Previous Topic:Proposal for Jvm subtypes
Next Topic:Adding API to access ImportManager or to add imports to ITreeAppendable
Goto Forum:
  


Current Time: Fri Sep 25 10:25:26 GMT 2020

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

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

Back to the top