xbase2 - formatting line breaks [message #688035] |
Thu, 23 June 2011 14:27  |
Eclipse User |
|
|
|
Hey folks,
I'm fighting with the xbase2 formatter.
This is what I currently have:
@SuppressWarnings("restriction")
public class FooScriptDslFormatter extends XbaseFormatter
{
@Override
protected void configureFormatting(FormattingConfig c)
{
// xbase
FooScriptDslGrammarAccess f = (FooScriptDslGrammarAccess) getGrammarAccess();
configure(c, f.getXbaseGrammarAccess());
}
}
Unfortunately this does not trigger line breaks for XFeatureCalls:
Should be transformed to:
Note that we don't want to introduce semicolons. Hence I was not able to determine the correct element for the setLinewrap() invocation.
Do I have to dig deeper or can we play a simple trick here?
Thanks!
erik
|
|
|
|
|
Re: xbase2 - formatting line breaks [message #901584 is a reply to message #688035] |
Mon, 13 August 2012 10:18  |
Eclipse User |
|
|
|
It seems this is not properly implemented for the xblockexpression as far as I could see it in the code. Here is the code that provides a nice formatting for me.
/**
* Some code taken from the Spray project style formatter</a>
*/
private void configureXBase(FormattingConfig c, XbaseGrammarAccess grammar) {
for (Pair<Keyword, Keyword> kw : grammar.findKeywordPairs("{", "}")) {
c.setLinewrap().after(kw.getFirst());
c.setLinewrap().around(kw.getSecond());
c.setIndentation(kw.getFirst(), kw.getSecond());
}
// no space before comma, one space after
for (Keyword kw : grammar.findKeywords(",")) {
c.setNoSpace().before(kw);
c.setSpace(" ").after(kw);
}
c.setNoSpace().around(
grammar.getStaticQualifierAccess().getColonColonKeyword_1());
xbaseFormmater.configureXMemberFeatureCall(c,
grammar.getXMemberFeatureCallAccess());
xbaseFormmater.configureXParenthesizedExpression(c,
grammar.getXParenthesizedExpressionAccess());
c.setLinewrap().after(grammar.getXExpressionInsideBlockRule());
Keyword semicolon = grammar.getXBlockExpressionAccess()
.getSemicolonKeyword_2_1();
c.setNoLinewrap().before(semicolon);
c.setNoSpace().before(semicolon);
c.setLinewrap().after(semicolon);
}
where xbaseFormmater is an instance of XbaseFormatter which you can inject easily with guice.
|
|
|
Powered by
FUDForum. Page generated in 0.02928 seconds