Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » importURI with particular path syntax(ImportUriGlobalScopeProvider)
importURI with particular path syntax [message #1700554] Fri, 03 July 2015 15:29 Go to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Hello.

In my DSL, a file can import the contents of another file with the following syntax:
#import BaseDir\file.ext
where the parent directory of BaseDir is in the project workspace.

The default implementation of ImportUriGlobalScopeProvider could not resolve a URI from the value of importURI attribute of the include statement. I extended the ImportUriGlobalScopeProvider and override the createURICollector to replace the URICollector instance with an alternative implementation. I override the URI resolve(String uri) method to produce a URI from the paths. This works because the result of the getImportedUris method contains the URIs of the included files.

However, the include statement still produces the error:
"Imported resource could not be found"

Which class is responsible for finding the resource and fails by producing that message?
Re: importURI with particular path syntax [message #1700555 is a reply to message #1700554] Fri, 03 July 2015 15:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
org.eclipse.xtext.validation.ImportUriValidator

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI with particular path syntax [message #1700556 is a reply to message #1700555] Fri, 03 July 2015 15:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
thus you should better replace the ImportUriResolver

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI with particular path syntax [message #1700557 is a reply to message #1700555] Fri, 03 July 2015 15:48 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Thank you for the quick reply.

I had included the class in the ValidatorFragment section of the configuration.
Re: importURI with particular path syntax [message #1700558 is a reply to message #1700557] Fri, 03 July 2015 15:55 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Replacing the ImportUriResolver is better since I would have validation of imports and could move the code for resolving URIs from the ImportUriGlobalScopeProvider to the resolver. I don't know though how to replace the ImportUriResolver instance with my implementation. From the code, the URICollector has an instance of ImportUriResolver and ImportUriValidator has one too. Perhaps other classes may use ImportUriResolver instances as well. Are these instances shared and set by some other class?
Re: importURI with particular path syntax [message #1700559 is a reply to message #1700558] Fri, 03 July 2015 16:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Guice does the injection for you. See the docs on dependency injection

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI with particular path syntax [message #1700807 is a reply to message #1700559] Tue, 07 July 2015 10:48 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
I used the method Class<? extends ImportUriResolver> bindImportUriResolver() to return my implementation.

On a related topic, I wonder if it's possible to implement a jump from the file including the file to the included file. The user could for example, Ctrl+Click on the the path of the include statement to jump to that file. Has anyone implemented such a feature?
Re: importURI with particular path syntax [message #1700808 is a reply to message #1700807] Tue, 07 July 2015 10:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
you have to customize HyperlinkHelper

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI with particular path syntax [message #1700959 is a reply to message #1700808] Wed, 08 July 2015 12:19 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
I replaced HyperlinkHelper with my implementation. My implementation overrides createHyperlinksByOffset(XtextResource, int, IHyperlinkAcceptor). When the user hovers over an include path or the include keyword, the path is underlined. I print on the console the uri of the link produced by the method. The URI seems ok. When I click the link, the editor does not jump to the file nor it indicates any error.
Re: importURI with particular path syntax [message #1700962 is a reply to message #1700959] Wed, 08 July 2015 12:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
then you do the hyperlink wrong

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI with particular path syntax [message #1700966 is a reply to message #1700962] Wed, 08 July 2015 12:46 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Yes. In my implementation the URI of the HyperLink points to a Resource not a particular EObject contained in the resource. Perhaps this is the problem. Perhaps the user of the HyperLink assumes that the link points to an EObject within the resource.
Re: importURI with particular path syntax [message #1700967 is a reply to message #1700966] Wed, 08 July 2015 12:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
No

XtextHyperlink result = hyperlinkProvider.get();
result.setHyperlinkRegion(region);
result.setURI(normalized); // uri of the resource
result.setHyperlinkText(hyperlinkText);
acceptor.accept(result);

the resource itself should be ok as well. you may debug into xtexthyperlink.open


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: importURI with particular path syntax [message #1701001 is a reply to message #1700967] Wed, 08 July 2015 15:01 Go to previous message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Turns out that URI's are case sensitive under Windows.
platform:/resource/project/A.ext is not the same as platform:/resource/project/a.ext
Previous Topic:Internal*Parser class size
Next Topic:letter-based depth structure
Goto Forum:
  


Current Time: Tue Mar 19 03:16:07 GMT 2024

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

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

Back to the top