Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding new fields in code generator(code generator)
Adding new fields in code generator [message #964558] Tue, 30 October 2012 16:12 Go to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
Hi,

I'm using http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/ way of code generating.
and i want to use it to add field in my xtext project on some of the generated classes
out of it scope

how can it be done?
Re: Adding new fields in code generator [message #964814 is a reply to message #964558] Tue, 30 October 2012 20:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

Fields are EAttributes (or EReferences)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding new fields in code generator [message #965639 is a reply to message #964814] Wed, 31 October 2012 11:52 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
great. Thank you very much!
can you please give me an example to do so.

attached is my current xtend file
which generate the following code in "ObjectValue" object:
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getFullName()
{
return null;
}


I want to add a new attribute to the class.

[Updated on: Wed, 31 October 2012 11:52]

Report message to a moderator

Re: Adding new fields in code generator [message #965645 is a reply to message #965639] Wed, 31 October 2012 11:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
def handle (EClass c) {
val attr = EcoreFactory::eINSTANCE.createEAttribute
attr.name = "test"
attr.EType = EcorePackage::eINSTANCE.EString
c.EStructuralFeatures += attr
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding new fields in code generator [message #965672 is a reply to message #965645] Wed, 31 October 2012 12:19 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
amazing! thank you!
how can i change the type to internal object, which not in the EcorePackage instances?
Re: Adding new fields in code generator [message #965703 is a reply to message #965672] Wed, 31 October 2012 12:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not sure what you are talking about


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding new fields in code generator [message #965721 is a reply to message #965703] Wed, 31 October 2012 13:04 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
attr.EType = EcorePackage::eINSTANCE.EString


can it be changed from 'String' to 'MyObject'?
Re: Adding new fields in code generator [message #965732 is a reply to message #965721] Wed, 31 October 2012 13:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Good question I think you need to add an additional edatatype to the
epackage for that

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding new fields in code generator [message #965735 is a reply to message #965732] Wed, 31 October 2012 13:17 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
Sorry for bothering you but how do I do that?
Re: Adding new fields in code generator [message #965808 is a reply to message #965721] Wed, 31 October 2012 14:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
As is said. You have to create a own edatatype. You will find
background information on that when you search the web. Please note:
this is 0% Xtext specific.

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding new fields in code generator [message #965820 is a reply to message #965808] Wed, 31 October 2012 14:29 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
ok, great! Thank you very much!
It was really helpful!
Re: Adding new fields in code generator [message #971015 is a reply to message #965820] Sun, 04 November 2012 14:08 Go to previous messageGo to next message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
Is it relevant also if I want to use Iterator<T> as the return type?

thank you very much Smile
Re: Adding new fields in code generator [message #971140 is a reply to message #971015] Sun, 04 November 2012 16:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I am not quite sure if you are on the right track. Why do you want to
do such things? Why do you need to customize your metamodel that
much? Sounds like it is time to switch to a manually maintained one.

PS guess it gets a list automatically if you set the upper bounds
property.

--
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding new fields in code generator [message #972474 is a reply to message #971140] Mon, 05 November 2012 17:02 Go to previous message
Dana Klein is currently offline Dana KleinFriend
Messages: 63
Registered: October 2012
Member
I want to implement an iterator method on one of my models.

such that in my model will be:
public java.util.Iterator<TerminalObject> elements () {...}

Thanks

the questions were for different models...

anyways, thank you Smile
Previous Topic:Dealing with custom implementation of Ecore beans
Next Topic:Hand over properties from Maven to MWE2 Workflow Descriptor
Goto Forum:
  


Current Time: Thu Apr 18 03:37:43 GMT 2024

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

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

Back to the top