Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Modifying an imported Xtext file programmatically(modification and reconciliation of abstract syntax with concrete syntax in xtext)
Modifying an imported Xtext file programmatically [message #1798253] Wed, 14 November 2018 16:57 Go to next message
Lucas Wagner is currently offline Lucas WagnerFriend
Messages: 7
Registered: March 2018
Junior Member
I'm working within the OSATE framework, which is an tooling environment for the AADL architecture description language. I am trying to process an AADL architecture and automatically modify the model for a program I'm working on.

I'm running into trouble modifying files that are imported from the file I originally run my code from in the editor. To make this concrete, I've attached an image of two test file that I'm using to illustrate the current problem. In it, there are two files "test.aadl" and "B.aadl", which contain packages (a package is a top level eobject defined in the xtext grammar for AADL) "test" and "B" respectively.

index.php/fa/34330/0/

I want to modify package test and, conditionally, I might want to modify package B when my code detects that something should be added to B. To accomplish this I'm using the following code snippet

index.php/fa/34331/0/

In this code, I have a contextual element (context, it is referenced in line 126 to get the resource) that I used to figure out where something needs to be added to the model. I use it to get the resource associated with it, open the file associated with the resource in the editor (line 134), and then use the getDocument().modify method of the editor to create a ReconcilingUnitOfWork object to do the actual modification within. The modification itself is shown in the method lines 149-163.

The problem? When I run this code, it is launched from an button press event in the editor that initially has "test.aadl" open, but not "B.aadl". If I it needs to modify "test.aadl" the code will launch an editor for "test.aadl" (it is already open) and modify it. If the code determines it must modify "B.aadl", it should open it (it is *not* already open) and then from the newly created editor, create a ReconcilingUnitOfWork inside which it can do that change.

The problem is this code opens imported files, but does not modify them. Inspection through debugging confirms the model for "B.aadl" is updated in memory, but the changes are not reconciled to the concrete syntax.

Some observations from debugging:


  • this code modifies the original file (test.aadl) if the context element exists within it
  • opening "B.aad" in the editor manually prior to running this code does not solve the problem
  • it appears that the editor is opened after the ReconcilingUnitOfWork is executed. I would expect from this code that the editor would be opened, then modified, but page.openEditor is likely a different thread so perhaps they occur simulaneously?


Any comments, suggestions, are appreciated. Thank you!

Re: Modifying an imported Xtext file programmatically [message #1798516 is a reply to message #1798253] Tue, 20 November 2018 06:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
following your description it is really hard to understand "what" you are actually changing and what is not working.

i assume modify only changes resources you call it on. => you have to call modify twice.

did you consider to have a look and use the change serializer api instead (no documentation, no tutorial, sorry)
as a starting point what to do you may have a look for org.eclipse.xtext.ui.editor.model.edit.BatchModification


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Unable to find mydsl package literals
Next Topic:Xtext DSLs ignored in Maven Multiple Modules Project
Goto Forum:
  


Current Time: Tue Apr 16 20:11:40 GMT 2024

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

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

Back to the top