/* * generated by Xtext */ package org.erlide.formatting; import org.eclipse.xtext.Keyword; import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter; import org.eclipse.xtext.formatting.impl.FormattingConfig; import org.eclipse.xtext.util.Pair; import org.erlide.services.ErlangGrammarAccess; /** * 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 */ public class ErlangFormatter extends AbstractDeclarativeFormatter { @Override protected void configureFormatting(final FormattingConfig c) { final ErlangGrammarAccess g = getGrammarAccess(); c.setAutoLinewrap(80); // 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(g.getSL_COMMENTRule()); // c.setLinewrap(0, 1, // 2).before(getGrammarAccess().getML_COMMENTRule()); // c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule()); for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("(", ")")) { c.setNoSpace().after(pair.getFirst()); c.setNoSpace().before(pair.getSecond()); } for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("[", "]")) { c.setNoSpace().after(pair.getFirst()); c.setNoSpace().before(pair.getSecond()); } for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("{", "}")) { c.setNoSpace().after(pair.getFirst()); c.setNoSpace().before(pair.getSecond()); } for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("<<", ">>")) { c.setNoSpace().after(pair.getFirst()); c.setNoSpace().before(pair.getSecond()); } for (final Keyword sep : g.findKeywords(",", ";", ".")) { c.setNoSpace().before(sep); } for (final Keyword sep : g.findKeywords(":")) { c.setNoSpace().around(sep); } c.setNoSpace().after(g.getAttributeAccess().getHyphenMinusKeyword_0()); c.setNoSpace().after(g.getFunctionAccess().getNameAssignment_0()); c.setNoSpace().after(g.getFunctionClauseAccess().getRefAssignment_0()); c.setNoSpace().before(g.getFunctionAccess().getFullStopKeyword_3()); c.setNoSpace().around(g.getFunRefAccess().getSolidusKeyword_2()); c.setNoSpace().around(g.getFunRefAccess().getColonKeyword_0_1()); c.setLinewrap(0, 1, 2).before( g.getAttributeAccess().getHyphenMinusKeyword_0()); c.setLinewrap(2).after(g.getFunctionAccess().getFullStopKeyword_3()); c.setIndentationDecrement().after( g.getFunctionAccess().getFullStopKeyword_3()); c.setLinewrap().after(g.getFunctionAccess().getSemicolonKeyword_2_0()); c.setIndentationDecrement().after( g.getFunctionAccess().getSemicolonKeyword_2_0()); c.setLinewrap().after( g.getFunctionClauseAccess() .getHyphenMinusGreaterThanSignKeyword_5()); c.setIndentationIncrement().after( g.getFunctionClauseAccess() .getHyphenMinusGreaterThanSignKeyword_5()); c.setLinewrap().after( g.getListOrComprehensionAccess().getCommaKeyword_1_1_1_0()); c.setLinewrap().after(g.getExpressionsAccess().getCommaKeyword_1_0()); c.setNoLinewrap().after( g.getLExpressionAccess().getExprAssignment_0_1()); c.setLinewrap().after( g.getListOrComprehensionAccess() .getVerticalLineVerticalLineKeyword_1_1_2_1_1()); c.setLinewrap().after( g.getBinaryOrComprehensionAccess() .getVerticalLineVerticalLineKeyword_1_1_2_1()); } @Override protected ErlangGrammarAccess getGrammarAccess() { return (ErlangGrammarAccess) super.getGrammarAccess(); } }