/*
 * generated by Xtext
 */
package org.yakindu.sct.generator.genmodel.formatting;

import org.eclipse.xtext.Group;
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.yakindu.sct.generator.genmodel.services.SGenGrammarAccess;

/**
 * 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 SGenFormatter 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());

		// Find elements which declare their body in curly brackets.
		// - Increment Indentation for the body.
		// - Line wrap before opening and after closing element
		for (Pair<Keyword, Keyword> pair : grammar.findKeywordPairs("{", "}")) {
			c.setIndentation(pair.getFirst(), pair.getSecond());
			c.setLinewrap().after(pair.getFirst());
			c.setLinewrap().around(pair.getSecond());

			Keyword openingBrace = pair.getFirst();
			Group containingGroup = (Group) openingBrace.eContainer();

			// Top-most elements with brackets: Insert blank lines
			// if (containingGroup.eContainer().eContainer() instanceof Grammar)
			// {
			c.setLinewrap(1, 2, 2).before(containingGroup);
			c.setLinewrap(1, 2, 2).after(containingGroup);
			// }
		}

		SGenGrammarAccess g = (SGenGrammarAccess) getGrammarAccess();
		c.setLinewrap().around(g.getFeatureConfigurationRule());
		c.setLinewrap().around(g.getFeatureParameterValueRule());
	}
}

@@ -789,16 +789,80 @@
 ig c) %7B%0A
+%09%09SGenGrammarAccess g = (SGenGrammarAccess) getGrammarAccess();%0A
 %09%09// It'
@@ -986,19 +986,16 @@
 ments%0A%09%09
-// 
 c.setLin
@@ -997,37 +997,32 @@
 etLinewrap(0, 1,
-%0A%09%09//
  2).before(getGr
@@ -1017,33 +1017,16 @@
 before(g
-etGrammarAccess()
 .getSL_C
@@ -1034,35 +1034,32 @@
 MMENTRule());%0A%09%09
-// 
 c.setLinewrap(0,
@@ -1061,21 +1061,16 @@
 ap(0, 1,
-%0A%09%09//
  2).befo
@@ -1073,33 +1073,16 @@
 before(g
-etGrammarAccess()
 .getML_C
@@ -1098,19 +1098,16 @@
 e());%0A%09%09
-// 
 c.setLin
@@ -1128,33 +1128,16 @@
 .after(g
-etGrammarAccess()
 .getML_C
@@ -1152,16 +1152,17 @@
 le());%0A%0A
+%0A
 %09%09// Fin
@@ -1650,195 +1650,171 @@
 %0A%09%09%09
-// Top-most elements with brackets: Insert blank lines%0A%09%09%09// if (containingGroup.eContainer().eContainer() instanceof Grammar)%0A%09%09%09// %7B%0A%09%09%09c.setLinewrap(1, 2, 2).before(containingGroup
+c.setLinewrap(1, 2, 2).before(containingGroup);%0A%09%09%09c.setLinewrap(1, 1, 2).after(containingGroup);%0A%09%09%7D%0A%0A%0A%09%09c.setLinewrap().around(g.getFeatureConfigurationRule()
 );%0A
-%09
 %09%09c.
@@ -1829,116 +1829,136 @@
 rap(
-1, 2, 2).after(containingGroup);%0A%09%09%09// %7D%0A%09%09%7D%0A%0A%09%09SGenGrammarAccess g = (SGenGrammarAccess) getGrammarAccess
+).around(g.getFeatureParameterValueRule());%0A%09%09c.setNoLinewrap().after(%0A%09%09%09%09g.getGeneratorEntryAccess().getStatechartKeyword_0
 ()
+)
 ;%0A%09%09
@@ -1954,32 +1954,34 @@
 rd_0());%0A%09%09c.set
+No
 Linewrap().aroun
@@ -1968,38 +1968,42 @@
 etNoLinewrap().a
-round(
+fter(%0A%09%09%09%09
 g.getFeatureConf
@@ -2003,36 +2003,60 @@
 ureConfiguration
-Rule
+Access().getFeatureKeyword_1
 ());%0A%09%09c.setLine
@@ -2043,32 +2043,34 @@
 rd_1());%0A%09%09c.set
+No
 Linewrap().aroun
@@ -2068,50 +2068,80 @@
 p().
-around(g.getFeatureParameterValueRule
+before(%0A%09%09%09%09g.getGeneratorModelAccess().getGeneratorModelKeyword_0
 ());%0A
+%0A
 %09%7D%0A%7D

improve formatter to work with wizard