Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext ecore cross references
Xtext ecore cross references [message #940424] Thu, 11 October 2012 12:16 Go to next message
Edwin Park is currently offline Edwin Park
Messages: 124
Registered: July 2009
Senior Member
Hi,

I have a problem using Xtext generated ecore files in both Eclipse and standalone Java. In a nutshell, Xtext generates relative ecore references which work fine in Eclipse for platform:/resource URIs which make it seem like all projects are siblings of each other, but break when loading resources via absolute file:/ URIs when projects are not physically situated in the same directory.

For example, I have a few Xtext languages that import each other and refer to each other's elements. Xtext generates ecore files for these languages, and they wind up having relative references to each other. I have a com.mecha1.atom.model.query Xtext project whose language generates an AtomQuery.ecore with references to an imported AtomType.ecore that look like this:

Quote:

eType="ecore:EClass ../../../../../../../com.mecha1.atom.model.type/src/com/mecha1/atom/model/type/AtomType.ecore#//EntityDecl"


This works ok in Eclipse because the actual absolute URIs are platform:/resource based and all of the workspace projects are directly referenced via platform:/resource/<project>:

Quote:

platform:/resource/com.mecha1.atom.model.query/src-gen/com/mecha1/atom/model/query/AtomQuery.ecore
platform:/resource/com.mecha1.atom.model.type/src/com/mecha1/atom/model/type/AtomType.ecore


However on the filesystem these projects exist in different subdirectories:

Quote:

file:/Users/esp/Code/mecha1/Atom/atom/data/com.mecha1.atom.model.query/bin/com/mecha1/atom/model/query/AtomQuery.ecore
file:/Users/esp/Code/mecha1/Atom/atom/core/com.mecha1.atom.model.type/bin/com/mecha1/atom/model/type/AtomType.ecore


So when the relative path is used to navigate from one ecore model to the other they do not resolve correctly. The relative URIs will also break if resources are loaded from archive:/ URIs e.g. when loaded from classpath bundles via org.eclipse.xtext.mwe.Reader.

Is there a strategy deal with this? For instance, is there a way to force Xtext to generate absolute URIs for cross references? Then at least I could use the EMF URI map to remap things depending on what context the models are being loaded in.

Thanks,
Edwin

[Updated on: Thu, 11 October 2012 12:16]

Report message to a moderator

Re: Xtext ecore cross references [message #940438 is a reply to message #940424] Thu, 11 October 2012 12:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25919
Registered: July 2009
Senior Member
Edwin,

When working stand alone, you can create "folder mappings" in the
resource set's URI converters' URI map. E.g., you'd map
"platform:/resource/<foo>/" to archive:file:/<location-of-foo.jar>/., or
"file:/<location-of-foo-folder>/". Note the trailing / on each; that's
what specifies that all URIs nested under that URI are to be remapped.
You'd need to do that for each project/jar. (I don't think it's a good
idea for Ecore models to be in the src folder because then you end up
with copies in the bin folder, and, after you deploy, there won't even
be a src or bin folder; it's a mess.) Of course using absolute URIs is
also a problem. No one can use such resources except the original person...



On 11/10/2012 6:16 PM, Edwin Park wrote:
> Hi,
>
> I have a problem using Xtext generated ecore files in both Eclipse and
> standalone Java. In a nutshell, Xtext generates relative ecore
> references which work fine in Eclipse for platform:/resource URIs
> which make it seem like all projects are siblings of each other, but
> break when loading resources via absolute file:/ URIs when projects
> are not physically situated in the same directory.
>
> For example, I have a few Xtext languages that import each other and
> refer to each other's elements. Xtext generates ecore files for these
> languages, and they wind up having relative references to each other.
> I have a com.mecha1.atom.model.query Xtext project whose language
> generates an AtomQuery.ecore with references to an imported
> AtomType.ecore that look like this:
>
> Quote:
>> eType="ecore:EClass
>> ../../../../../../../com.mecha1.atom.model.type/src/com/mecha1/atom/model/type/AtomType.ecore#//EntityDecl"
>
>
> This works ok in Eclipse because the actual absolute URIs are
> platform:/resource based and all of the workspace projects are
> directly referenced via platform:/resource/<project>:
>
> Quote:
>> platform:/resource/com.mecha1.atom.model.query/src-gen/com/mecha1/atom/model/query/AtomQuery.ecore
>>
>> platform:/resource/com.mecha1.atom.model.type/src/com/mecha1/atom/model/type/AtomType.ecore
>>
>
>
> However on the filesystem these projects exist in different
> subdirectories:
>
> Quote:
>> file:/Users/esp/Code/mecha1/Atom/atom/data/com.mecha1.atom.model.query/bin/com/mecha1/atom/model/query/AtomQuery.ecore
>>
>> file:/Users/esp/Code/mecha1/Atom/atom/core/com.mecha1.atom.model.type/bin/com/mecha1/atom/model/type/AtomType.ecore
>>
>
>
> So when the relative path is used to navigate from one ecore model to
> the other they do not resolve correctly. The relative URIs will also
> break if resources are loaded from archive:/ URIs e.g. when loaded
> from classpath bundles via org.eclipse.xtext.mwe.Reader.
>
> Is there a strategy deal with this? For instance, is there a way to
> force Xtext to generate absolute URIs for cross references? Then at
> least I could use the EMF URI map to remap things depending on what
> context the models are being loaded in.
>
> Thanks,
> Edwin
>
Re: Xtext ecore cross references [message #941048 is a reply to message #940438] Fri, 12 October 2012 03:09 Go to previous messageGo to next message
Edwin Park is currently offline Edwin Park
Messages: 124
Registered: July 2009
Senior Member
Hi Ed,

Thanks, this helped to put me on the right track.

I also moved my ecore/genmodel files into a non-source 'model' directory in my plugin according to your suggestion. This avoids the files being duplicated in the bin dir as you said, but when I take them out of the classpath like this, I can no longer reference them in the Xtext editor.

For example, I modified the default mydsl sample to include a reference to an EClass in the greeting:

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

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

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' eClass=[ecore::EClass|QualifiedName] '!';

QualifiedName:
	ID ('.' ID)*;


And I have a plugin com.mecha1.atom.mysql that looks like this:

com.mecha1.atom.mysql/model/mysqlConfig.ecore
com.mecha1.atom.mysql/model/MysqlConfig.genmodel

com.mecha1.atom.mysql/plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>

<!--
-->

<plugin>

   <extension point="org.eclipse.emf.ecore.generated_package">
      <package
            uri="http://www.mecha1.com/atom/mysql/MysqlConfig"
            class="com.mecha1.atom.mysql.mysqlConfig.MysqlConfigPackage"
            genModel="model/MysqlConfig.genmodel"/>
   </extension>

</plugin>


com.mecha1.atom.mysql/build.properties:
#

bin.includes = .,\
               META-INF/,\
               plugin.xml,\
               plugin.properties,\
               model/
jars.compile.order = .
source.. = src/,\
           src-gen/,\
           xtend-gen/
output.. = bin/


When I launch a hosted Eclipse and create a .mydsl file in a plug-in project with the com.mecha1.atom.mydsl plugin specified as a dependency, the content assist for the eClass attribute does not show anything. However if the ecore files are in the classpath of the dependency plugin, the content assist will show them.

Another thing I noticed is that if I include the org.eclipse.emf.ecore plugin, the Xtext content assist will correctly show the contents of the Ecore.ecore, which is also in a model directory in the plugin. Is there something else I need to do to get Xtext to recognize the ecore file for cross reference scoping/content assist if the ecore is not in the classpath?

Thanks,
Edwin

Re: Xtext ecore cross references [message #941142 is a reply to message #941048] Fri, 12 October 2012 04:36 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25919
Registered: July 2009
Senior Member
Edwin,

Comments below.

On 12/10/2012 9:09 AM, Edwin Park wrote:
> Hi Ed,
>
> Thanks, this helped to put me on the right track.
>
> I also moved my ecore/genmodel files into a non-source 'model'
> directory in my plugin according to your suggestion. This avoids the
> files being duplicated in the bin dir as you said, but when I take
> them out of the classpath like this, I can no longer reference them in
> the Xtext editor.
Yes, because it doesn't index them until they commit this patch I provided:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=390411
>
> For example, I modified the default mydsl sample to include a
> reference to an EClass in the greeting:
>
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> Model:
> greetings+=Greeting*;
>
> Greeting:
> 'Hello' eClass=[ecore::EClass|QualifiedName] '!';
>
> QualifiedName:
> ID ('.' ID)*;
>
>
> And I have a plugin com.mecha1.atom.mysql that looks like this:
>
> com.mecha1.atom.mysql/model/mysqlConfig.ecore
> com.mecha1.atom.mysql/model/MysqlConfig.genmodel
>
> com.mecha1.atom.mysql/plugin.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?eclipse version="3.0"?>
>
> <!--
> -->
>
> <plugin>
>
> <extension point="org.eclipse.emf.ecore.generated_package">
> <package
> uri="http://www.mecha1.com/atom/mysql/MysqlConfig"
> class="com.mecha1.atom.mysql.mysqlConfig.MysqlConfigPackage"
> genModel="model/MysqlConfig.genmodel"/>
> </extension>
>
> </plugin>
>
>
> com.mecha1.atom.mysql/build.properties:
>
> #
>
> bin.includes = .,\
> META-INF/,\
> plugin.xml,\
> plugin.properties,\
> model/
> jars.compile.order = .
> source.. = src/,\
> src-gen/,\
> xtend-gen/
> output.. = bin/
>
>
> When I launch a hosted Eclipse and create a .mydsl file in a plug-in
> project with the com.mecha1.atom.mydsl plugin specified as a
> dependency, the content assist for the eClass attribute does not show
> anything. However if the ecore files are in the classpath of the
> dependency plugin, the content assist will show them.
Yes, that's the bug I referred to.
>
> Another thing I noticed is that if I include the org.eclipse.emf.ecore
> plugin, the Xtext content assist will correctly show the contents of
> the Ecore.ecore, which is also in a model directory in the plugin.
But it's an actual deployed bundle so it's actually on the classpath but
the PDE doesn't properly put the model folder on the classpath, only the
bin folder.
> Is there something else I need to do to get Xtext to recognize the
> ecore file for cross reference scoping/content assist if the ecore is
> not in the classpath?
>
> Thanks,
> Edwin
>
>
Previous Topic:right place to add save actions?
Next Topic:Issues and error when migrating to Juno and changing to GIT
Goto Forum:
  


Current Time: Sat Jul 26 01:11:19 EDT 2014

Powered by FUDForum. Page generated in 0.04423 seconds