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

Bug 350776

Summary: Sample code in Formatter does not compile
Product: [Modeling] TMF Reporter: Karsten Thoms <karsten.thoms>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: btickets
Version: 2.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Karsten Thoms CLA 2011-06-30 03:56:02 EDT
In the generated formatter the following code is produced:
-----------------------------------------------------------------
// 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());
-----------------------------------------------------------------


Uncommenting these lines leads to uncompilable code, since getSL_CommentRule() is not defined for IGrammarAccess.

I propose to change the generator to inject the DSL's GrammarAccess and use this one.

-----------------------------------------------------------------
import com.google.inject.Inject;
import ....services.MyDslGrammarAccess;

public class MyDslFormatter extends AbstractDeclarativeFormatter {
	@Inject
	private MyDslGrammarAccess grammarAccess; 

	@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(grammarAccess.getSL_COMMENTRule());
//		c.setLinewrap(0, 1, 2).before(grammarAccess.getML_COMMENTRule());
//		c.setLinewrap(0, 1, 1).after(grammarAccess.getML_COMMENTRule());
	}
}
-----------------------------------------------------------------
Comment 1 Sven Efftinge CLA 2012-11-21 09:27:07 EST
dup

*** This bug has been marked as a duplicate of bug 329996 ***
Comment 2 Eclipse Webmaster CLA 2017-10-31 11:06:08 EDT
Requested via bug 522520.

-M.
Comment 3 Eclipse Webmaster CLA 2017-10-31 11:17:25 EDT
Requested via bug 522520.

-M.