Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Load EObject with all cross-references from file path
Load EObject with all cross-references from file path [message #1723512] Tue, 16 February 2016 10:21 Go to next message
Andreas Stange is currently offline Andreas StangeFriend
Messages: 2
Registered: February 2016
Junior Member
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 #1723540 is a reply to message #1723512] Tue, 16 February 2016 13:39 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 748
Registered: July 2009
Location: Dortmund, Germany
Senior Member

XtextResource.OPTION_RESOLVE_ALL option and EcoreUtil2.resolveAll(resource) do resolve all cross references of a resource, but therefore all potential cross-referenced resources have to be part of the ResourceSet.

In a standalone environment you will have to populate the ResourceSet programmatically. Within Eclipse, all potential resources are known within the workspace or referenced libraries. In a standalone environment not.

Within a MWE workflow, the XtextReader component does such a job. Based on the configured platform URI it searches for files for which a DSL file extension is registered.

Outside an MWE workflow you will have to populate your ResourceSet yourself.

Consider that it is usually not necessary to resolve all cross references at once (although there are certain special use cases), since they will resolve lazily and this is usually the desired way.


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Load EObject with all cross-references from file path [message #1723633 is a reply to message #1723540] Tue, 16 February 2016 21:57 Go to previous message
Andreas Stange is currently offline Andreas StangeFriend
Messages: 2
Registered: February 2016
Junior Member
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.
Previous Topic:Inferr 1. type parameter of inferredType( myExpression )
Next Topic:Adding Additional Parameters to ContentAssistContext
Goto Forum:
  


Current Time: Sat Sep 18 05:43:52 GMT 2021

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

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

Back to the top