ResourceDescriptionStrategy for locally defined eObjects [message #1030756] |
Sun, 31 March 2013 18:08 |
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 #1030798 is a reply to message #1030771] |
Sun, 31 March 2013 19:44 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.03593 seconds