Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » IXtextDocument.modify consumes all preceding white space(Modifying a document in this way does not seem to obey my declared formatting)
IXtextDocument.modify consumes all preceding white space [message #892793] Fri, 29 June 2012 17:31 Go to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

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 #892949 is a reply to message #892793] Mon, 02 July 2012 06:31 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
The preceding whitespace is part of the following model element. This
explains why you find that lost in your document. However, it sounds
like a bug to me. Could you please file a ticket with a reproducable
sample attached?

Thanks a lot,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 29.06.12 19:31, schrieb Joey Mink:
> 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 Go to previous messageGo to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

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 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
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
Hello foo!
 Hello bar!

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

Previous Topic:EMF repository for Eclipse 3.5 and 3.6
Next Topic:Problem with scopes
Goto Forum:
  


Current Time: Thu Feb 20 12:12:25 GMT 2020

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

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

Back to the top