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

Bug 329996

Summary: [formatter] invalid example code in comments
Product: [Modeling] TMF Reporter: Karsten Thoms <karsten.thoms>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: trivial    
Priority: P3 CC: btickets, moritz.eysholdt
Version: 1.0.1   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description Karsten Thoms CLA 2010-11-11 09:00:09 EST
In the formatter implementation the following default code is produced:
-------------------------------------------
	@Override
	protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getSL_COMMENTRule());
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
//		c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
	}
-------------------------------------------

Removing the comments as suggested will lead to non-compilable code, since getGrammarAccess() will return IGrammarAccess and getML_COMMENTRule()) is only valid on the DSL specific GrammarAccess.

I suggest to change the code to:

-------------------------------------------
	@Override
	protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following statements.
// They will add and preserve newlines around comments
//     «MyDSL»GrammarAccess g = («MyDSL»GrammarAccess) getGrammarAccess();
//		c.setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
//		c.setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
//		c.setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());
	}
-------------------------------------------
Comment 1 Sven Efftinge CLA 2012-11-19 08:41:31 EST
We should also generate the injected field of the language specific grammar access.
Comment 2 Sven Efftinge CLA 2012-11-21 09:27:07 EST
*** Bug 350776 has been marked as a duplicate of this bug. ***
Comment 3 Moritz Eysholdt CLA 2016-07-21 04:53:18 EDT
won't fix because it affects the old formatter infrastructure