Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Model without a root object
Model without a root object [message #951004] Sat, 20 October 2012 10:00 Go to next message
Lester William Polsfuss is currently offline Lester William Polsfuss
Messages: 3
Registered: October 2012
Junior Member
Hi,

I'm working on a M2T project that generates code from a java model. This model defines a number of class objects that have instance variables, methods etc.
When the workflow is executed, it will only generate the code for the first class defined in the model and not for all classes.

I suspect that this is caused by the fact that my java model has no 'root' object. Most tutorials on the matter assume a root object like 'Model'.

Is it possible to make a 'main' definition such that all instances of that type are considered without having a root object in the model?

This is how the current main definition looks like:

«DEFINE main FOR Class»
«FILE name.toString() + ".java"»
public class «name» {

	«EXPAND field FOREACH field»
        ...
}
«ENDFILE»
«ENDDEFINE»




Re: Model without a root object [message #951391 is a reply to message #951004] Sat, 20 October 2012 17:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6327
Registered: July 2009
Senior Member
Hi,

it always depends on how you call the template. so can you give us a bit more context.

~Christian
Re: Model without a root object [message #951400 is a reply to message #951391] Sat, 20 October 2012 18:03 Go to previous messageGo to next message
Lester William Polsfuss is currently offline Lester William Polsfuss
Messages: 3
Registered: October 2012
Junior Member
Hi Christian,

The template is called from a workflow files which was generated by eclipse / XPand new project wizard.

This are the content of generator.mwe
<?xml version="1.0"?>
<workflow>
	<property name="model" value="javaprogram.project/src/JavaProgram.xmi" />
	<property name="src-gen" value="src-gen" />
	
	<!-- set up EMF for standalone execution -->
	<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
		<platformUri value=".."/>
	</bean>
	
	<!-- instantiate metamodel -->
	<bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>

	<!-- load model and store it in slot 'model' -->
	<component class="org.eclipse.emf.mwe.utils.Reader">
		<uri value="platform:/resource/${model}" />
		<modelSlot value="model" />
	</component>

	<!-- check model -->
	<component class="org.eclipse.xtend.check.CheckComponent">
		<metaModel idRef="mm_emf"/>
		<checkFile value="metamodel::Checks" />
		<emfAllChildrenSlot value="model" />
	</component>

	<!--  generate code -->
	<component class="org.eclipse.xpand2.Generator">
		<metaModel idRef="mm_emf"/>
		<expand
			value="template::javaprogram::main FOR model" />
		<outlet path="${src-gen}" >
			<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>
</workflow>

Re: Model without a root object [message #951418 is a reply to message #951400] Sat, 20 October 2012 18:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6327
Registered: July 2009
Senior Member
Hi,

you may try

<expand
			value="template::javaprogram::main FOREACH model" />


instead
Re: Model without a root object [message #952183 is a reply to message #951418] Sun, 21 October 2012 08:17 Go to previous messageGo to next message
Lester William Polsfuss is currently offline Lester William Polsfuss
Messages: 3
Registered: October 2012
Junior Member
Unfortunately, this doesn't work. I get the following error when running the code generation:

Quote:

[ERROR]: Collection expected!(Element: EXPAND template::javaprogram::main FOREACH model; Reported by: Generator: generating 'template::javaprogram::main FOREACH model' => src-ge


I think FOREACH can only be used on a collection. Is there a way to obtain all child nodes from the model?
Re: Model without a root object [message #952241 is a reply to message #952183] Sun, 21 October 2012 09:26 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6327
Registered: July 2009
Senior Member
This error message makes finally clear: you HAVE a root object.
you still can use EMF means to get children e.g. eContents/eAllContents.
it would help if you could share some information on your metamodel
to give you some better advice on what to do.

~Christian
Previous Topic:Problems running org.eclipse.acceleo:maven:3.2.1 in maven
Next Topic:(Xpand) How to access ecore.ecore via Xpand code
Goto Forum:
  


Current Time: Wed Oct 01 12:27:49 GMT 2014

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

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