Using NodeModelUtils on cloned EObjects #3357
Unanswered
tfonda-fbk
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
A bit of context: in my project I am developing an editor that offers some extra functionality to the user. The user can trigger this functionality from a dedicated entry in the context menu that shows up when right-clicking on the editor view.
This functionality performs some computation, possibly modifying the parse tree Xtext created when parsing the file(s). Thus, after the computation has finished and the result has been presented to the user, there are discrepancies between the parse tree residing in memory and the content of the file(s). As a consequence, if the user triggers this functionality again, a failure happens, as the functionality now operates on a tainted parse tree.
To work around this problem, I wrote some code to duplicate the entire ResourceSet (because in our DSL, model files can import other model files) containing the Resource corresponding to the file the user right-clicked on when they triggered the functionality. This way, the functionality operates on a clean parse tree that matches the textual models each time it is invoked. Preliminary question: is this a clever idea, or are there better ways to achieve this?
Assuming it is a clever idea, let's move on to the real problem. The code for my extra functionality exploits
NodeModelUtils.findNodesForFeature()
andNodeModelUtils.getTokenText()
to retrieve some tokens from the textual model given an EObject. These methods work fine when operating on the original ResourceSet, butfindNodesForFeature()
seems to always return an empty list when called on an EObject belonging to the duplicate ResourceSet. Intuitively I guess this happens because the duplicate ResourceSet "does not derive from", and thus is not linked to, the textual models. Main question: is there anything I can do to find the INodes I need, starting from one of the cloned EObjects?FYI, the code I'm using to duplicate the ResourceSet is:
Many thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions