Skip to main content



      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 13:31 Go to next message
Eclipse UserFriend
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 02:31 Go to previous messageGo to next message
Eclipse UserFriend
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 08:51 Go to previous messageGo to next message
Eclipse UserFriend
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 15:28 Go to previous message
Eclipse UserFriend
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

[Updated on: Tue, 03 July 2012 15:29] by Moderator

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


Current Time: Sun Jul 13 12:54:04 EDT 2025

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

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

Back to the top