Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Iterate over elements from imported models
[XPAND] Iterate over elements from imported models [message #508452] Mon, 18 January 2010 22:39 Go to next message
Christian Pelster is currently offline Christian PelsterFriend
Messages: 23
Registered: January 2010
Junior Member
Hi all,

after converting from OAW to MWE I'm stuck with the following problem:

My DSL allows to split the model over multiple files (via "Import : 'import' importURI=STRING;").
With OAW-XPAND the following construct:

«FOREACH allElements().typeSelect(Entity) AS entity»
.....
«ENDFOREACH»


would iterate over all "Entity" elements from all imported model files, which obviously doesn't work anymore since
allElements
disappeared. Whats the correct way to achieve this with MWE-XPAND?

Regards,

Christian
Re: [XPAND] Iterate over elements from imported models [message #508504 is a reply to message #508452] Tue, 19 January 2010 09:18 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
You'll have to create that extension yourself.

A java extensions, which is implmented like this should work:

public static List<EObject> allElements(EObject ctx) {
ResourceSet rs = ctx.eResource().getResourceSet();
EcoreUtil.resolveAll(rs);
TreeIterator<Object> = EcoreUtil.eAllContents(rs);
// convert the treeiterator to a list
// Note, that you'll have to filter out the Resources
return convertedList;
}

Note that since Xtext 0.8.0M4a we have a new workflow component which
allows to select all elements in the resource set by type and /or name.

Sven

Christian Pelster schrieb:
> Hi all,
>
> after converting from OAW to MWE I'm stuck with the following problem:
>
> My DSL allows to split the model over multiple files (via "Import :
> 'import' importURI=STRING;").
> With OAW-XPAND the following construct:
>
>
> «FOREACH allElements().typeSelect(Entity) AS entity»
> .....
> «ENDFOREACH»
>
>
> would iterate over all "Entity" elements from all imported model files,
> which obviously doesn't work anymore since allElements disappeared.
> Whats the correct way to achieve this with MWE-XPAND?
>
> Regards,
>
> Christian
>


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [XPAND] Iterate over elements from imported models [message #518933 is a reply to message #508452] Fri, 05 March 2010 13:53 Go to previous messageGo to next message
Urtzi Odriozola is currently offline Urtzi OdriozolaFriend
Messages: 27
Registered: March 2010
Junior Member
Hi Sven!

There is no other way to iterate those elements? I mean, more easiest way (intuitive way) without using extensions?

Because I tried with extensions but I've got some cast errors and etc. And I prefer the using of some other mechanism instead.

I'm really interested in this feature and I need a help to implement it.

Thank you.
Re: [XPAND] Iterate over elements from imported models [message #518999 is a reply to message #518933] Fri, 05 March 2010 11:28 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
As I said, with Xtext 0.7.x the described way is the way to go.
With the upcoming Helios release we'll provide a simpler way.

Maybe you want to share some information about the problems you face?

Sven

Urtzi Odriozola schrieb:
> Hi Sven!
>
> There is no other way to iterate those elements? I mean, more easiest
> way (intuitive way) without using extensions?
>
> Because I tried with extensions but I've got some cast errors and etc.
> And I prefer the using of some other mechanism instead.
>
> I'm really interested in this feature and I need a help to implement it.
>
> Thank you.


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [XPAND] Iterate over elements from imported models [message #519912 is a reply to message #508452] Wed, 10 March 2010 13:41 Go to previous messageGo to next message
Urtzi Odriozola is currently offline Urtzi OdriozolaFriend
Messages: 27
Registered: March 2010
Junior Member
Yes, of course. I wanted to be sure before start asking help.

The problem is that I don't know how to cast my DSL type IncludeOperation to an EObject emf type.

This is the template where I'm trying to call the extension:
«DEFINE TestCaseType FOR IncludeOperation-»
	«FOREACH getOperations((emf::EObject)this) AS op»
		«EXPAND action::Action FOREACH op.actions-»
	«ENDFOREACH»
«ENDDEFINE»


So, I've got a extension file containing this code below:
import myDsl;

List[emf::EObject] getOperations(emf::EObject param) : JAVA
  extensions.Includer.allElements(org.eclipse.emf.ecore.EObject)
;


And a java class:
package extensions;

import java.util.List;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;

public class Includer {
	public static List<EObject> allElements(EObject ctx) {
			
			List<EObject> convertedList = null;
			EObject obj;
			
			ResourceSet rs = ctx.eResource().getResourceSet();
			EcoreUtil.resolveAll(rs);
			TreeIterator<EObject> iterator = EcoreUtil.getAllContents(rs, false);
			// convert the treeiterator to a list
			while(iterator.hasNext()){
				obj = iterator.next();
				// Note, that you'll have to filter out the Resources
			}
			return convertedList;
			}
}


Thank you for your help.
Re: [XPAND] Iterate over elements from imported models [message #521061 is a reply to message #508452] Tue, 16 March 2010 11:15 Go to previous messageGo to next message
Urtzi Odriozola is currently offline Urtzi OdriozolaFriend
Messages: 27
Registered: March 2010
Junior Member
Maybe, I've don't explained too enough the context of my problem... sorry for being so expressionless. Embarrassed Embarrassed

Ok, so I will start for the beginning. My problem is that, I've got a DSL languaje where it would be possible to "include" parts of the same languaje that are stored in other files. I mean, I wanna include files of the same metamodel into a main file, to get some file hierarchy and organize and understand better the work.

For example, this would be a test case with some operations. And I wanna include some other operations just because they are too large and It's more comfortable to work in another file.

MyDsl file:
<testCase name=ImportProject_TestCase>
        <include operation="operations/operation.scatedsl"/>
	<operation name=FillWizard>
                   // Here there are more elements
        </operation>
        <include operation="operations/operation3.scatedsl"/>
</testCase>


So now, I want to Xpand those included files in the concrete order I've put in my model.

Any ideas of how can I Xpand a concrete file respecting the order of the Operations? Sad

Thank you for all!! Very Happy Very Happy

P.S: The include statement's parameter It's an importURI type. Sorry for my English... Embarrassed
Re: [XPAND] Iterate over elements from imported models [message #523247 is a reply to message #508452] Thu, 25 March 2010 16:11 Go to previous message
Urtzi Odriozola is currently offline Urtzi OdriozolaFriend
Messages: 27
Registered: March 2010
Junior Member
Solved!!!

Thank you Sven for help me! But finally I followed this thread http://dev.eclipse.org/newslists/news.eclipse.modeling.m2t/m sg01632.html and I found a solution.
Previous Topic:Additional Xpath Functions
Next Topic:[Acceleo] Calling Java methods
Goto Forum:
  


Current Time: Tue Sep 24 16:50:06 GMT 2024

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

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

Back to the top