IXtextDocument.modify consumes all preceding white space [message #892793] |
Fri, 29 June 2012 17:31 |
|
Hi all!
I've finally made use of IXextDocument.modify( IUnitOfWork.Void<XtextResource> ). Works wonderfully! Except for one thing.
public class SaveUnitOfWork extends IUnitOfWork.Void<XtextResource> {
...
public void process(XtextResource resource) throws Exception {
...
}
...
}
When I make changes to the XtextResource's underlying EMF model, the change is reflected in the editor (yay!). However, any whitespace preceding the EObject I modify gets removed. I've tried to update my DSL's implementation of AbstractDeclarativeFormatter to fix this, but it doesn't seem to have any affect on the removal of preceding whitespace.
Does this sound familiar to anyone who has used IXtextDocument.modify(...)?
|
|
|
|
Re: IXtextDocument.modify consumes all preceding white space [message #893057 is a reply to message #892949] |
Mon, 02 July 2012 12:51 |
|
Sebastian,
Thanks for your response! I just drafted up a simple example using the default Greeting DSL. I wrote an Eclipse command to rename the first Greeting's name to "foo" - and the whitespace preceding the name was maintained. So I figure it's probably not an Xtext bug.
I wonder about a statement you made:
Quote:The preceding whitespace is part of the following model element. This
explains why you find that lost in your document.
What exactly do you mean, "the following model element"?
|
|
|
Re: IXtextDocument.modify consumes all preceding white space [message #893388 is a reply to message #893057] |
Tue, 03 July 2012 19:28 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi,
internally there is the semantic model and the node model. Usually you are interested in the semantic model as it holds the typed model elements with its features. In that model information about hidden terminals (white spaces, comments etc.) is lost.
The node model contains the entire textual model file in a structured form, so that serialising the model again will result something that looks like what you started out with (in particular after changes in the model not caused by simple typing, like refactorings or application of quick fixes).
The semantic and the node model have a tight connection and the contract is that hidden terminals (e.g. white spaces) are associated with the semantic model element immediately following them.
So if you have the greetings example
the line break and space after foo! are already "part" of the second greeting.
Alex
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
[Updated on: Tue, 03 July 2012 19:29] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04863 seconds