Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Registering/creating your own fragments to be used in the workflow
Registering/creating your own fragments to be used in the workflow [message #1002956] Sat, 19 January 2013 23:52 Go to next message
Joost van Pinxten is currently offline Joost van Pinxten
Messages: 50
Registered: November 2012
Member
I'd like a pointer to how I can create my own fragment in Xtext 2, to be added to the MWE2 workflow file. For example, I'd like to add another type of scope provider, that uses the importURI for defining the global scope, but is namespace-aware in the local scope. (The latter enables the grammar to use shorthand FQN instead of full FQN)

public class MyDslScopingFragment extends AbstractScopingFragment {

	@Override
	protected Class<? extends IScopeProvider> getLocalScopeProvider() {
		return ImportedNamespaceAwareLocalScopeProvider.class;
	}

	@Override
	protected Class<? extends IGlobalScopeProvider> getGlobalScopeProvider() {
		return ImportUriGlobalScopeProvider.class;
	}

}


However, I get the exception that addToStandaloneSetup(String,Boolean) for org::eclipse::xtext::impl::GrammarImpl could not be found! Like in http://www.eclipse.org/forums/index.php/mv/msg/199696/637268/ I tried to add this template, but had to change it a bit, as some of the references were incorrect. Unfortunately, this led only to more errors in the .xpt file. I even got the same warning as in the previously stated topic, so I know that the files are recognized and executed, but the encoding is set to UTF-8, and sometimes does and sometimes doesn't give problems, very weird.

«IMPORT org::eclipse::xtext»

«DEFINE addToPluginXmlRt(String scopeProviderSuperClassName, Boolean generateStub) FOR xtext::Grammar»«ENDDEFINE»

«DEFINE addToPluginXmlUi(String scopeProviderSuperClassName, Boolean generateStub) FOR xtext::Grammar»«ENDDEFINE»

«DEFINE addToStandaloneSetup(String scopeProviderSuperClassName, Boolean generateStub) FOR xtext::Grammar»«ENDDEFINE»

«DEFINE generate(String scopeProviderSuperClassName, Boolean generateStub) FOR xtext::Grammar»
«IF generateStub»
«EXPAND AbstractScopingFragment::JavaScopeProvider(scopeProviderSuperClassName)»
«ENDIF»
«ENDDEFINE»


I also changed the last EXPAND statement to the explicit package of the abstractscopingfragment (for which I don't see a JavaScopeProvider method/reference):
«EXPAND org::eclipse::xtext::generator::scoping::AbstractScopingFragment::JavaScopeProvider(scopeProviderSuperClassName)»


My question now; where can I find how this should actually be done in the latest version of xtext?

Re: Registering/creating your own fragments to be used in the workflow [message #1003100 is a reply to message #1002956] Sun, 20 January 2013 08:30 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6301
Registered: July 2009
Senior Member
Hi,

please note: the code uses xpands javabeansmetamodel and not the emf metamodel. make sure you configure the xpand editor respectively in the projects properties.

~Christian
Re: Registering/creating your own fragments to be used in the workflow [message #1003105 is a reply to message #1003100] Sun, 20 January 2013 08:51 Go to previous messageGo to next message
Joost van Pinxten is currently offline Joost van Pinxten
Messages: 50
Registered: November 2012
Member
Christian, thanks for the quick response. And yes, indeed, that works, removed most of the errors from the xpt template, but I still had to use:

 «EXPAND org::eclipse::xtext::generator::scoping::AbstractScopingFragment::JavaScopeProvider(scopeProviderSuperClassName)»
 
instead of
 «EXPAND AbstractScopingFragment::JavaScopeProvider(scopeProviderSuperClassName)» 
, which will throw the exception:
No Definition 'AbstractScopingFragment::JavaScopeProvider(String) for org::eclipse::xtext::impl::GrammarImpl' found!


Although for me it seemed to be quite impossible to (quickly) find the solution; it seems like such silly details when you know which settings, files and workflow to use... Did I miss the documentation related to this subject? Or should this behavior become apparent from the source code?
Re: Registering/creating your own fragments to be used in the workflow [message #1224978 is a reply to message #1002956] Sat, 28 December 2013 10:03 Go to previous message
Joost van Pinxten is currently offline Joost van Pinxten
Messages: 50
Registered: November 2012
Member
I'm currently (Xtext 2.4.3) using the following template (and same ScopeProvider) which (finally) lets the generator workflow complete.

So to repeat;
- create your own ScopeProvider class (so that your Xtext editor knows what to inject into your validator etc)
- create a template with the same name, but .xpt as file extension and copy the following code in;

«IMPORT org::eclipse::xtext»

«DEFINE addToPluginXmlRt(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»«ENDDEFINE»

«DEFINE addToPluginXmlUi(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»«ENDDEFINE»

«DEFINE addToStandaloneSetup(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»«ENDDEFINE»

«DEFINE generate(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»
	«EXPAND org::eclipse::xtext::generator::scoping::AbstractScopingFragment::generateScopeProvider(scopeProviderSuperClassName, generateStub, generateXtendStub)»
«ENDDEFINE»


And then it should be possible to run the DSLgenerator workflow again.

* Disclaimer; I've just taken this from the original source (and adjusted for different package) (org.eclipse.xtext.generator.scoping.ImportURIScopingFragment from the org.eclipse.xtext.generator.source_2.4.3.v201309030823 plugin jar or org.eclipse.xtext.generator_2.4.3.v201309030823 plugin jar)
Previous Topic:Problem Referring to Existing EPackage
Next Topic:Ensure type safety for Xtext grammar
Goto Forum:
  


Current Time: Wed Sep 17 19:44:50 GMT 2014

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

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