Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Registering EMF EPackage for Xtext
Registering EMF EPackage for Xtext [message #1027409] Tue, 26 March 2013 23:50 Go to next message
Roza Ghamari is currently offline Roza GhamariFriend
Messages: 82
Registered: January 2013
Member
I am re-posting this message here.

Hi everyone,

This might be a repeated question but I really tried to do my best to find an answer before posting, didn't succeed as you can see.

I have created two EMF models using ecore, model2 referencing model1 and they both have a single genmodel. Now, I want to use these ecore models in my xtext grammar partially for the parts that are exactly matching with the grammar. I also generate another model as the AST for my DSL. As a result the generated AST has references to model1 and model2.

After much of search and reading, I found that it is recommended to use namesapceURI for referring to a model in xtext. I am doing so and the workflow runs correctly (after including genmodel and registering packages in standalone setup and setting the platform URI correctly). However, as you know xtext editor looks for registered packages to find the namespace URI, which in my case it fails to find. I find it very annoying and misleading to get errors in my editor and as a result package explorer, while everything is fine. My understanding is that I need to register my packages, but how I don't know. Do you have any link to tutorials on how to register the ecore models on your development instance of eclipse? Can you explain the steps here? I really couldn't find anything.

I know that it is possible to register the model in standalone setup of wrokflow, but hwat I want is registering model (i.e. processing the package registry extension pint of ecore model) for my editor.

This is something that took 3 days of me and my colleagues! I am sure if you answer this you'll help many others.

Thanks in advance!
Re: Registering EMF EPackage for Xtext [message #1027438 is a reply to message #1027409] Wed, 27 March 2013 00:51 Go to previous messageGo to next message
Roza Ghamari is currently offline Roza GhamariFriend
Messages: 82
Registered: January 2013
Member
Just found the solution for xtext. Adding xtext nature to the emf projects will do the registration, so the xtext grammar editor will not show errors for namspaceURI based imports.
Re: Registering EMF EPackage for Xtext [message #1081673 is a reply to message #1027409] Wed, 07 August 2013 14:34 Go to previous message
Heinrich Müller is currently offline Heinrich MüllerFriend
Messages: 10
Registered: March 2012
Junior Member
Just stumbled across this. It should be noted that this works if you do the following:

Workflow {
    bean = StandaloneSetup {
    	scanClassPath = true
    	platformUri = "${runtimeProject}/.."
    	// The following two lines can be removed, if Xbase is not used.
    	registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage"
    	registerGeneratedEPackage = "com.company.MyPackage"
    	registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
    	registerGenModelFile = "platform:/resource/com.company.model/model/my.genmodel"
    }


in the mwe2 workflow

and add both Xtext Builder and Nature to your model project's .project file like this:

<projectDescription>
	<name>com.company.model</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.pde.ManifestBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.pde.SchemaBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.pde.PluginNature</nature>
		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
	</natures>
</projectDescription>


You can then reference the ecore with its nsURI like this:

grammar org.xtext.example.mydsl.MyXDsl with org.eclipse.xtext.common.Terminals

import "http://company.com/mymodel/1.0" as other

generate myXDsl "http://www.xtext.org/example/mydsl/MyXDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!' str=[other::DEVString];
Previous Topic:calling XbaseCompiler 2.4 in the inferrer
Next Topic:Built in types for non Xbase based language
Goto Forum:
  


Current Time: Thu Apr 25 22:22:42 GMT 2024

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

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

Back to the top