Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350776 - Sample code in Formatter does not compile
Summary: Sample code in Formatter does not compile
Status: CLOSED DUPLICATE of bug 329996
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-30 03:56 EDT by Karsten Thoms CLA
Modified: 2017-10-31 11:17 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.