Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » UML2C where to start
UML2C where to start [message #1695346] Wed, 13 May 2015 15:59 Go to next message
Jonathan Marino is currently offline Jonathan MarinoFriend
Messages: 1
Registered: May 2015
Junior Member
Hello, I want to make an UML2C code generator, I don´t know: first: to use xpand or acceleo. Second: where to start, examples, previous works, etc.
can any one help me?
Re: UML2C where to start [message #1695356 is a reply to message #1695346] Wed, 13 May 2015 17:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
Hi,

the first question i cannot answer, it is a matter of taste, features, maintenance etc

to the second question: here is a simple example template and workflow attached

src/workflow/workflow.mwe
<workflow>
	
	<bean class="org.eclipse.xtend.typesystem.uml2.Setup" />
	
	<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri=".." />
	
	<component class="org.eclipse.emf.mwe.utils.Reader">
		<uri value="platform:/resource/xpand.uml.sample/src/model/test.uml" />
		<modelSlot value="model" />
	</component>
	
	<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner">
		<directory value="src-gen" />
	</component>
	
	
	<component class="org.eclipse.xpand2.Generator">
		<metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel" />
		<expand value="template::Template::main FOR model" />
		<outlet path="src-gen" >
			<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>
	

</workflow>


src/template/Template.xpt
«EXTENSION template::GeneratorExtensions»

«DEFINE main FOR uml::Model»
	«EXPAND main FOREACH ownedElement»
«ENDDEFINE»

«DEFINE main FOR uml::Package»
	«EXPAND main FOREACH ownedElement»
«ENDDEFINE»

«DEFINE main FOR uml::Class»
«FILE getFQPN().replaceAll("\\.","/")+"/"+name+".java"»
package «getFQPN()»;
public class «name» {

}
«ENDFILE»
«ENDDEFINE»

«DEFINE main FOR uml::Element»
«ENDDEFINE»

src/template/GeneratorExtensions.ext
String getFQPN(uml::Class c) : c.package.getFQN();
String getFQN(uml::Package p) : p.nestingPackage.getFQN() == "" ? p.name : (p.nestingPackage.getFQN() + "." + p.name);
String getFQN(uml::Model m) : "";	


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: UML2C where to start [message #1695358 is a reply to message #1695356] Wed, 13 May 2015 17:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
P.S. if you want to use a uml profile types you need a slightly different setup

<workflow>
	
	<bean class="org.eclipse.xtend.typesystem.uml2.Setup" />
	
	<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri=".." />
	
	<component class="org.eclipse.emf.mwe.utils.Reader">
		<uri value="platform:/resource/xpand.uml.profile.sample/src/model/test.uml" />
		<modelSlot value="model" />
	</component>
	
	<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner">
		<directory value="src-gen" />
	</component>
	
	
	<component class="org.eclipse.xpand2.Generator">
		<metaModel class="org.eclipse.xtend.typesystem.uml2.profile.ProfileMetaModel">
			<profile value="platform:/resource/xpand.uml.profile.sample/src/model/test.profile.uml" />
		</metaModel>
		<metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel" />
		<expand value="template::Template::main FOR model" />
		<outlet path="src-gen" >
			<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>
	

</workflow>


«DEFINE main FOR test::Bean»
«FILE getFQPN().replaceAll("\\.","/")+"/"+name+".java"»
package «getFQPN()»;
public class «name» {

}
«ENDFILE»
«ENDDEFINE»


(test.Bean is a Stereotype in the Profile)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: UML2C where to start [message #1695362 is a reply to message #1695358] Wed, 13 May 2015 17:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
p.S: depending on your usecase you may have a look at eclipse xtend as well

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:xpand to xtend2 type system migration
Next Topic:Generation process M2T
Goto Forum:
  


Current Time: Thu Oct 18 15:26:52 GMT 2018

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

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

Back to the top