Load EObject with all cross-references from file path [message #1723512] |
Tue, 16 February 2016 05:21  |
Eclipse User |
|
|
|
Hello,
I have a model A with references model B. Both are of the same DSL and in the same project and the project has the Xtext nature added to it. So in the Eclipse editor window everything is fine (no error markers).
Now I want to load an EObject of A where also B is resolved, as part of a project launch. Therefore I know the location of the file in which A is saved (lets say "src/A.mydsl").
This works if I create a ResourceSet that contains both, A and B:
// Get resource of A
val uriOfA = URI.createFileURI(fullPathOfA)
val resSet = new XtextResourceSet()
val resource = resSet.getResource(uriOfA, true)
// Get resource of B as well
resSet.getResource(URI.createFileURI(fullPathOfB)
// Load EObject for A where also B is resolved
if(!resource.getContents().isEmpty) {
return resource.getContents().get(0)
} else {
return null
}
But in general I don't know the location of the files that are referenced by A. I tried the following commands, because I thought they might find the referenced objects and resolve them:
resSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE)
EcoreUtil2.resolveAll(resource)
However, they do not. If I don't get the resource of B manually, the reference to it in the loaded EObject of A is null.
I read about an index that is maintained by Xtext and also found https://www.eclipse.org/forums/index.php/t/261245/ where a resourceDescriptionsProvider is used to find the referenced models.
However, when I do
@Inject
private ResourceDescriptionsProvider resourceDescriptionsProvider;
the resourceDescriptionsProvider is null, which is propably because I do this in a simple class that has nothing to do with Guice otherwise.
As result I have a few questions:
1. What does the XtextResource.OPTION_RESOLVE_ALL option and EcoreUtil2.resolveAll(resource) do, if not resolving all referenced EObjects?
2. Is there a predefined method that does what I want? IMO it does seem to be a normal use-case.
3. If there is no such method, how do I get a reference to the resourceDescriptionsProvider?
|
|
|
|
Re: Load EObject with all cross-references from file path [message #1723633 is a reply to message #1723540] |
Tue, 16 February 2016 16:57  |
Eclipse User |
|
|
|
Quote:Within Eclipse, all potential resources are known within the workspace or referenced libraries
What exactly does this mean? Can I create a ResourceSet that contains just ALL resources in the current workspace? I don't think this is efficient.
Well, I think I will just search my project for the files that have the file extension of my DSL and fill my ResourceSet with these. Then the OPTION_RESOLVE_ALL can the rest.
|
|
|
Powered by
FUDForum. Page generated in 0.09712 seconds