Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Include/Import other models in an Xtext DSL for an existing ecore model
Include/Import other models in an Xtext DSL for an existing ecore model [message #696111] Wed, 13 July 2011 09:43 Go to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Hi

I'm unsure how to define references to other definitions in my ecore metamodel.

I currently have an ecore metamodel called Structure which can contain Attributes. An attribute can have a type which references an IntrinsicType instance. IntrinsicType is defined in the ecore metamodel Types (Defined as children of a top level TypeContainer). Also an Attribute can point to a different Structure.

I've created an Xtext DSL for the Types ecore meta model and one for the Structure meta model.

When it comes to creating instances using these DSL's I would like to be able to reference Types, defined in an instance of the Types DSL, and be able to reference Structures defined in other instances of the Structure DSL from with in a given Structure DSL instance (in general there will be one Types DSL instance and a Structure DSL instance for every structure in the system).

The Structure DSL that works with Attributes looks like the following:
grammar dk.example.structure.dsl.StructureDsl with org.eclipse.xtext.common.Terminals 

import "platform:/resource/dk.example.metamodels/model/Structure.ecore" 
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "platform:/resource/dk.example.metamodels/model/Types.ecore" as types

Attribute returns Attribute:
	{Attribute}
	'Attribute'
	name=EString
	'{'
		('foreignKeyReference' foreignKeyReference=[Structure])?
		('type' type=[types::IntrinsicType])?
    '}';   


For DSLs that generate their own meta model I've seen examples of using import using QualifiedName and Include using URI, but I have no idea on how to model this into my Structure metamodel and connect this properly in the xtext DSL defined above...

Any tips? Smile

/Jeppe

[Updated on: Wed, 13 July 2011 09:46]

Report message to a moderator

Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696161 is a reply to message #696111] Wed, 13 July 2011 11:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

can you actually explain what your problem is? do you want to know how to get the cross refererence into the ecore file?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696169 is a reply to message #696161] Wed, 13 July 2011 12:19 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Hi Christian

I thought I did, but let me try and rephrase it a bit Smile

I have an xtext dsl that I can use to define Structures.
Since structures can reference other Structures or Intrinsic types (through Attributes living inside a Structure), I would like some way in my Structure DSL to specify an import/include of other structures and intrinsic types (which will be in separate files) so I can reference them.

Since my Structure DSL directly works on my Structure ecore model, then as far as I understand it, need to add something (which I don't know what should be) to my ecore model, which would allow the Xtext DSL work with the import/include ?

Did this make more sense?

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696173 is a reply to message #696169] Wed, 13 July 2011 12:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

no since inter file references work out of the box (just by name of the element - no matter which file it is within)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696188 is a reply to message #696173] Wed, 13 July 2011 12:52 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Cross reference doesn't work for me with the current setup.
In my runtime Eclipse workspace I have 3 files: 2 .structure files and one .types file and neither Type nor Structure cross reference works.

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696210 is a reply to message #696188] Wed, 13 July 2011 14:04 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

do you use the qualified name fragment, you try to reference a structure via an ID (e.g. StructureName), but possibly its name is a qualified name (e.g. StructureContaier.StructureName). If you use the Open-Model-Element-Dialog (shift ctrl F3), restricting the search to the EClass Structure, you should see which elements of that type are in the index.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696232 is a reply to message #696210] Wed, 13 July 2011 14:39 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
None of them show up if I try the Open-Model-Element-Dialog. That's weird Confused

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696306 is a reply to message #696232] Wed, 13 July 2011 16:43 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You cannot reference something across file boundaries that is not in the
index. So your indexing does not work.

Consider debugging your IQualifiedNameProvider. I suspect your model
elements don't hava an attribute 'name' which the default implementation
depends on. No qualified name -> no index entry.

Second source of problems could be your IResourceDescription.Manager.
Tis component actually composes the index entries (using the
IQualifiedNameProvider). Debugging this one could also give you a clue.

Am 13.07.11 16:39, schrieb Jeppe Cramon:
> None of them show up if I try the Open-Model-Element-Dialog. That's
> weird :?
>
> /Jeppe


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696552 is a reply to message #696306] Thu, 14 July 2011 09:29 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Hi Jan

All, but one EClass (the TypeContainer which houses all IntrinsicTypes), have an inherited name attribute.

If I look at the code setup (standard setup), it uses the default IResourceDescription.Manager and default IQualifiedNameProvider. Debugging them didn't really make me much clever :-/

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696557 is a reply to message #696552] Thu, 14 July 2011 09:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

the question is not only if the have this attribute, but that you fill it too.
since you find nothing in the index it may not be filled at all.

and the default qualifiednameprovider might give them a name parentname.name
in this case you'd have to write: type=[types::IntrinsicType|FQN])?
with FQN: ID ('.' ID)*;
or customize the name calculation.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 14 July 2011 09:42]

Report message to a moderator

Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696572 is a reply to message #696557] Thu, 14 July 2011 10:21 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
All instances defined through the DSL have their name set as the first thing, so it's a bit weird that they don't show up in the Open-Model-Element-Dialog.

I tried to define an ecore model, which gathers everything into one ecore model, and created a single DSL to define the model instances, and the instances defined here all show up in the Open-Model-Element-Dialog.

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696575 is a reply to message #696572] Thu, 14 July 2011 10:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
And debugging IQualifiedNameProvider gets nothing? it's never called?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696582 is a reply to message #696575] Thu, 14 July 2011 10:37 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
SimpleNameProvider gets called and returns the correct name.
DefaultResourceDescriptionManager also gets called and returns descriptors.

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696588 is a reply to message #696582] Thu, 14 July 2011 10:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
And the elements are still not in index? did you try to set up a clean project? did you check if plugin.xml and plugin.xml_gen in the ui project contain the save stuff - if not merge stuff from .xmlgen to .xml

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696595 is a reply to message #696588] Thu, 14 July 2011 11:08 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
They were equal for both DSL UI projects...
I didn't try with a clean project, but will try that.
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696604 is a reply to message #696595] Thu, 14 July 2011 11:39 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Tried with a clean project form scratch - same problem.
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696609 is a reply to message #696604] Thu, 14 July 2011 11:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Can you share a reproducable example?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696610 is a reply to message #696609] Thu, 14 July 2011 11:58 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Sure, should I attach it here or send it directly to you?
/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696615 is a reply to message #696610] Thu, 14 July 2011 12:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
attaching here is ok

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696630 is a reply to message #696615] Thu, 14 July 2011 12:43 Go to previous messageGo to next message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
Zip file becomes 3.4 MB - can I use another way of sending it?

/Jeppe
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696669 is a reply to message #696630] Thu, 14 July 2011 14:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

3,4 if export your project via rightclick from workspace?
you can write a mail to my firstname, a dot and my lastname.
I work for the company that creates Xtext in Germany.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Include/Import other models in an Xtext DSL for an existing ecore model [message #696937 is a reply to message #696669] Fri, 15 July 2011 07:15 Go to previous message
Jeppe Cramon is currently offline Jeppe CramonFriend
Messages: 37
Registered: July 2009
Member
For those wondering what the solution was here it comes. The create Xtext from from existing ecore model sets the Import scoping fragment to
fragment = scoping.ImportURIScopingFragment {}


but it should have been
fragment = scoping.ImportNamespacesScopingFragment {}

to work with this example.

Thanks to Christian for the solution Smile

/Jeppe
Previous Topic:Does Xtext have limitation on the size of the grammar?
Next Topic:Typo in reference documentation
Goto Forum:
  


Current Time: Tue Apr 16 11:13:32 GMT 2024

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

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

Back to the top