|
|
|
|
|
Re: Using the XText Formatter [message #1047621 is a reply to message #1047617] |
Tue, 23 April 2013 08:57   |
Eclipse User |
|
|
|
At the moment it looks like this:
/*
* generated by Xtext
*/
package idainfront.xtex.iipax.idd.formatting
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
import org.eclipse.xtext.formatting.impl.FormattingConfig
import com.google.inject.Inject;
import idainfront.xtex.iipax.idd.services.IiDslGrammarAccess;
/**
* This class contains custom formatting description.
*
* see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
* on how and when to use it
*
* Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
*/
class IiDslFormatter extends AbstractDeclarativeFormatter {
@Inject extension IiDslGrammarAccess
IiDslGrammarAccess f;
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(SL_COMMENTRule)
// c.setLinewrap(0, 1, 2).before(ML_COMMENTRule)
// c.setLinewrap(0, 1, 1).after(ML_COMMENTRule)
f = ([u]IiDslGrammarAccess[/u])getGrammarAccess();
c.setAutoLinewrap(120);
// find common keywords an specify formatting for them
for (Pair<Keyword, Keyword> pair : [u]f.findKeywordPairs("(", ")")[/u]) {
c.setNoSpace().after(pair.[u]getFirst[/u]());
c.setNoSpace().before(pair.[u]getSecond[/u]());
}
for (Keyword comma : f.findKeywords(",")) {
c.setNoSpace().before(comma);
}
// formatting for grammar rule Line
c.setLinewrap(2).after(f.[u]getLineAccess[/u]().getSemicolonKeyword_1());
c.setNoSpace().before(f.[u]getLineAccess[/u]().getSemicolonKeyword_1());
// formatting for grammar rule TestIndentation
c.setIndentationIncrement().after(
f.[u]getTestIndentationAccess[/u]().getLeftCurlyBracketKeyword_1());
c.setIndentationDecrement().before(
f.[u]getTestIndentationAccess[/u]().getRightCurlyBracketKeyword_3());
c.setLinewrap().after(
f.[u]getTestIndentationAccess[/u]().getLeftCurlyBracketKeyword_1());
c.setLinewrap().after(
f.[u]getTestIndentationAccess[/u]().getRightCurlyBracketKeyword_3());
// formatting for grammar rule Param
c.setNoLinewrap().around(f.[u]getParamAccess[/u]().getColonKeyword_1());
c.setNoSpace().around(f.[u]getParamAccess[/u]().getColonKeyword_1());
// formatting for Comments
[u]cfg[/u].setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
[u]cfg[/u].setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
[u]cfg[/u].setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());
}
}
Underlined the places where I have errors 
[Edit: Or so I thought, seems underline doesn't work in code ]
[Updated on: Tue, 23 April 2013 08:58] by Moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07699 seconds