|
|
Re: How to get a Resource in a project [message #1062658 is a reply to message #1062640] |
Mon, 10 June 2013 05:46   |
Eclipse User |
|
|
|
Thanks for your answer Ed, but I need some extra explanation. 
I'm using Xtext and in my MyDSLImportUriGlobalScopeProvider, I want to make import URIs relative to the project (not to the current resource).
I get an import URI with this line of code:
String importUriString = getImportUriResolver().apply(object);
import that, as said, is relative to the project root. So, if the project structure is:
MyProject
->MyFolderA
->MyFile1.dsl
->MyFolderB
->MyFile2.dsl
if I want to import MyFile2.dsl into MyFile1.dsl, I'll write:
import "MyFolderB/MyFile2.dsl"
and so the importUriString will be "MyFolderB/MyFile2.dsl".
If I correctly understood, I have to construct an absolute URI and then use it with the EcoreUtil2 method getResource(Resource, String). Am I right?
I tried something as:
URI importUri = URI.createPlatformResourceURI("/"+projectName+"/"+importUriString, true);
Resource importedResource = EcoreUtil2.getResource(resource, importUriString);
but I obtain a null Resource. Could you please help me to understand where I am wrong?
Marco
|
|
|
Re: How to get a Resource in a project [message #1062667 is a reply to message #1062658] |
Mon, 10 June 2013 06:08  |
Eclipse User |
|
|
|
Marco,
Comments below.
On 10/06/2013 11:46 AM, Marco Naddeo wrote:
> Thanks for your answer Ed, but I need some extra explanation. :)
>
> I'm using Xtext and in my MyDSLImportUriGlobalScopeProvider, I want to
> make import URIs relative to the project (not to the current resource).
That's an Xtext question.
>
> I get an import URI with this line of code:
>
> String importUriString = getImportUriResolver().apply(object);
>
> import that, as said, is relative to the project root. So, if the
> project structure is:
>
>
> MyProject
> ->MyFolderA
> ->MyFile1.dsl
> ->MyFolderB
> ->MyFile2.dsl
>
> if I want to import MyFile2.dsl into MyFile1.dsl, I'll write:
>
> import "MyFolderB/MyFile2.dsl"
>
> and so the importUriString will be "MyFolderB/MyFile2.dsl".
>
> If I correctly understood, I have to construct an absolute URI and
> then use it with the EcoreUtil2 method getResource(Resource, String).
> Am I right?
>
> I tried something as:
>
>
> URI importUri =
> URI.createPlatformResourceURI("/"+projectName+"/"+importUriString, true);
> Resource importedResource = EcoreUtil2.getResource(resource,
> importUriString);
>
>
> but I obtain a null Resource.
These are all Xtext questions, but my impression is that this utility
method wants a relative URI. If you have an absolute URI, you can just
use ResourceSet.getResource (and can obtain the resource set from
resource.getResourceSet()).
> Could you please help me to understand where I am wrong?
>
>
> Marco
>
|
|
|
Powered by
FUDForum. Page generated in 0.07165 seconds