Adding a new resource to the IResourceDescriptions [message #1835708] |
Thu, 10 December 2020 19:38  |
Elie Richa 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02033 seconds