Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Model instance( derived from the metamodel .ecore) to Java code using xtend2
Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #705147] Fri, 29 July 2011 13:51 Go to next message
Chandan  is currently offline Chandan Friend
Messages: 12
Registered: July 2011
Location: Zurich
Junior Member
I'm new to xtend2.


I have defined metamodel(my.ecore) then created the model instance like (aaa.my) I would like to refer this model instance in xtend2 template to generate java code.

I donot want to use the xtext grammar to generate the (.ecore file ) since I already have one.



Is there a way how I can achieve this , i can imagine writing the mwe2 file( in a way we write .mwe file to read the model instance and the xpand template file(.xpt)) but have no idea what this file consists of.

Thanks in advance

[Updated on: Fri, 29 July 2011 13:55]

Report message to a moderator

Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #705387 is a reply to message #705147] Fri, 29 July 2011 20:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i just blogged on this

http://christiandietrich.wordpress.com/2011/07/29/xtend2-code-generators-with-non-xtext-models/

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 29 July 2011 20:18]

Report message to a moderator

Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #708891 is a reply to message #705387] Wed, 03 August 2011 09:03 Go to previous messageGo to next message
Chandan  is currently offline Chandan Friend
Messages: 12
Registered: July 2011
Location: Zurich
Junior Member
Thanks Christian for the above article, this was very helpful.

Chandan

[Updated on: Mon, 15 August 2011 08:52]

Report message to a moderator

Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #715722 is a reply to message #708891] Mon, 15 August 2011 10:01 Go to previous messageGo to next message
Chandan  is currently offline Chandan Friend
Messages: 12
Registered: July 2011
Location: Zurich
Junior Member
Is there a way to invoke xtend2(.xtend) template from java code instaed of using (mwe2 file). I searched a lot but didn't find any example, though I found an example on how to invoke Xpand template from java code but this is not exactly what I want.

Any help here would be appreciated.
Thanks in advance
~Chandan

[Updated on: Mon, 15 August 2011 10:02]

Report message to a moderator

Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #715723 is a reply to message #715722] Mon, 15 August 2011 10:03 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

normally an Xtend2-Template is compiled into a java class which you can "invoke".

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #715814 is a reply to message #715723] Mon, 15 August 2011 16:20 Go to previous messageGo to next message
Chandan  is currently offline Chandan Friend
Messages: 12
Registered: July 2011
Location: Zurich
Junior Member
Alex, I can understand that would be a normal java method invocation.

This is what i can think of now to test the Template invocation through java :
I created a test class to test this.

public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// Initialize the model
StatemachinePackage.eINSTANCE.eClass();
MyDslGenerator myDslGenerator = new MyDslGenerator(); // java class for the Xtend template
// Obtain a new resource set
ResourceSet resourceSet = new ResourceSetImpl();
// Register the XMI resource factory for the .statemachine extension
resourceSet
.getResourceFactoryRegistry()
.getExtensionToFactoryMap()
.put("statemachine", new XMIResourceFactoryImpl());
Resource resource = resourceSet.getResource(URI.createURI("model/My.statemachine"), true);

myDslGenerator.doGenerate(resource, new JavaIoFileSystemAccess());
}
}

But Now I'm getting this exception :

Exception in thread "main" java.lang.IllegalArgumentException: A slot with name 'DEFAULT_OUTPUT' has not been configured.
at org.eclipse.xtext.generator.JavaIoFileSystemAccess.generateFile(JavaIoFileSystemAccess.java:23)
at org.eclipse.xtext.generator.AbstractFileSystemAccess.generateFile(AbstractFileSystemAccess.java:34)
at test.MyDslGenerator.doGenerate(MyDslGenerator.java:30)
at test.Test.main(Test.java:30)

I dont know how to initialize the slot or am I doing something wrong here.
~Chandan
Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #715838 is a reply to message #715814] Mon, 15 August 2011 17:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

maybe you should follow the error message and configure your JavaIoFileSystemAccess()
see org.eclipse.xtext.generator.GeneratorComponent.getConfiguredFileSystemAccess()

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #715840 is a reply to message #715814] Mon, 15 August 2011 17:53 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

if I create a new Xtext project and run the workflow, a generator package is generated as well. It contains a Main.java containing the following lines (note the comment)
// configure and start the generator
fileAccess.setOutputPath("src-gen/");
generator.doGenerate(resource, fileAccess);


Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #716018 is a reply to message #715838] Tue, 16 August 2011 08:27 Go to previous messageGo to next message
Chandan  is currently offline Chandan Friend
Messages: 12
Registered: July 2011
Location: Zurich
Junior Member
Thnx Christian. I got it how to configure.
~Chandan
Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #716019 is a reply to message #715840] Tue, 16 August 2011 08:28 Go to previous messageGo to next message
Chandan  is currently offline Chandan Friend
Messages: 12
Registered: July 2011
Location: Zurich
Junior Member
Thnx Alex. I got the generator to work
~Chandan
Re: Model instance( derived from the metamodel .ecore) to Java code using xtend2 [message #718128 is a reply to message #715722] Tue, 23 August 2011 10:47 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Xtend2 is compiled to java, so why not call the generated Java method?

Am 15.08.11 12:01, schrieb Chandan:
>
> Is there a way to invoke xtend2(.xtend) template from java code. I
> searched a lot but didn't find any example, though I found an example on
> how to invoke Xpand template from java code but this is not exactly what
> I want.
>
> Any help here would be appreciated.
> Thanks in advance
> ~Chandan


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Folding swallowed newlines
Next Topic:GMF synchronization with XTEXT2
Goto Forum:
  


Current Time: Fri Mar 29 14:05:47 GMT 2024

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

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

Back to the top