Registering/creating your own fragments to be used in the workflow [message #1002956] |
Sat, 19 January 2013 23:52 |
Joost van Pinxten Messages: 51 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 #1224978 is a reply to message #1002956] |
Sat, 28 December 2013 10:03 |
Joost van Pinxten Messages: 51 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)
|
|
|
Powered by
FUDForum. Page generated in 0.03323 seconds