Commit cc68e4c2 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

* some formatting "improvements"

parent 55eb6f36
Loading
Loading
Loading
Loading
+46 −4
Original line number Diff line number Diff line
@@ -3,8 +3,13 @@
 */
package org.etsi.mts.tdl.formatting2;

import java.util.List;

import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.formatting2.IFormattableDocument;
import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.etsi.mts.tdl.Element;
import org.etsi.mts.tdl.ElementImport;
import org.etsi.mts.tdl.PackageableElement;
@@ -12,6 +17,7 @@ import org.etsi.mts.tdl.StructuredDataType;
import org.etsi.mts.tdl.StructuredDataInstance;
import org.etsi.mts.tdl.TestObjective;
import org.etsi.mts.tdl.TimeLabel;
import org.etsi.mts.tdl.tdlPackage;
import org.etsi.mts.tdl.TimeConstraint;
import org.etsi.mts.tdl.ComponentType;
import org.etsi.mts.tdl.Annotation;
@@ -20,6 +26,8 @@ import org.etsi.mts.tdl.DataElementMapping;
import org.etsi.mts.tdl.TestConfiguration;
import org.etsi.mts.tdl.TestDescription;
import org.etsi.mts.tdl.Behaviour;
import org.etsi.mts.tdl.ExceptionalBehaviour;
import org.etsi.mts.tdl.PeriodicBehaviour;
import org.etsi.mts.tdl.Comment;
import org.etsi.mts.tdl.FormalParameter;
import org.etsi.mts.tdl.LocalExpression;
@@ -51,11 +59,45 @@ public class TDLtxiFormatter extends TDLtxFormatter {
	}

	protected void format(org.etsi.mts.tdl.Element e, IFormattableDocument doc) {
		var open = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getBEGINRule());
		var close = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getENDRule());
		if (!open.isEmpty()) {
			doc.append(open.get(0), p->p.newLine());
			doc.interior(open.get(0), close.get(0), p->p.indent());
		}
//		doc.interior(e, p->p.indent());
		if (e instanceof Behaviour) {
//			List<ISemanticRegion> assignments = this.textRegionExtensions.regionFor(e).assignments(this._grammarAccess.findAssignments(this._grammarAccess.getTimeConstraintFragmentRule()).toArray(new Assignment[] {}));
//			for (var a : assignments) {
//				doc.prepend(a.getPreviousSemanticRegion(), p->p.newLine());
//				doc.surround(a.getPreviousSemanticRegion(), p->p.indent());
//				doc.append(a, p->p.newLine());
//			}
			List<ISemanticRegion> features = this.textRegionExtensions.regionFor(e).features(
					tdlPackage.Literals.BEHAVIOUR__TEST_OBJECTIVE
//					tdlPackage.Literals.ATOMIC_BEHAVIOUR__TIME_CONSTRAINT, 
//					tdlPackage.Literals.ATOMIC_BEHAVIOUR__TIME_LABEL 
					);
			for (var f : features) {
				//TODO: this depends on keywords..
				doc.prepend(f.getPreviousSemanticRegion(), p->p.newLine());
				doc.surround(f.getPreviousSemanticRegion(), p->p.indent());
				doc.append(f, p->p.newLine());
			}
		}

		
		
		for (var m : e.eContents()) {
			if (m instanceof Comment || 
					m instanceof TimeLabel ||
					m instanceof TimeConstraint ||
					m instanceof TestObjective
			if (m instanceof TimeLabel ||
					m instanceof TimeConstraint //||
//					m instanceof Comment
					) { 
				doc.append(m, p->p.newLine());
			} else if (m instanceof Comment || 
					m instanceof TestObjective ||
					m instanceof ExceptionalBehaviour ||
					m instanceof PeriodicBehaviour
					) {
				doc.prepend(m, p->p.newLine());
				doc.surround(m, p->p.indent());