Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334645

Summary: [formatter] AbstractDeclarativeFormatter is removing text
Product: [Modeling] TMF Reporter: Mark Christiaens <mark.g.j.christiaens>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mark.g.j.christiaens, moritz.eysholdt
Version: 2.0.0Flags: moritz.eysholdt: indigo+
Target Milestone: M6   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Mark Christiaens CLA 2011-01-18 09:13:09 EST
Build Identifier: 20100917-0705

I've implemented a formatter based on AbstractDeclarativeFormatter.  It's behaving strangely.  For example, I have a grammar rule:

-------------------------------------------------------------------------------
EntityDeclaration: 
        'entity' name=Identifier 'is'
	...
	'end' 'entity'? end_name=[EntityDeclaration]? ';';
-------------------------------------------------------------------------------

And a function in my formatter that configures the some formatting (I have a lot other such functions but I don't see how they could interfere):

-------------------------------------------------------------------------------
static private void configureEntityDeclaration(FormattingConfig c,
			VHDLLangGrammarAccess f) {
		EntityDeclarationElements eda = f.getEntityDeclarationAccess();
		c.setIndentationIncrement().after(eda.getIsKeyword_2());
		c.setIndentationDecrement().before(eda.getEndKeyword_7());
	}
-------------------------------------------------------------------------------

Prior to formatting the (garbled) input is: 

-------------------------------------------------------------------------------
...
library ieee;use ieee.std_logic_1164.all;
use ieee.numeric_std.all;entity

fmvgpwbdcxs is generic(
	knrjvwspqzm:integer range 2 to 6:= 6;
	ddqwgtngbxc:integer
range 0 to 63:=0;whxdkdmhjwj:integer range 0 to 9:=0;
...
-------------------------------------------------------------------------------

After formatting:

-------------------------------------------------------------------------------
...
library ieee;
use ieee.std_logic_1164.ALL; 

use ieee.numeric_std.ALL;
entity 



fmvgpwbdcxsis generic ( 

	knrjvwspqzm : integer range 2 to 6 := 6; 

    
	ddqwgtngbxc : integer 
    range 0 to 63 := 0;
    whxdkdmhjwj : integer range 0 to 9 := 0;
...
-------------------------------------------------------------------------------

Note that the 'is' keyword is gone before the generic.  

Reproducible: Always
Comment 1 Mark Christiaens CLA 2011-01-18 09:13:41 EST
I am using Xtext 2.0 M4
Comment 2 Moritz Eysholdt CLA 2011-02-07 08:56:04 EST
Hi Mark,

I tried to reproduce this with Xtext HEAD, but I couldn't.

I've used this grammar:
---------------
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=EntityDeclaration*;

EntityDeclaration:
	'entity' name=Identifier 'is'
	foo+=ID*
	'end' 'entity'? end_name=[EntityDeclaration]? ';';

Identifier:
	ID;
----------------


And this formatter:
---------------
public class MyDslFormatter extends AbstractDeclarativeFormatter {

  @Override
  protected void configureFormatting(FormattingConfig c) {

    MyDslGrammarAccess g = (MyDslGrammarAccess) getGrammarAccess();

    c.setIndentationIncrement().after(
        g.getEntityDeclarationAccess().getIsKeyword_2());
    c.setIndentationDecrement().before(
        g.getEntityDeclarationAccess().getEndKeyword_4());

    c.setLinewrap().after(
        g.getEntityDeclarationAccess().getFooAssignment_3());

  }
}
---------------


and this document:
---------------
entity fmvgpwbdcxs is foo
	bar
	baz
end fmvgpwbdcxs ; 
----------------

The document is getting formatted as intended an the keyword "is" is *not* getting lost.

Is there anything missing that I need to know to reproduce this?
Comment 3 Moritz Eysholdt CLA 2011-02-08 07:54:22 EST
After taking a closer look at the example I noticed that no token got lost, it's just a white-space that is disappearing:

original:
-------
fmvgpwbdcxs is generic
-------


formatted:
-------
fmvgpwbdcxsis generic
-------

(note the keyword "is" is still there, however, it erroneously got merged with "fmvgpwbdcxs")
Comment 4 Mark Christiaens CLA 2011-02-08 08:07:35 EST
So, is it a bug in the serialization or am I supposed to write my formatting rules differently?
Comment 5 Moritz Eysholdt CLA 2011-02-08 09:13:32 EST
(In reply to comment #4)
> So, is it a bug in the serialization or am I supposed to write my formatting
> rules differently?

Hi Mark,

it's a bug and I'm fixing it. As a workaround you can explicitly configure a white-space before the keyword:

cfg.setSpace(" ").before(ruleAccess.getIsKeyword());
Comment 6 Moritz Eysholdt CLA 2011-02-08 09:28:00 EST
fixed in master.
Comment 7 Karsten Thoms CLA 2017-09-19 17:04:39 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:16:37 EDT
Closing all bugs that were set to RESOLVED before Neon.0