Commit 19c3025d authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ formatting refinements

parent 50c0cfb9
Loading
Loading
Loading
Loading
+74 −25
Original line number Original line Diff line number Diff line
@@ -77,11 +77,11 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
		for (EObject m : e.eContents()) {
		for (EObject m : e.eContents()) {
			if (!(m instanceof Annotation) && !(m instanceof LocalExpression)) {
			if (!(m instanceof Annotation) && !(m instanceof LocalExpression)) {
				//TODO: handle nested behaviour
				//TODO: handle nested behaviour
				doc.prepend(m, p->p.newLine());
				doc.prepend(m, newLine());
				doc.surround(m, p->p.indent());
				doc.surround(m, indent());
				doc.append(m, p->p.newLine());
				doc.append(m, newLine());
			} else if (m instanceof Annotation) {
			} else if (m instanceof Annotation) {
				doc.append(m, p->p.newLine());
				doc.append(m, newLine());
			} else {
			} else {
			}
			}
			doc.format(m);
			doc.format(m);
@@ -212,6 +212,28 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
		return indent;
		return indent;
	}
	}


	public Procedure1<? super IHiddenRegionFormatter> noSpace() {
		Procedure1<? super IHiddenRegionFormatter> indent = p->p.noSpace();
		return indent;
	}

	public Procedure1<? super IHiddenRegionFormatter> setSpace(String space) {
		Procedure1<? super IHiddenRegionFormatter> indent = p->p.setSpace(space);
		return indent;
	}

	
	public Procedure1<? super IHiddenRegionFormatter> noIndentation() {
		Procedure1<? super IHiddenRegionFormatter> indent = p->p.noIndentation();
		return indent;
	}

	public Procedure1<? super IHiddenRegionFormatter> setNewLines(int lines) {
		Procedure1<? super IHiddenRegionFormatter> indent = p->p.setNewLines(lines);
		return indent;
	}

	
	public Procedure1<? super IHiddenRegionFormatter> newLine() {
	public Procedure1<? super IHiddenRegionFormatter> newLine() {
		Procedure1<? super IHiddenRegionFormatter> newLine = p->p.newLine();
		Procedure1<? super IHiddenRegionFormatter> newLine = p->p.newLine();
		return newLine;
		return newLine;
@@ -301,6 +323,13 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
			}
			}
		}
		}


		if (e instanceof TestDescription) {
			for (var o : ((TestDescription) e).getTestObjective()) {
				doc.prepend(o, newLine());
				doc.format(o);
			}
		}

		if (e instanceof DataElementMapping) {
		if (e instanceof DataElementMapping) {
			for (ParameterMapping m : ((DataElementMapping)e).getParameterMapping()) {
			for (ParameterMapping m : ((DataElementMapping)e).getParameterMapping()) {
				doc.prepend(m, newLine());
				doc.prepend(m, newLine());
@@ -326,6 +355,7 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
//			doc.prepend(rKeyword, newLine());
//			doc.prepend(rKeyword, newLine());
//			doc.surround(rKeyword, indent());
//			doc.surround(rKeyword, indent());
			
			
			doc.interior(e, indent());
			List<ISemanticRegion> features = this.textRegionExtensions.regionFor(e).features(
			List<ISemanticRegion> features = this.textRegionExtensions.regionFor(e).features(
					tdlPackage.Literals.TEST_OBJECTIVE__DESCRIPTION,
					tdlPackage.Literals.TEST_OBJECTIVE__DESCRIPTION,
					tdlPackage.Literals.TEST_OBJECTIVE__OBJECTIVE_URI
					tdlPackage.Literals.TEST_OBJECTIVE__OBJECTIVE_URI
@@ -334,11 +364,18 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
					);
					);
			for (ISemanticRegion f : features) {
			for (ISemanticRegion f : features) {
				//TODO: this depends on keywords..
				//TODO: this depends on keywords..
				doc.prepend(f.getPreviousSemanticRegion(), newLine());
//				doc.prepend(f.getPreviousSemanticRegion(), newLine());
				doc.surround(f.getPreviousSemanticRegion(), indent());
//				doc.surround(f.getPreviousSemanticRegion(), indent());
				doc.append(f, newLine());
				doc.append(f, newLine());
			}
			}
			
			
			List<ISemanticRegion> baseKeywords = this.textRegionExtensions.regionFor(e).keywords("Description", "References");
			for (ISemanticRegion f : baseKeywords) {
				doc.prepend(f, newLine());
//				doc.surround(f, indent());
			}


			if (e instanceof StructuredTestObjective) {
			if (e instanceof StructuredTestObjective) {
				//TODO: this depends on keywords..
				//TODO: this depends on keywords..
				List<ISemanticRegion> keywords = this.textRegionExtensions.regionFor(e).keywords("Configuration:", "PICS:");
				List<ISemanticRegion> keywords = this.textRegionExtensions.regionFor(e).keywords("Configuration:", "PICS:");
@@ -429,30 +466,36 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
//		if (!annotations.isEmpty()) {
//		if (!annotations.isEmpty()) {
//			doc.surround(annotations.get(0), newLine());
//			doc.surround(annotations.get(0), newLine());
//		}
//		}
		
	}
	}


	protected void format(org.etsi.mts.tdl.TestDescription e, IFormattableDocument doc) {
	protected void format(org.etsi.mts.tdl.TestDescription e, IFormattableDocument doc) {
		for (Annotation a : e.getAnnotation()) {
		for (Annotation a : e.getAnnotation()) {
			doc.surround(a, p->p.newLine());
			doc.surround(a, newLine());
//			doc.append(a, p->p.noIndentation());
//			doc.append(a, p->p.noIndentation());
			doc.format(a);
			doc.format(a);
//			doc.prepend(a, p->p.newLine());
//			doc.prepend(a, p->p.newLine());
		}
		}
		for (TestObjective a : e.getTestObjective()) {
		for (TestObjective a : e.getTestObjective()) {
			doc.append(a, p->p.newLine());
//			doc.append(a, p->p.noIndentation());
//			doc.append(a, p->p.noIndentation());
			doc.format(a);
			doc.format(a);
			doc.append(a, newLine());
		}
		}
		for (Comment c : e.getComment()) {
		for (Comment c : e.getComment()) {
			doc.append(c, p->p.newLine());
			doc.append(c, newLine());
//			doc.append(c, p->p.noIndentation());
//			doc.append(c, p->p.noIndentation());
			doc.format(c);
			doc.format(c);
		}
		}

		doc.prepend(e, newLine());
		for (EObject m : e.eContents()) {
		for (EObject m : e.eContents()) {
			doc.format(m);
			doc.format(m);
		}
		}
		
		List<ISemanticRegion> keywords = this.textRegionExtensions.regionFor(e).keywords("Test");
		for (ISemanticRegion f : keywords) {
			doc.prepend(f, newLine());
//			doc.surround(f, indent());
		}

	}
	}
	
	
	protected void format(org.etsi.mts.tdl.DataUse e, IFormattableDocument doc) {
	protected void format(org.etsi.mts.tdl.DataUse e, IFormattableDocument doc) {
@@ -464,8 +507,8 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
		}
		}
		if (e instanceof DataElementUse) {
		if (e instanceof DataElementUse) {
			for (DataUse m : ((DataElementUse) e).getItem()) {
			for (DataUse m : ((DataElementUse) e).getItem()) {
				doc.prepend(m, p->p.newLine());
				doc.prepend(m, newLine());
				doc.surround(m, p->p.indent());
				doc.surround(m, indent());
//			doc.append(m, p->p.newLine());
//			doc.append(m, p->p.newLine());
				doc.format(m);
				doc.format(m);
			}
			}
@@ -473,11 +516,11 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
		
		
		List<ISemanticRegion> closeParen = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getRParenRule());
		List<ISemanticRegion> closeParen = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getRParenRule());
		if (!closeParen.isEmpty()) {
		if (!closeParen.isEmpty()) {
			doc.prepend(closeParen.get(0), p->p.newLine());
			doc.prepend(closeParen.get(0), newLine());
		}
		}
		List<ISemanticRegion> closeItems = this.textRegionExtensions.regionFor(e).keywords("]");
		List<ISemanticRegion> closeItems = this.textRegionExtensions.regionFor(e).keywords("]");
		if (!closeItems.isEmpty()) {
		if (!closeItems.isEmpty()) {
			doc.prepend(closeItems.get(0), p->p.newLine());
			doc.prepend(closeItems.get(0), newLine());
		}
		}




@@ -494,32 +537,38 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
		
		
		Package e = _package;
		Package e = _package;
		for (Annotation a : e.getAnnotation()) {
		for (Annotation a : e.getAnnotation()) {
			doc.append(a, p->p.newLine());
			doc.append(a, newLine());
			doc.append(a, p->p.noIndentation());
			doc.append(a, noIndentation());
			doc.format(a);
			doc.format(a);
		}
		}
		for (Comment c : e.getComment()) {
		for (Comment c : e.getComment()) {
			doc.append(c, p->p.newLine());
			doc.append(c, newLine());
			doc.append(c, p->p.noIndentation());
			doc.append(c, noIndentation());
			doc.format(c);
			doc.format(c);
		}
		}
		doc.interior(_package, p->p.indent());
		doc.interior(_package, indent());


		List<ISemanticRegion> dots = this.textRegionExtensions.allRegionsFor(e).keywords(".", "@", ",", "::");
		List<ISemanticRegion> dots = this.textRegionExtensions.allRegionsFor(e).keywords(".", "@", ",", "::");
		for (ISemanticRegion dot : dots) {
		for (ISemanticRegion dot : dots) {
			doc.surround(dot, p -> p.noSpace());
			doc.surround(dot, noSpace());
		}
		List<ISemanticRegion> colon = this.textRegionExtensions.allRegionsFor(e).keywords(":");
		for (ISemanticRegion r : colon) {
			//TODO: remove space after
//			doc.surround(r, noSpace());
//			doc.append(r, indent());
		}
		}
		for (ElementImport elementImport : _package.getImport()) {
		for (ElementImport elementImport : _package.getImport()) {
			doc.surround(elementImport, p -> p.setNewLines(1));
			doc.surround(elementImport, setNewLines(1));
			doc.format(elementImport);
			doc.format(elementImport);
		}
		}
		for (PackageableElement packageableElement : _package.getPackagedElement()) {
		for (PackageableElement packageableElement : _package.getPackagedElement()) {
			doc.surround(packageableElement, p -> p.setNewLines(1));
			doc.surround(packageableElement, setNewLines(1));
			doc.format(packageableElement);
			doc.format(packageableElement);
		}
		}



		for (org.etsi.mts.tdl.Package __package : _package.getNestedPackage()) {
		for (org.etsi.mts.tdl.Package __package : _package.getNestedPackage()) {
			doc.surround(__package, setNewLines(1));
			doc.format(__package);
			doc.format(__package);
		}
		}
	}
	}