Newer
Older
/*
* generated by Xtext 2.25.0
*/
package org.etsi.mts.tdl.formatting2;
import java.util.List;
import org.eclipse.xtext.formatting2.AbstractJavaFormatter;
import org.eclipse.xtext.formatting2.IFormattableDocument;
import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
import org.eclipse.xtext.xbase.lib.Extension;
import org.etsi.mts.tdl.Annotation;
import org.etsi.mts.tdl.Comment;
import org.etsi.mts.tdl.ElementImport;
import org.etsi.mts.tdl.NamedElement;
import org.etsi.mts.tdl.Element;
import org.etsi.mts.tdl.MemberAssignment;
import org.etsi.mts.tdl.PackageableElement;
import org.etsi.mts.tdl.ParameterMapping;
import org.etsi.mts.tdl.TestObjective;
import org.etsi.mts.tdl.services.TDLtxGrammarAccess;
import com.google.inject.Inject;
public class TDLtxFormatter extends AbstractJavaFormatter {
@Inject
@Extension
private TDLtxGrammarAccess _grammarAccess;
//lazy short default formatting approach based on delimiters
//TODO: it does not work with white-space delimiters
protected void formatCustom(Element e, IFormattableDocument doc) {
doc.prepend(e, p -> p.setNewLines(1));
var rbs = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getBEGINRule());
var res = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getENDRule());
int i = 0;
for (var rs : rbs) {
i++;
var re = res.get(res.size() - i);
doc.interior(rs, re, p -> p.indent());
}
for (var r : rbs) {
doc.append(r, p -> p.setNewLines(1));
}
for (var r : res) {
doc.surround(r, p -> p.setNewLines(1));
}
}
protected void format(org.etsi.mts.tdl.NamedElement e, IFormattableDocument doc) {
// doc.interior(e, p->p.indent());
formatCustom(e, doc);
for (Comment comment : e.getComment()) {
doc.surround(comment, p -> p.setNewLines(1));
doc.format(comment);
}
for (Annotation _annotation : e.getAnnotation()) {
// this.textRegionExtensions.regionFor(e).keyword("@")
doc.append(_annotation, p -> p.setNewLines(1));
doc.format(_annotation);
}
// doc.surround(this.textRegionExtensions.regionFor(e).keyword("@"), p->p.noSpace());
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
for (var c : e.eContents()) {
if (c instanceof NamedElement
|| c instanceof MemberAssignment
|| c instanceof ParameterMapping
|| c instanceof Comment
) {
doc.surround(c, p->p.setNewLines(1));
formatCustom((Element)c, doc);
}
}
if (e instanceof TestObjective) {
//TODO: a bit of a hack
for (var rs : this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getEStringRule())) {
doc.append(rs, p -> p.setNewLines(1));
}
}
}
protected void format(org.etsi.mts.tdl.Package _package, IFormattableDocument doc) {
// TODO: format HiddenRegions around keywords, attributes, cross references,
// etc.
org.etsi.mts.tdl.Package e = _package;
formatCustom(e, doc);
for (Comment comment : _package.getComment()) {
doc.surround(comment, p -> p.setNewLines(1));
doc.format(comment);
}
for (Annotation _annotation : _package.getAnnotation()) {
doc.surround(_annotation, p -> p.setNewLines(1));
doc.format(_annotation);
}
for (PackageableElement packageableElement : _package.getPackagedElement()) {
doc.format(packageableElement);
}
for (ElementImport elementImport : _package.getImport()) {
doc.surround(elementImport, p -> p.setNewLines(1));
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
doc.format(elementImport);
}
for (org.etsi.mts.tdl.Package __package : _package.getNestedPackage()) {
doc.format(__package);
}
}
protected void format(Comment comment, IFormattableDocument doc) {
// TODO: format HiddenRegions around keywords, attributes, cross references,
// etc.
doc.surround(comment, p -> p.setNewLines(1));
}
// TODO: implement for Annotation, ElementImport, AnnotationType, Extension,
// TestObjective, DataResourceMapping, DataElementMapping, SimpleDataType,
// SimpleDataInstance, StructuredDataType, StructuredDataInstance, Action,
// Function, ComponentType, GateType, Time, TestConfiguration, TestDescription,
// PredefinedFunction, ProcedureSignature, CollectionDataType,
// CollectionDataInstance, ParameterMapping, Member, FormalParameter,
// ProcedureParameter, MemberAssignment, ParameterBinding, MemberReference,
// OmitValue, AnyValue, AnyValueOrOmit, DataInstanceUse, LiteralValueUse,
// FormalParameterUse, FunctionCall, VariableUse, TimeLabelUse,
// PredefinedFunctionCall, ComponentInstance, Variable, TimeLabel, GateInstance,
// Timer, Connection, GateReference, BehaviourDescription, TimerStart,
// TimerStop, TimeOut, Wait, Quiescence, PeriodicBehaviour,
// AlternativeBehaviour, ParallelBehaviour, BoundedLoopBehaviour,
// OptionalBehaviour, UnboundedLoopBehaviour, ConditionalBehaviour,
// CompoundBehaviour, DefaultBehaviour, InterruptBehaviour, VerdictAssignment,
// Assertion, Stop, Break, Assignment, InlineAction, ActionReference,
// TestDescriptionReference, Interaction, Message, ProcedureCall,
// TimeConstraint, Block, LocalExpression, ComponentInstanceBinding, Target,
// ValueAssignment
}