Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem when generating Xtext problem from different EMF models
Problem when generating Xtext problem from different EMF models [message #1032904] Wed, 03 April 2013 11:44 Go to next message
Luca Gherardi is currently offline Luca Gherardi
Messages: 60
Registered: November 2010
Member
I have three ecore metamodels:

Meta Model A

There is a class Model which contains a collection of elements (containments = true, cardinality 1...*)
Element is defines a a reference to an object of type Category which is defined in the meta model C (containment = false, cardinality 1...1).
It also contains a collection of Attribute (containments = true, cardinality 0...*)

Meta Model B
This metamodel defines two classes that extend Attribute: SimpleAttribute and ComplexAttribute

Meta Model C
Defies the class Category

Now I would like to generate a DSL for the MetaModel A.
This should replace the tree editor provided by EMF.

I tried to cretae a new "Xtext project from EMF". This is the result:

// automatically generated by Xtext
grammar MyDSL with org.eclipse.xtext.common.Terminals

import "http://metamodelA" as mA
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://metamodelB" as mB
import "http://metamodelC" as mC

Model returns mA::Model:
	'Model'
	name=EString
	'{'
		'elements' '{' elements+=Element ( "," elements+=Element)* '}' 
	'}';


EString returns ecore::EString:
	STRING | ID;

Element returns ma::Element:
	'Element'
	name=EString
	'{'
		'category' category=[mc::Category|EString]
		('attributes' '{' attributes+=Attribute ( "," attributes+=Attribute)* '}' )?
	'}';

Category returns mC::Category:
	...
;


This code gives me two errors:
1) Cannot find compatible category category in sealed EClass Element from imported package http://metamodelA: The existing reference 'category' has an incompatible type 'Category'. The expected type is 'Category'.
2) Attribute cannot be resolved to a rule

For the second problem I tried to define

Attribute returns mA::Attribute :
	SimpleAttribute | ComplexAttribute 
	
;

SimpleAttribute returns mb::SimpleAttribute: 
	....
;

ComplexAttribute returns mb::ComplexAttribute: 
	....
;



However the first rules returns the error : "Cannot add supertype 'Attribute' to sealed type 'SimpleAttribute'".
But actually SimpleAttribute is already a sub-class of Attribute.

How can I fix these problems?
Re: Problem when generating Xtext problem from different EMF models [message #1033051 is a reply to message #1032904] Wed, 03 April 2013 16:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6213
Registered: July 2009
Senior Member
Hi,

can you share something reproducable? did you obey: EPackages have to refer to each other by means of platform-resource or platform-plugin URIs.
Re: Problem when generating Xtext problem from different EMF models [message #1033085 is a reply to message #1032904] Wed, 03 April 2013 16:59 Go to previous messageGo to next message
Annika Wießgügel is currently offline Annika Wießgügel
Messages: 11
Registered: January 2013
Junior Member
Hi Luca,

i'm not an expert, but from my own experience i can tell you where your first exception comes from (or where i suppose it comes from ^^) :

"1) Cannot find compatible category category in sealed EClass Element from imported package http://metamodelA: The existing reference 'category' has an incompatible type 'Category'. The expected type is 'Category'."

Normally you find this exception, when your Model (Model A in this case) doesn't have an attribute " category" in "Element". You have to either rename category in the Element-Rule to something that fits the model, or add an attribute into you model A.

I can't solve you second problem. I know exactly that i also had to fight it but don't know how i solved it.
Hope my answer wasn't wrong,

greetings from germany,

Annika

[Updated on: Wed, 03 April 2013 16:59]

Report message to a moderator

Re: Problem when generating Xtext problem from different EMF models [message #1033520 is a reply to message #1033051] Thu, 04 April 2013 06:08 Go to previous message
Luca Gherardi is currently offline Luca Gherardi
Messages: 60
Registered: November 2010
Member
Thanks for your hint.

I used the URI import "http://..." which was automatically generated by EMF projects.

I replaced it with the plugin-URI and now it works.

Thanks again!
Luca
Previous Topic:Xtext: Trying to check for cross references but get ambiguous grammar
Next Topic:[Xbase 2.4] TypeComputer is not invoked
Goto Forum:
  


Current Time: Sat Aug 23 03:50:35 EDT 2014

Powered by FUDForum. Page generated in 0.07335 seconds