/*
 * generated by Xtext 2.25.0
 */
package org.etsi.mts.tdl.formatting2;

import java.util.List;

import org.eclipse.xtext.TerminalRule;
import org.eclipse.xtext.formatting2.IFormattableDocument;
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
import org.etsi.mts.tdl.services.TDLtxGrammarAccess;
import org.etsi.mts.tdl.structuredobjectives.ExpectedBehaviour;

import com.google.inject.Inject;

public class TDLtxiFormatter extends TDLtxFormatter {
	@Inject
	private TDLtxGrammarAccess _grammarAccess;

	protected void format(org.etsi.mts.tdl.structuredobjectives.ExpectedBehaviour e, IFormattableDocument doc) {
		//DONE: a bit of a hack, moved to TXi formatter?
		ISemanticRegion thatKeyword = this.textRegionExtensions.regionFor(e).keyword("that");

		if (thatKeyword!=null) {
			doc.append(thatKeyword, p->p.newLine());
			doc.append(thatKeyword, p->p.indent());
		}
		
		List<ISemanticRegion> when = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getWhenRule());
		List<ISemanticRegion> then = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getThenRule());
		if (!when.isEmpty()) {
			doc.surround(when.get(0), p->p.indent());
			doc.append(when.get(0), p->p.newLine());
			doc.interior(when.get(0), then.get(0), p->p.indent());
			doc.surround(then.get(0), p->p.indent());
			doc.append(then.get(0), p->p.newLine());
			doc.append(then.get(0), p->p.indent());
			doc.surround(((ExpectedBehaviour) e).getThenClause(), p->p.indent());
		}
		super.format(e, doc);

	}
}
