Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Importing a Metamodel in XText 2.12.
Importing a Metamodel in XText 2.12. [message #1774868] Fri, 20 October 2017 17:27 Go to next message
Ruchika Kumar is currently offline Ruchika KumarFriend
Messages: 50
Registered: January 2017
Member
Hello,

I tried by all means for the last two days to find a post that would allow me to solve my problem, but alas here I am.

The problem I'm trying to fix is simple enough: I'm trying to import an ecore metamodel in XText instead of generating it. Resources such as this and others seem to be deprecated for XText 2.12

Unfortunately, the proposed solution online seem to be deprecated. Therefore, I opted to follow the instructions in the XText documentation, namely the section for importing metamodels, by creating the default XText "MyDsl" project.

MyDsl.text:

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

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';


GenerateMyDsl.mwe2:

module org.xtext.example.mydsl.GenerateMyDsl

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

Workflow {
	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "org.xtext.example.mydsl"
				rootPath = rootPath
				runtimeTest = {
					enabled = true
				}
				eclipsePlugin = {
					enabled = true
				}
				eclipsePluginTest = {
					enabled = true
				}
				createEclipseMetaData = true
			}
			code = {
				encoding = "windows-1252"
				lineDelimiter = "\r\n"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "org.xtext.example.mydsl.MyDsl"
			fileExtensions = "mydsl"
			
			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
		}
	}	
}


As expected, after generating the XText artifacts, I get a MyDsl.ecore and MyDsl.genmodel written in "./model/generated".

I then proceeded to change the "generate" statement to an "import" in MyDsl.text:

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

import "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';


And registered my "MyDsl.genmodel", as explained in documentation through the workflow file GenerateMyDsl.mwe2:

module org.xtext.example.mydsl.GenerateMyDsl

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

Workflow {

	component = XtextGenerator {
		configuration = {
			project = StandardProjectConfig {
				baseName = "org.xtext.example.mydsl"
				rootPath = rootPath
				runtimeTest = {
					enabled = true
				}
				eclipsePlugin = {
					enabled = true
				}
				eclipsePluginTest = {
					enabled = true
				}
				createEclipseMetaData = true
			}
			code = {
				encoding = "windows-1252"
				lineDelimiter = "\r\n"
				fileHeader = "/*\n * generated by Xtext \${version}\n */"
			}
		}
		language = StandardLanguage {
			name = "org.xtext.example.mydsl.MyDsl"
			fileExtensions = "mydsl"
			
			//added this line
			referencedResource = "platform:/resource/org.xtext.example.mydsl/model/temp/MyDsl.genmodel"
			serializer = {
				generateStub = false
			}
			validator = {
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
			}
		}
	}	
}


The "./model/temp" folder is just a copy of "./model/generated". I then go on to successfully generate the XText artifacts once again, but some of the generated artifacts contain compilation errors, namely some manifest files complaining "org.xtext.example.mydsl.myDsl.impl,
org.xtext.example.mydsl.myDsl" do not exist in this plug-in.

My intuition tells me this problem has something do to with registering an ePackage for the meta model, but I'm not sure exactly how to go about that.

Is there a quick fix that can be made so that I can import an ecore metamodel file in XText?

In case it factors in the analysis, I'm currently using XText 2.12 and Eclipse Oxygen

Thanks in advance
Re: Importing a Metamodel in XText 2.12. [message #1774869 is a reply to message #1774868] Fri, 20 October 2017 17:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
if you have an imported metamodel nobody will generate the java code.

=> you cound add an additional org.eclipse.emf.mwe2.ecore.EcoreGenerator component to the workflow
e.g. as in https://www.eclipse.org/forums/index.php/t/1079948/

=> or you generate the code manually (open genmodel, rightklick, generate model code - you may need to generate to another folder than src-gen - is configured in the genmodel file as well)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Importing a Metamodel in XText 2.12. [message #1774878 is a reply to message #1774869] Fri, 20 October 2017 19:00 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

If you want to see a family of editors with imported/manual metamodels and no warnings have a look at the GIT\org.eclipse.ocl\plugins\org.eclipse.ocl.xtext.* projects.

If you want to see some workflows to build the Ecore models and editors see GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.build\src\org\eclipse\ocl\examples\build\GenerateCSModels.mwe2 and GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.build\src\org\eclipse\ocl\examples\build\GenerateAllEditors.mwe2

Regards

Ed Willink
Previous Topic:Xtext 2.13 is out
Next Topic:Only static inner classes?
Goto Forum:
  


Current Time: Sat Sep 22 01:38:57 GMT 2018

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

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

Back to the top