Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to resolve reference to ecore class?
How to resolve reference to ecore class? [message #1730672] Wed, 27 April 2016 14:36 Go to next message
Mark Drei is currently offline Mark DreiFriend
Messages: 13
Registered: April 2016
Junior Member
Hi,

I'm new to both xtext and EMF and now I got stuck. I hope someone here can give me some pointers.

I want to refer to an Ecore class from within my DSL. In the end I want to be able to Ctrl-Click / F3 on that reference inside the DSL in order to navigate to its definition.
Here's what I have so far:


  • An Ecore Model with a class "SomeClass" and a collection "Collection" of "SomeClass". I have a genmodel an generated all the plugins. SomeClass has a field "name" which I want to use as identifier for that instance.
  • The DSL definition imports and uses the ecore model, this seems to work (no errors, warnings...)
    import "http ://drei.net/toreference" as ref
    ...
    'Reference:' ref = [ref::SomeClass]
    

  • I added Xtext nature to the project containing the ecore and genmodel
  • I added a referencedResource entry in the .mwe2 file
    language = StandardLanguage {
    	name = "net.drei.DecDescLanguage"
    	referencedResource = "platform:/resource/net.drei.ToReference/model/ToReference.genmodel"
    	fileExtensions = "ddl"
    	...
    }
    


Now when I use my DSL, I can create ".toreference" models and add instances of "SomeClass" to it. But right now I seem to be unable to refer to these classes from inside my DSL.
// I have a SomeClass named "one" in a file next to the DSL file
Reference: one 

then I get the error Couldn't resolve reference to SomeClass 'one'.

My guess is that I now have to write some code which maps the name "one" to the element in the .toreference model. But where, is this a Scoping topic? Or am I missing something entirely?
Re: How to resolve reference to ecore class? [message #1730812 is a reply to message #1730672] Thu, 28 April 2016 16:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
Hi,

if ToReference is not xtext based you Need to Provide your own IResourceServiceProvider to be able to reference xmi based ecore models.
https://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/ should give you some ideas what to do


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to resolve reference to ecore class? [message #1731113 is a reply to message #1730812] Mon, 02 May 2016 21:56 Go to previous messageGo to next message
Mark Drei is currently offline Mark DreiFriend
Messages: 13
Registered: April 2016
Junior Member
Hi,

thanks for the blog article, that made things a lot clearer!

However I have a very strange problem now: I have exceptions when starting my client eclipse application.
I get a java.lang.ArrayStoreException exception when my Guice Module (which extends org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule) is loaded.
Debugging showed that somehow my Guice Module is and is not a com.google.inject.Module at the same time.
I stripped the problem down to this:
	initializeEcoreInjector() {
		ReferenceGuiceModule referenceGuiceModule = new ReferenceGuiceModule();
		Module tmp = referenceGuiceModule;
		crash(tmp);
		...
	}

	private void crash(Module module)
	{
		if (module instanceof Module) {
			... // The debugger never steps into this block
			    // how can this be when my code compiles?
		}
		// the next call will cause the exception
		tutNix(module);
	}

	private void tutNix(Module... modules) {
		... // some code which is never reached. The varargs argument causes the ArrayStoreException
	}


Any idea what the issue could be?
I suspected that it could be an incompatibility between the jars and and my compiled code, but shouldn't I be safe with the latest greatest java 1.8 version? I tried others, but didn't change the picture.

Thanks,
Mark
Re: How to resolve reference to ecore class? [message #1731125 is a reply to message #1731113] Tue, 03 May 2016 03:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
I have no idea how you setup this one. There should be the same guice dependency. Can you share a small reproducing example

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to resolve reference to ecore class? [message #1731149 is a reply to message #1731125] Tue, 03 May 2016 08:12 Go to previous messageGo to next message
Mark Drei is currently offline Mark DreiFriend
Messages: 13
Registered: April 2016
Junior Member
Small is somewhat difficult, I was not able to reproduce the issue without the whole Eclipse plugin structure. Simply having the same code in a Main method did not reproduce it.
On Github, https://github.com/MarkDrei/DecDescLang/tree/bughunt , is code which shows the issue with little extra source code, but it's still a couple of eclipse projects.
Re: How to resolve reference to ecore class? [message #1731151 is a reply to message #1731149] Tue, 03 May 2016 08:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.xtext.extension_resourceServiceProvider">
      <resourceServiceProvider
            class="net.dreiucker.decdesclanguage.toreference.ui.ExecutableExtensionFactory:org.eclipse.xtext.ui.resource.generic.EmfResourceUIServiceProvider"
            uriExtension="toreference">
      </resourceServiceProvider>
   </extension>

</plugin>



Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: net.dreiucker.DecDescLanguage.ToReference.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: net.dreiucker.decdesclanguage.toreference.ui.Activator
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 net.dreiucker.DecDescLanguage.ToReference,
 org.eclipse.xtext.ui
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.apache.log4j,
 org.eclipse.xtext.ui.shared



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to resolve reference to ecore class? [message #1731155 is a reply to message #1731151] Tue, 03 May 2016 09:11 Go to previous messageGo to next message
Mark Drei is currently offline Mark DreiFriend
Messages: 13
Registered: April 2016
Junior Member
Wow! Thank you so much!

How did you find this? Probably you know where to look for.
Can you give some advice how to recognize such issues in the future?
Re: How to resolve reference to ecore class? [message #1731156 is a reply to message #1731155] Tue, 03 May 2016 09:14 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13219
Registered: July 2009
Senior Member
just had a look on how you register the resource service provider

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Project Wizard for xtext Project
Next Topic:How to get started with code generator in intellij?
Goto Forum:
  


Current Time: Fri Nov 22 05:29:16 GMT 2019

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

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

Back to the top