| Summary: | Sample code in Formatter does not compile | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Karsten Thoms <karsten.thoms> |
| Component: | Xtext | Assignee: | 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: | |||
dup *** This bug has been marked as a duplicate of bug 329996 *** Requested via bug 522520. -M. Requested via bug 522520. -M. |
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()); } } -----------------------------------------------------------------