Skip to main content


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 15:44 Go to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
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 20:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
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.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem when generating Xtext problem from different EMF models [message #1033085 is a reply to message #1032904] Wed, 03 April 2013 20:59 Go to previous messageGo to next message
Annika Wießgügel is currently offline Annika WießgügelFriend
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 20: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 10:08 Go to previous message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
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: Fri Mar 29 09:47:59 GMT 2024

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

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

Back to the top