Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » EGL 101
EGL 101 [message #774360] Tue, 03 January 2012 19:08 Go to next message
Yves Weissig is currently offline Yves Weissig
Messages: 9
Registered: January 2012
Junior Member
Hi,
I'm trying to accomplish some model-to-text transformation with EGL.
I've setup Xtext to parse a text to a model. After that I want to use ETL to transform the model, and finally I want to use EGL to "unparse" the model to text again. Xtext generates an implicit meta-model on the fly (attached .ecore). I'm using this one and a test setup to transform my model to text, but I don't get the EGL (EOL) syntax...
[% for (eobj in EObject.allInstances()) { %] 
	[% if (eobj.isTypeOf(Model)) { %]
		[% var m : Model := EObject.selectOne(e|e.isTypeOf(Model)); %]		
	[% } %]
	[% if (eobj.isTypeOf(CharData)) { %]
		[% var cd : CharData := new CharData; %]
		[% cd := EObject.selectOne(d|d.isKindOf(CharData)); %]
		[%cd.print();%]
		[%=cd.value%]
	[% } %]
[% } %]

What I basically trying in this EGL snippet is: Iterate each EObject (that should give me every object... because EObject is the supertype of everything) in my model... than look what type it is, according to the type do something with it, but: how do I type cast an EObject to XYZ? And how can I access the properties? Any suggestions? I'm really stuck here.
Best regards
Yves
Re: EGL 101 [message #774614 is a reply to message #774360] Wed, 04 January 2012 09:38 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris Kolovos
Messages: 886
Registered: July 2009
Senior Member
Hi Yves,

Could I suggest having a look at the examples demonstrating the EOL syntax (http://eclipse.org/gmt/epsilon/examples/ and http://eclipse.org/gmt/epsilon/live/)? The book should also help http://eclipse.org/gmt/epsilon/doc/book/.

In your example, there's no EClass called EObject in your metamodel and as such EObject.allInstances() shouldn't work. If you've named your model X in the launch configuration, you can get all its model elements using X.allContents(). As EOL is a dynamically-typed language, there's no need for type casting.

Cheers,
Dimitris

Re: EGL 101 [message #774752 is a reply to message #774614] Wed, 04 January 2012 14:25 Go to previous message
Yves Weissig is currently offline Yves Weissig
Messages: 9
Registered: January 2012
Junior Member
Hi Dimitris,

thanks for the answer, I somehow got it working this morning.
As a note... EObject was supposed to be Ecore's EObject, I imported the Ecore Meta-Model additionally to my own.
My code looks now like this:
[%
for (m in Model.allInstances()) { m.test(); }

operation Attribute test() {
	(self + " is an Attribute").println();
	out.print(self.key + "=" + self.value);
}
%]

Each of my objects "implements" such a test()-method.

Best regards
Yves
Previous Topic:[Eugenia] Custom Icons for Tools
Next Topic:Validation with EVL & RCP
Goto Forum:
  


Current Time: Sat Oct 25 01:27:05 GMT 2014

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

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