Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding a new resource to the IResourceDescriptions
Adding a new resource to the IResourceDescriptions [message #1835708] Thu, 10 December 2020 19:38 Go to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
Hello folks,

I'm trying to serialize a model created programmatically and I'm encountering issues on the serialization of cross-references. The environment is Eclipse and involves two different projects so I'm having trouble understanding what's going on. I would appreciate some help if possible :)

Generally what I'm trying to achieve is:
1. A command is triggered from a menu
2. I inspect the current editor to get the current semantic object. The current editor is editing a file in what I'll call the "source project"
3. I create multiple new model trees (same Xtext language). The new model trees have cross references between them and to the source project.
4. I serialize the model trees into another target Eclipse project (the target project is configured to have visibility over the first source project) by creating a resource set from the target project and creating a resource per model tree.

I tried different variations of the above and always get to errors on the serialization of cross-references:

No EObjectDescription could be found in Scope <SourceClass>.<ref> for <TargetClass>'<name>'


References to the source project are being serialized correctly, and references within the same resource are serialized correctly. But it's references between the new resources that are giving the above error.

Is it that the new resources don't have ResourceDescriptions yet for the global scope to include the new objects?

What is the proper way to achieve what I'm trying to do?

For clarity here is roughly the code (Xtend) that I'm using:

    @Inject EObjectAtOffsetHelper objAtOffsetHelper
    @Inject IResourceSetProvider resSetProv

    override execute(ExecutionEvent event) throws ExecutionException {
            val editor = HandlerUtil.getActiveEditor(event) as XtextEditor
            if (editor !== null) {
                val doc = editor.document
                val sel = editor.selectionProvider.selection
                if (sel instanceof ITextSelection) {
                    val offset = sel.offset
                    val srcUri = doc.readOnly [ xtextResource |
                        val srcObj = objAtOffsetHelper.resolveContainedElementAt(xtextResource, offset)
                        if (srcObj !== null) {
                            EcoreUtil.getURI(srcObj)
                        }
                    ]

                    if (srcUri !== null) {
                        val tgtProject = <get-target-project>
                        val resSet = resSetProv.get(project)
                        val srcObj = resSet.getEObject(srcUri, true) as BlockType
                        val testingResSet = resSetProv.get(tgtProject)
                        
                        val rva1File = testingPrj.getFolder("src").getFile("RVA1.bls")
                        val rva2File = testingPrj.getFolder("src").getFile("RVA2.bls")
                        
                        val rva1 = createRVA => [
                            name = 'RVA1'
                            ref = srcObj // This is a reference to the source project
                        ]
                        val rva1Res = testingResSet.createResource(rva1File.toUri)  // I have a utility function to create a URI for an IFile
                        rva1Res.contents += rva1
                        
                        val rva2 = createRVA => [
                            name = 'RVA2'
                            ref = rva1 // This is a reference to the other new resource
                        ]                        
                        val rva2Res = testingResSet.createResource(rva2File.toUri)
                        rva2Res.contents += rva2
                        
                        rva1Res.save(#{}) // This succeeds because references to the source project serialize correctly
                        rva2Res.save(#{}) // This fails because the reference to the new resource fails to be serialized


Thanks in advance for any help!



Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Re: Adding a new resource to the IResourceDescriptions [message #1835710 is a reply to message #1835708] Thu, 10 December 2020 19:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, make sure you init your resourceset with LiveScopeResourceSetInitializer

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding a new resource to the IResourceDescriptions [message #1835744 is a reply to message #1835710] Fri, 11 December 2020 10:34 Go to previous message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
Thank you for the quick response Christian. Indeed your suggestion worked like a charm!

Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Previous Topic:New Xtext project from ECore - Packaging error
Next Topic:Programmatic serialization not using formatter preferences
Goto Forum:
  


Current Time: Tue Apr 23 08:52:12 GMT 2024

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

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

Back to the top