Skip to main content



      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 05:43 Go to next message
Eclipse UserFriend
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 05:46] by 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 07:57 Go to previous messageGo to next message
Eclipse UserFriend
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
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 08:19 Go to previous messageGo to next message
Eclipse UserFriend
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 08:24 Go to previous messageGo to next message
Eclipse UserFriend
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
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 08:52 Go to previous messageGo to next message
Eclipse UserFriend
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 10:04 Go to previous messageGo to next message
Eclipse UserFriend
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
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 10:39 Go to previous messageGo to next message
Eclipse UserFriend
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 12:43 Go to previous messageGo to next message
Eclipse UserFriend
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
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 05:29 Go to previous messageGo to next message
Eclipse UserFriend
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 05:41 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Thu, 14 July 2011 05:42] by 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 06:21 Go to previous messageGo to next message
Eclipse UserFriend
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 06:24 Go to previous messageGo to next message
Eclipse UserFriend
And debugging IQualifiedNameProvider gets nothing? it's never called?
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 06:37 Go to previous messageGo to next message
Eclipse UserFriend
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 06:49 Go to previous messageGo to next message
Eclipse UserFriend
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
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 07:08 Go to previous messageGo to next message
Eclipse UserFriend
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 07:39 Go to previous messageGo to next message
Eclipse UserFriend
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 07:43 Go to previous messageGo to next message
Eclipse UserFriend
Can you share a reproducable example?

~Christian
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 07:58 Go to previous messageGo to next message
Eclipse UserFriend
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 08:14 Go to previous messageGo to next message
Eclipse UserFriend
attaching here is ok
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 08:43 Go to previous messageGo to next message
Eclipse UserFriend
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 10:37 Go to previous messageGo to next message
Eclipse UserFriend
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
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 03:15 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 04:53:50 EDT 2025

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

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

Back to the top