I would like to implement a formatter that emulates the IDE default. e.g newline after semicolon, 2 space indentation after opening brace, etc.
So firstly: is there a quick way to achieve this?
As a first step I tried un-commenting the three rules in the auto-generated class as follows:
public class OoaFormatter extends AbstractDeclarativeFormatter {
@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());
}
}
However this generates an error in the IDE for each of the three calls to setLineWrap:
The method getML_COMMENTRule() is undefined for the type IGrammarAccess
So I looked at the docs and tried the code there:
//...
@Override
protected void configureFormatting(FormattingConfig c) {
OoaGrammarAccess f = getGrammarAccess(); //error
//...
However the call to getGrammarAccess() produces another error:
Type mismatch: cannot convert from IGrammarAccess to OoaGrammarAccess
Before I chase this down I'd appreciate any suggestions on how best to proceed. Examples especially appreciated.
Thanks.