Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ResourceDescriptionStrategy for locally defined eObjects
ResourceDescriptionStrategy for locally defined eObjects [message #1030756] Sun, 31 March 2013 18:08 Go to next message
Steve Kallestad is currently offline Steve Kallestad
Messages: 62
Registered: March 2013
Member
I have implemented a custom ResourceDescriptionStrategy.

Within that ResourceDescriptionStrategy, I am adding custom userData.

I've also implemented a custom LinkingService.

For imported resources, I can see the custom userData within my LinkingService. For anything that's defined within the file I'm currently editing, no userData exists.

Looking through the documentation, I see that only objects outside the current resource are indexed.

I understand that, but I'm confused as to why my ResourceDescriptionStrategy is not being used to build IEObjectDescriptions for locally defined eObjects or how to actually implement something that will provide the data I'm looking for without actually having to re-implement the ResourceDescriptionStrategy anywhere and everywhere I might actually want to examine my userData.

Here's an example I'm working with:

I have a function declaration.
/*
 * multiplies two integers and returns the result
 */
function multiply(int x, int y){
  return x * y
}


Now, within my ResourceDescription Strategy, I want to store the function signature and a template as userData:
userData("signature") = "multiply(int, int)"
userData("template")  = "multiply(${x}, ${y})\n$cursor"
userData("do_a_dance")  = "let's get funky"


Within my LinkingService, when a user uses a function I want to be able to check the signature and link appropriately
final IScope scope = getScope(context, ref);
Iterator<IEObjectDescription> allel = scope.getAllElements().iterator();
while(allel.hasNext()){
	IEObjectDescription desc = allel.next();
			
	logger.debug("Signature:{}",desc.getUserData("signature"));
	}


For anything defined externally, I see the appropriate signature.
For anything defined within the editor, I see nothing.

I understand that there are many different ways to attack this problem, but it seems to me that there's no sense in leveraging a ResourceDescriptionStrategy for anything unless you can also implement it for things that are locally defined.

I'm sure there's a way to do it, I'm just missing it.

I can't seem to find it in the documentation and I swear I had found a forum post at one point that spelled it out, but I can't seem to find it anymore.
Re: ResourceDescriptionStrategy for locally defined eObjects [message #1030771 is a reply to message #1030756] Sun, 31 March 2013 18:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382535

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: ResourceDescriptionStrategy for locally defined eObjects [message #1030798 is a reply to message #1030771] Sun, 31 March 2013 19:44 Go to previous message
Steve Kallestad is currently offline Steve Kallestad
Messages: 62
Registered: March 2013
Member
Christian - you are da man!

To summarize the link - until that bug gets resolved you have to customize your ImportedNamespaceAwareLocalScopeProvider as well as your ResourceDescriptionStrategy.

That was a little tricky to figure out how to bind, so for the next guy...

If you search the Abstract-YourDSL-RuntimeModule.java you'll see:
// contributed by org.eclipse.xtext.generator.scoping.AbstractScopingFragment
public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
		binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.class);
	}



Override that function in your runtime module by copying the code and replacing it with your ImportedNamespaceAwareLocalScopeProvider subclass:
    @Override
    	public void configureIScopeProviderDelegate(Binder binder) {
    	binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class)
    	.annotatedWith(
    			com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(YourDSLImportedNamespaceAwareLocalScopeProvider.class);	
    }


That's probably obvious for a veteran xtext user. For me... that took a good deal of brain power (and I was already a little low).

I haven't coded the inserting of user data just yet in there, but that's the road I'm going down for the moment. There's some sample code in the bug report, but I haven't quite digested it just yet.

[Updated on: Sun, 31 March 2013 19:45]

Report message to a moderator

Previous Topic:How to import and parse a file with xtext and generate an EMF model out of it?
Next Topic:Model serialization problem
Goto Forum:
  


Current Time: Sat Oct 25 18:29:29 GMT 2014

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

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