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

Bug 313677

Summary: [formatter] precedence of NoSpace/Linewrap unexpected
Product: [Modeling] TMF Reporter: Johan Wannheden <johan.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ed, moritz.eysholdt
Version: 1.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Johan Wannheden CLA 2010-05-20 05:02:16 EDT
Build Identifier: M20100211-1343

Given the following Xtext grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

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

Model :
  (elements+=Element)+
  (
    c='c'       &
    (d='d'      )?
  )
;

Element :
  '(' (AElement | BElement) ')'
;

AElement : elem='a';
BElement : elem='b';

and the following formatter rules defined in method configureFormatting:

ModelElements modelAccess = f.getModelAccess();
c.setLinewrap().before(modelAccess.getCCKeyword_1_0_0());
c.setLinewrap().before(modelAccess.getDDKeyword_1_1_0());

ElementElements elementAccess = f.getElementAccess();
c.setNoSpace().around(elementAccess.getLeftParenthesisKeyword_0());
c.setNoSpace().around(elementAccess.getRightParenthesisKeyword_2());

and the following model:

(a)(b)
c

I would execpt that formatting has no effect, i.e. that the model is already correctly formatted. But the outcome is the following:

(a)(b)c

Is this a bug? I would have expected a linewrap before 'c'.


Reproducible: Always

Steps to Reproduce:
1. Define grammar
2. Implement formatter
3. Create 'test.mydsl' and format given text
Comment 1 Johan Wannheden CLA 2010-05-20 05:03:01 EDT
This issue applies to Xtext RC1.
Comment 2 Moritz Eysholdt CLA 2010-05-20 05:20:55 EDT
Sounds like a Bug.

Could you check whether 

c.setLinewrap().before(modelAccess.getCAssignment_...());

or

c.setLinewrap().before(modelAccess.getGroup_2()); // The group which contains the assignments.

has the desired effect and could be a workaround?
Comment 3 Johan Wannheden CLA 2010-05-20 05:26:49 EDT
Unfortunately none of the suggested workarounds work :-(
Comment 4 Moritz Eysholdt CLA 2011-02-07 09:31:48 EST
*** Bug 314034 has been marked as a duplicate of this bug. ***
Comment 5 Moritz Eysholdt CLA 2016-07-21 04:22:38 EDT
won't fix because it affects the old formatter infrastructure