Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Define own scope: Reference C methods
Define own scope: Reference C methods [message #762832] Thu, 08 December 2011 17:16 Go to next message
thomas.kipar is currently offline thomas.kiparFriend
Messages: 13
Registered: July 2011
Junior Member
Hi,

I am new to Xtext and just started playing around a little with it. What I want to do is to define a DSL that contains cross references to C-Methods (totally analogous to the jvm-types stuff). What do I have to do for this?

What I did is:
- Creating a ecore model that contains a class describing a C-Method (lets call is CMethod)
- Importing that model to my xtext grammar, using the CMethod-class as cross reference in a rule
- Implementing IGlobalScopeProvider. In the getScope(...) method, I check the class of the given EReference
- If its type is CMethod, I return an instance of my own Scope (CMethdScope extends Abstractcope)
- Finally, I have to implement getAllLocalElements() in my CMehtodScope class. I just search for declared methods and return IEObjectDescriptions

For now, I'm unsure how to build the object descriptions. I just could pass a new instance of my CMethod class there. However, when using my generated editor I get a "dangling reference" error. The JVMTypes creates proxy objects, but I do not understand how to use/create some "custom" URIs that are used there ("java"-protocol), so thats where I am stuck.

Please, can somebody explain how do I have to build those IEObjectDescriptions I have to return from my own scope so I can use them in my grammar?

Regards,

Thoams

Re: Define own scope: Reference C methods [message #762907 is a reply to message #762832] Thu, 08 December 2011 19:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13409
Registered: July 2009
Senior Member
Hi,

do you know this: http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/ implementing an iresourceservice provider will make this magically working without any further customizations (uml ist just another ecore based metamodel as you cstuff is)

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Define own scope: Reference C methods [message #762941 is a reply to message #762907] Thu, 08 December 2011 20:56 Go to previous message
thomas.kipar is currently offline thomas.kiparFriend
Messages: 13
Registered: July 2011
Junior Member
Hi Christian,

thanks for your answer. If I understand it correctly, the example shown in the link uses references to existing instances of EObjects saved in a resource (an UML model in this case). I do not have something like that, since C-Code is not any ecore-resource.

However, think I got the thing running now (finally). Afaik Xtext can only hold references on other EObjects. Thats what I do not have (so I just create some arbitrary once in my scope provider). Doing so fails, because the linker is not able to find those objects somewhere. The solution is already given by the jvm-types stuff (but for quite difficult to understand, at least for me).
In order to reference other "custom" resources, you have to create your own "protocol" (=some string) and register it to the resourceSet attached to the resource given to your scope provider:
pResourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(PROTOCOL, resFactory);

where resFactory must be an instance implementing Resource.Factory (from emf). When returning IEObjectDescription from your scope, you have to set a proxy url (using your protocol) to the object you attach to the description:
InternalEObject internal = (InternalEObject) pObject;
internal.eSetProxyURI(URI.createURI("MY_PROTOCOL:/my/uri/one#frament.1"));

where MY_PROTOCOL is the protocol you used above. When Xtext runs the linker, your implementation of Resource.Factory is invoked in order to load the resource from the given uri (in which you encode the required information).

Hope that's it.
Previous Topic:Generator Problems with xtext 2.1.1
Next Topic:Two-step validation question
Goto Forum:
  


Current Time: Sun Mar 29 19:39:13 GMT 2020

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

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

Back to the top