Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Workflow
Workflow [message #662375] Wed, 30 March 2011 12:50 Go to next message
Muhammad  is currently offline Muhammad
Messages: 13
Registered: March 2011
Junior Member
Hi,

MY MODEL IN XTEXT IS:
________________________________
grammar tutorialDSL.TDSL with org.eclipse.xtext.common.Terminals

generate tDSL "http://www.TDSL.tutorialDSL"
Tutorial:
"Title" title=STRING (pages+=Page)*;

Page:
Text | Question;

Text:
Heading | Contents;

Heading:
"Heading" heading=STRING;

Contents:
"Contents" contents=STRING;
************************************************************ **********
BASIC XPAND TEMPLATE IS:
_________________________________
«IMPORT tutorialDSL::tDSL»

«EXTENSION templates::Extensions»

«DEFINE main FOR Tutorial-»
«FILE "output.txt"-»

«ENDFILE-»
«ENDDEFINE»
************************************************************ ***
THE WORKFLOW IS;
_______________________________________________

module workflow.TDSLGenerator

import org.eclipse.emf.mwe.utils.*

var targetDir = "src-gen"
var fileEncoding = "Cp1252"
var modelPath = "src/model"

Workflow {

component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true

// or define search scope explicitly
path = modelPath

// this class will be generated by the xtext generator
register = tutorialDSL.TDSLStandaloneSetup {}
load = {
slot = "tutorial"
type = "Tutorial"
}
}

component = org.eclipse.xpand2.Generator {
expand = "templates::Template::main FOREACH tutorial"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}
************************************************************ ***
The workflow warning is:
Could not find any exported element of type 'Tutorial' -> Slot 'tutorial' is empty.

How should I change my workflow so that I get can have access to all elements of my model including Tutorial?

Thanks
Re: Workflow [message #662403 is a reply to message #662375] Wed, 30 March 2011 14:47 Go to previous messageGo to next message
Maxim Frolov is currently offline Maxim Frolov
Messages: 20
Registered: March 2010
Location: Aachen
Junior Member
Adding 'name' property to Tutorial should fix the warning:

Tutorial:
"Title" name=ID title=STRING (pages+=Page)*;

I think this is because by searching for elements Xtext assumes per default that model elements have 'name' attribute.

/max
Re: Workflow [message #662426 is a reply to message #662403] Wed, 30 March 2011 15:44 Go to previous messageGo to next message
Muhammad  is currently offline Muhammad
Messages: 13
Registered: March 2011
Junior Member
Thanks, it works.
Thanks again, made life easy Smile
Re: Workflow [message #662493 is a reply to message #662375] Wed, 30 March 2011 20:13 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

It is only relevant that a name can be computed for the object. By default it is the 'name' attribute. If an object does not have a name attribute one could add a custom IQualifiedNameProvider and bind it to the runtime module. I often do this for the "Model" type and return the resource name as name.

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;

public class MyDslQualifiedNameProvider extends
		DefaultDeclarativeQualifiedNameProvider {

	String qualifiedName (final Model m) {
		return m.eResource().getURI().lastSegment();
	}
}


Registration in the runtime module:
public class MyDslRuntimeModule extends com.swissre.cs96.parsgen.sridl.AbstractMyDslRuntimeModule {
	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyDslQualifiedNameProvider.class;
	}

}


Then the "Model" objects get exported and they can be used as input for the generator in the workflow.

~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Previous Topic:[Acceleo3] properties file
Next Topic:[Xpand/Xtend] Deleting elements from one List affects the elements on another List
Goto Forum:
  


Current Time: Wed Sep 17 09:40:33 GMT 2014

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

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