Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2017-08-14 09:39:23 +0000
committerJuergen Haug2017-08-28 15:09:41 +0000
commit965e852cc5dc0a3a6891c5bd8962d596eb122238 (patch)
tree34ec02c82941ccb213cd0dd88e66eb5d96c96912 /plugins/org.eclipse.etrice.core.fsm
parentc6148998f6ef8ec40882e70d684208440d8de574 (diff)
downloadorg.eclipse.etrice-965e852cc5dc0a3a6891c5bd8962d596eb122238.tar.gz
org.eclipse.etrice-965e852cc5dc0a3a6891c5bd8962d596eb122238.tar.xz
org.eclipse.etrice-965e852cc5dc0a3a6891c5bd8962d596eb122238.zip
[targetLang] migration to formatter2 + added ccstring formatting
Diffstat (limited to 'plugins/org.eclipse.etrice.core.fsm')
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/.antlr-generator-3.2.0-patch.jarbin0 -> 1484649 bytes
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/src-gen/org/eclipse/etrice/core/fsm/AbstractFSMRuntimeModule.java11
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/GenerateFSM.mwe22
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.xtend30
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.xtend107
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java10
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.java22
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.java318
9 files changed, 440 insertions, 62 deletions
diff --git a/plugins/org.eclipse.etrice.core.fsm/.antlr-generator-3.2.0-patch.jar b/plugins/org.eclipse.etrice.core.fsm/.antlr-generator-3.2.0-patch.jar
new file mode 100644
index 000000000..90516fd7a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.fsm/.antlr-generator-3.2.0-patch.jar
Binary files differ
diff --git a/plugins/org.eclipse.etrice.core.fsm/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.fsm/META-INF/MANIFEST.MF
index 827d2377e..46fdc34cf 100644
--- a/plugins/org.eclipse.etrice.core.fsm/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.core.fsm/META-INF/MANIFEST.MF
@@ -28,7 +28,7 @@ Export-Package: org.eclipse.etrice.core.fsm,
org.eclipse.etrice.core.fsm.fSM,
org.eclipse.etrice.core.fsm.fSM.impl,
org.eclipse.etrice.core.fsm.fSM.util,
- org.eclipse.etrice.core.fsm.formatting,
+ org.eclipse.etrice.core.fsm.formatting2,
org.eclipse.etrice.core.fsm.generator,
org.eclipse.etrice.core.fsm.naming,
org.eclipse.etrice.core.fsm.parser.antlr,
diff --git a/plugins/org.eclipse.etrice.core.fsm/src-gen/org/eclipse/etrice/core/fsm/AbstractFSMRuntimeModule.java b/plugins/org.eclipse.etrice.core.fsm/src-gen/org/eclipse/etrice/core/fsm/AbstractFSMRuntimeModule.java
index 0c4317193..d9ad7cf06 100644
--- a/plugins/org.eclipse.etrice.core.fsm/src-gen/org/eclipse/etrice/core/fsm/AbstractFSMRuntimeModule.java
+++ b/plugins/org.eclipse.etrice.core.fsm/src-gen/org/eclipse/etrice/core/fsm/AbstractFSMRuntimeModule.java
@@ -153,9 +153,14 @@ public abstract class AbstractFSMRuntimeModule extends org.eclipse.xtext.service
return org.eclipse.etrice.core.fsm.generator.FSMGenerator.class;
}
- // contributed by org.eclipse.xtext.generator.formatting.FormatterFragment
- public Class<? extends org.eclipse.xtext.formatting.IFormatter> bindIFormatter() {
- return org.eclipse.etrice.core.fsm.formatting.FSMFormatter.class;
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public Class<? extends org.eclipse.xtext.formatting2.IFormatter2> bindIFormatter2() {
+ return org.eclipse.etrice.core.fsm.formatting2.FSMFormatter.class;
+ }
+
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public void configureFormatterPreferences(com.google.inject.Binder binder) {
+ binder.bind(org.eclipse.xtext.preferences.IPreferenceValuesProvider.class).annotatedWith(org.eclipse.xtext.formatting2.FormatterPreferences.class).to(org.eclipse.xtext.formatting2.FormatterPreferenceValuesProvider.class);
}
}
diff --git a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/GenerateFSM.mwe2 b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/GenerateFSM.mwe2
index 412df2b89..f499fb284 100644
--- a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/GenerateFSM.mwe2
+++ b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/GenerateFSM.mwe2
@@ -102,7 +102,7 @@ Workflow {
fragment = generator.GeneratorFragment auto-inject {}
// formatter API
- fragment = formatting.FormatterFragment auto-inject {}
+ fragment = formatting2.Formatter2Fragment auto-inject {}
// labeling API
fragment = labeling.LabelProviderFragment auto-inject {}
diff --git a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.xtend b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.xtend
deleted file mode 100644
index 6f61b3ed6..000000000
--- a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.xtend
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * generated by Xtext
- */
-package org.eclipse.etrice.core.fsm.formatting
-
-import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
-import org.eclipse.xtext.formatting.impl.FormattingConfig
-// import com.google.inject.Inject;
-// import org.eclipse.etrice.core.fsm.services.FSMGrammarAccess
-
-/**
- * This class contains custom formatting description.
- *
- * see : http://www.eclipse.org/Xtext/documentation.html#formatting
- * on how and when to use it
- *
- * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
- */
-class FSMFormatter extends AbstractDeclarativeFormatter {
-
-// @Inject extension FSMGrammarAccess
-
- 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(SL_COMMENTRule)
-// c.setLinewrap(0, 1, 2).before(ML_COMMENTRule)
-// c.setLinewrap(0, 1, 1).after(ML_COMMENTRule)
- }
-}
diff --git a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.xtend b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.xtend
new file mode 100644
index 000000000..95b05d019
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.xtend
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.fsm.formatting2
+
+import com.google.inject.Inject
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.etrice.core.common.converter.CCStringIndentation
+import org.eclipse.etrice.core.common.converter.CC_StringConverter
+import org.eclipse.etrice.core.common.formatting2.BaseFormatter
+import org.eclipse.etrice.core.fsm.fSM.DetailCode
+import org.eclipse.etrice.core.fsm.fSM.ProtocolSemantics
+import org.eclipse.etrice.core.fsm.fSM.State
+import org.eclipse.etrice.core.fsm.fSM.StateGraph
+import org.eclipse.etrice.core.fsm.fSM.Transition
+import org.eclipse.etrice.core.fsm.fSM.Trigger
+import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition
+import org.eclipse.etrice.core.fsm.services.FSMGrammarAccess
+import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
+import org.eclipse.xtext.formatting2.IFormattableDocument
+import org.eclipse.xtext.formatting2.ITextReplacerContext
+import org.eclipse.xtext.formatting2.internal.AbstractTextReplacer
+import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion
+
+class FSMFormatter extends BaseFormatter {
+
+ @Inject extension FSMGrammarAccess
+
+ override void formatAllByKeywords(EObject it, extension IFormattableDocument document) {
+ super.formatAllByKeywords(it, document)
+
+ allRegionsFor.keywords('->', 'extends', '=', 'or', '|').forEach[surround[oneSpace]]
+ }
+
+ protected def prependDefaultNewLines(EObject it, extension IFormattableDocument document) {
+ if(previousHiddenRegion.lineCount > 2) prepend[newLines = 2] else prepend[newLine]
+ }
+
+ protected def prependDefaultNewLines(ISemanticRegion it, extension IFormattableDocument document) {
+ if(previousHiddenRegion.lineCount > 2) prepend[newLines = 2] else prepend[newLine]
+ }
+
+ def dispatch void format(StateGraph it, extension IFormattableDocument document) {
+ eContents.forEach[prependDefaultNewLines(document)]
+ }
+
+ def dispatch void format(State it, extension IFormattableDocument document) {
+ regionFor.keywords('entry', 'exit', 'do', 'subgraph').forEach[prependDefaultNewLines(document) append[oneSpace]]
+ }
+
+ def dispatch void format(Transition it, extension IFormattableDocument document) {
+ regionFor.keywords('action', 'guard', 'cond').forEach[prependDefaultNewLines(document) append[oneSpace]]
+ }
+
+ def dispatch void format(TriggeredTransition it, extension IFormattableDocument document) {
+ regionFor.keywords('action', 'guard', 'cond', 'triggers').forEach[prependDefaultNewLines(document) append[oneSpace]]
+
+ triggers.head.prepend[newLine]
+ triggers.tail.forEach[prepend[oneSpace]]
+ }
+
+ def dispatch void format(Trigger it, extension IFormattableDocument document) {
+ regionFor.keywordPairs('<', '>').forEach[interior[noSpace]]
+ }
+
+ def dispatch void format(ProtocolSemantics it, extension IFormattableDocument document) {
+ rules.forEach[prependDefaultNewLines(document)]
+ }
+
+ @FinalFieldsConstructor
+ static class DetailCodeReplacer extends AbstractTextReplacer {
+
+ override createReplacements(ITextReplacerContext context) {
+ if (region.multiline) {
+ val ccIndent = new CCStringIndentation(CC_StringConverter.stripDelim(region.text.trim))
+ val endIndent = if(ccIndent.ignoreLast) context.indentationString else ''
+ val replacement = ccIndent.replaceEditorIndentation(context.getIndentationString(context.indentation + 1)) + endIndent
+ context => [
+ addReplacement(region.replaceWith(CC_StringConverter.DELIM + replacement + CC_StringConverter.DELIM))
+ ]
+
+ }
+
+ context
+ }
+
+ }
+
+ def dispatch void format(DetailCode detailcode, extension IFormattableDocument document) {
+ val ccRegion = detailcode.regionFor.assignment(detailCodeAccess.linesAssignment_0_1)
+ if(ccRegion !== null) {
+ detailcode.prepend[oneSpace]
+ if(detailcode.multiline) document.addReplacer(new DetailCodeReplacer(document, ccRegion))
+ } else {
+ detailcode.regionFor.assignments(detailCodeAccess.linesAssignment_1_1).forEach[prepend[newLine]]
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java
index 6e511dfe9..1a4df443a 100644
--- a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java
@@ -10,8 +10,7 @@ import java.util.List;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.etrice.core.common.converter.CC_StringConveter;
-import org.eclipse.etrice.core.common.util.CCStringIndentation;
+import org.eclipse.etrice.core.common.converter.CCStringIndentation;
import org.eclipse.etrice.core.fsm.fSM.ChoicePoint;
import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.fsm.fSM.FSMPackage;
@@ -131,8 +130,10 @@ public class FSMJavaValidator extends org.eclipse.etrice.core.fsm.validation.Abs
@Check
public void checkDetailCode(DetailCode dc) {
- if (dc.getLines().isEmpty())
+ if (dc.getLines().isEmpty()) {
error("detail code must not be empty", dc, FSMPackage.Literals.DETAIL_CODE__LINES);
+ return;
+ }
// ccstring is new standard for detail code
boolean isPlainStyle = false;
@@ -141,8 +142,7 @@ public class FSMJavaValidator extends org.eclipse.etrice.core.fsm.validation.Abs
if(lineNode.getGrammarElement() instanceof RuleCall){
AbstractRule rule = ((RuleCall)lineNode.getGrammarElement()).getRule();
if(rule == grammar.getCC_STRINGRule()) {
- CCStringIndentation ccStringIndent = new CCStringIndentation(CC_StringConveter.stripDelim(lineNode.getText()));
- if(!ccStringIndent.validateIndentation())
+ if(!new CCStringIndentation(lineNode.getText()).hasConsistentIndentation())
warning("Inconsistent indentation", dc, FSMPackage.Literals.DETAIL_CODE__LINES, lineNodes.indexOf(lineNode));
} else if(rule == grammar.getSTRINGRule()) {
isPlainStyle = true;
diff --git a/plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.java b/plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.java
deleted file mode 100644
index f2ff9c355..000000000
--- a/plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting/FSMFormatter.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * generated by Xtext
- */
-package org.eclipse.etrice.core.fsm.formatting;
-
-import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
-import org.eclipse.xtext.formatting.impl.FormattingConfig;
-
-/**
- * This class contains custom formatting description.
- *
- * see : http://www.eclipse.org/Xtext/documentation.html#formatting
- * on how and when to use it
- *
- * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
- */
-@SuppressWarnings("all")
-public class FSMFormatter extends AbstractDeclarativeFormatter {
- @Override
- protected void configureFormatting(final FormattingConfig c) {
- }
-}
diff --git a/plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.java b/plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.java
new file mode 100644
index 000000000..4e5f4abf4
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.fsm/xtend-gen/org/eclipse/etrice/core/fsm/formatting2/FSMFormatter.java
@@ -0,0 +1,318 @@
+/**
+ * Copyright (c) 2011 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ */
+package org.eclipse.etrice.core.fsm.formatting2;
+
+import com.google.inject.Inject;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.common.base.Annotation;
+import org.eclipse.etrice.core.common.base.AnnotationType;
+import org.eclipse.etrice.core.common.base.Documentation;
+import org.eclipse.etrice.core.common.base.Import;
+import org.eclipse.etrice.core.common.converter.CCStringIndentation;
+import org.eclipse.etrice.core.common.converter.CC_StringConverter;
+import org.eclipse.etrice.core.common.formatting2.BaseFormatter;
+import org.eclipse.etrice.core.fsm.fSM.DetailCode;
+import org.eclipse.etrice.core.fsm.fSM.ProtocolSemantics;
+import org.eclipse.etrice.core.fsm.fSM.SemanticsRule;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraph;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.core.fsm.fSM.Trigger;
+import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition;
+import org.eclipse.etrice.core.fsm.services.FSMGrammarAccess;
+import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
+import org.eclipse.xtext.Assignment;
+import org.eclipse.xtext.formatting2.IFormattableDocument;
+import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
+import org.eclipse.xtext.formatting2.ITextReplacerContext;
+import org.eclipse.xtext.formatting2.internal.AbstractTextReplacer;
+import org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion;
+import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
+import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder;
+import org.eclipse.xtext.formatting2.regionaccess.ITextReplacement;
+import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Pair;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@SuppressWarnings("all")
+public class FSMFormatter extends BaseFormatter {
+ @FinalFieldsConstructor
+ public static class DetailCodeReplacer extends AbstractTextReplacer {
+ @Override
+ public ITextReplacerContext createReplacements(final ITextReplacerContext context) {
+ ITextReplacerContext _xblockexpression = null;
+ {
+ ITextSegment _region = this.getRegion();
+ boolean _isMultiline = _region.isMultiline();
+ if (_isMultiline) {
+ ITextSegment _region_1 = this.getRegion();
+ String _text = _region_1.getText();
+ String _trim = _text.trim();
+ String _stripDelim = CC_StringConverter.stripDelim(_trim);
+ final CCStringIndentation ccIndent = new CCStringIndentation(_stripDelim);
+ String _xifexpression = null;
+ boolean _isIgnoreLast = ccIndent.isIgnoreLast();
+ if (_isIgnoreLast) {
+ _xifexpression = context.getIndentationString();
+ } else {
+ _xifexpression = "";
+ }
+ final String endIndent = _xifexpression;
+ int _indentation = context.getIndentation();
+ int _plus = (_indentation + 1);
+ String _indentationString = context.getIndentationString(_plus);
+ String _replaceEditorIndentation = ccIndent.replaceEditorIndentation(_indentationString);
+ final String replacement = (_replaceEditorIndentation + endIndent);
+ final Procedure1<ITextReplacerContext> _function = (ITextReplacerContext it) -> {
+ ITextSegment _region_2 = this.getRegion();
+ ITextReplacement _replaceWith = _region_2.replaceWith(((CC_StringConverter.DELIM + replacement) + CC_StringConverter.DELIM));
+ it.addReplacement(_replaceWith);
+ };
+ ObjectExtensions.<ITextReplacerContext>operator_doubleArrow(context, _function);
+ }
+ _xblockexpression = context;
+ }
+ return _xblockexpression;
+ }
+
+ public DetailCodeReplacer(final IFormattableDocument document, final ITextSegment region) {
+ super(document, region);
+ }
+ }
+
+ @Inject
+ @Extension
+ private FSMGrammarAccess _fSMGrammarAccess;
+
+ @Override
+ public void formatAllByKeywords(final EObject it, @Extension final IFormattableDocument document) {
+ super.formatAllByKeywords(it, document);
+ ISemanticRegionsFinder _allRegionsFor = this.textRegionExtensions.allRegionsFor(it);
+ List<ISemanticRegion> _keywords = _allRegionsFor.keywords("->", "extends", "=", "or", "|");
+ final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.surround(it_1, _function_1);
+ };
+ _keywords.forEach(_function);
+ }
+
+ protected EObject prependDefaultNewLines(final EObject it, @Extension final IFormattableDocument document) {
+ EObject _xifexpression = null;
+ IHiddenRegion _previousHiddenRegion = this.textRegionExtensions.previousHiddenRegion(it);
+ int _lineCount = _previousHiddenRegion.getLineCount();
+ boolean _greaterThan = (_lineCount > 2);
+ if (_greaterThan) {
+ final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
+ it_1.setNewLines(2);
+ };
+ _xifexpression = document.<EObject>prepend(it, _function);
+ } else {
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
+ it_1.newLine();
+ };
+ _xifexpression = document.<EObject>prepend(it, _function_1);
+ }
+ return _xifexpression;
+ }
+
+ protected ISemanticRegion prependDefaultNewLines(final ISemanticRegion it, @Extension final IFormattableDocument document) {
+ ISemanticRegion _xifexpression = null;
+ IHiddenRegion _previousHiddenRegion = it.getPreviousHiddenRegion();
+ int _lineCount = _previousHiddenRegion.getLineCount();
+ boolean _greaterThan = (_lineCount > 2);
+ if (_greaterThan) {
+ final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
+ it_1.setNewLines(2);
+ };
+ _xifexpression = document.prepend(it, _function);
+ } else {
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
+ it_1.newLine();
+ };
+ _xifexpression = document.prepend(it, _function_1);
+ }
+ return _xifexpression;
+ }
+
+ protected void _format(final StateGraph it, @Extension final IFormattableDocument document) {
+ EList<EObject> _eContents = it.eContents();
+ final Consumer<EObject> _function = (EObject it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _eContents.forEach(_function);
+ }
+
+ protected void _format(final State it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ List<ISemanticRegion> _keywords = _regionFor.keywords("entry", "exit", "do", "subgraph");
+ final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_1);
+ };
+ _keywords.forEach(_function);
+ }
+
+ protected void _format(final Transition it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ List<ISemanticRegion> _keywords = _regionFor.keywords("action", "guard", "cond");
+ final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_1);
+ };
+ _keywords.forEach(_function);
+ }
+
+ protected void _format(final TriggeredTransition it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ List<ISemanticRegion> _keywords = _regionFor.keywords("action", "guard", "cond", "triggers");
+ final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_1);
+ };
+ _keywords.forEach(_function);
+ EList<Trigger> _triggers = it.getTriggers();
+ Trigger _head = IterableExtensions.<Trigger>head(_triggers);
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
+ it_1.newLine();
+ };
+ document.<Trigger>prepend(_head, _function_1);
+ EList<Trigger> _triggers_1 = it.getTriggers();
+ Iterable<Trigger> _tail = IterableExtensions.<Trigger>tail(_triggers_1);
+ final Consumer<Trigger> _function_2 = (Trigger it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.<Trigger>prepend(it_1, _function_3);
+ };
+ _tail.forEach(_function_2);
+ }
+
+ protected void _format(final Trigger it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ List<Pair<ISemanticRegion, ISemanticRegion>> _keywordPairs = _regionFor.keywordPairs("<", ">");
+ final Consumer<Pair<ISemanticRegion, ISemanticRegion>> _function = (Pair<ISemanticRegion, ISemanticRegion> it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.<ISemanticRegion, ISemanticRegion>interior(it_1, _function_1);
+ };
+ _keywordPairs.forEach(_function);
+ }
+
+ protected void _format(final ProtocolSemantics it, @Extension final IFormattableDocument document) {
+ EList<SemanticsRule> _rules = it.getRules();
+ final Consumer<SemanticsRule> _function = (SemanticsRule it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _rules.forEach(_function);
+ }
+
+ protected void _format(final DetailCode detailcode, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(detailcode);
+ FSMGrammarAccess.DetailCodeElements _detailCodeAccess = this._fSMGrammarAccess.getDetailCodeAccess();
+ Assignment _linesAssignment_0_1 = _detailCodeAccess.getLinesAssignment_0_1();
+ final ISemanticRegion ccRegion = _regionFor.assignment(_linesAssignment_0_1);
+ if ((ccRegion != null)) {
+ final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
+ it.oneSpace();
+ };
+ document.<DetailCode>prepend(detailcode, _function);
+ boolean _isMultiline = this.textRegionExtensions.isMultiline(detailcode);
+ if (_isMultiline) {
+ FSMFormatter.DetailCodeReplacer _detailCodeReplacer = new FSMFormatter.DetailCodeReplacer(document, ccRegion);
+ document.addReplacer(_detailCodeReplacer);
+ }
+ } else {
+ ISemanticRegionsFinder _regionFor_1 = this.textRegionExtensions.regionFor(detailcode);
+ FSMGrammarAccess.DetailCodeElements _detailCodeAccess_1 = this._fSMGrammarAccess.getDetailCodeAccess();
+ Assignment _linesAssignment_1_1 = _detailCodeAccess_1.getLinesAssignment_1_1();
+ List<ISemanticRegion> _assignments = _regionFor_1.assignments(_linesAssignment_1_1);
+ final Consumer<ISemanticRegion> _function_1 = (ISemanticRegion it) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
+ it_1.newLine();
+ };
+ document.prepend(it, _function_2);
+ };
+ _assignments.forEach(_function_1);
+ }
+ }
+
+ public void format(final Object it, final IFormattableDocument document) {
+ if (it instanceof TriggeredTransition) {
+ _format((TriggeredTransition)it, document);
+ return;
+ } else if (it instanceof State) {
+ _format((State)it, document);
+ return;
+ } else if (it instanceof XtextResource) {
+ _format((XtextResource)it, document);
+ return;
+ } else if (it instanceof Transition) {
+ _format((Transition)it, document);
+ return;
+ } else if (it instanceof Annotation) {
+ _format((Annotation)it, document);
+ return;
+ } else if (it instanceof AnnotationType) {
+ _format((AnnotationType)it, document);
+ return;
+ } else if (it instanceof Documentation) {
+ _format((Documentation)it, document);
+ return;
+ } else if (it instanceof Import) {
+ _format((Import)it, document);
+ return;
+ } else if (it instanceof DetailCode) {
+ _format((DetailCode)it, document);
+ return;
+ } else if (it instanceof ProtocolSemantics) {
+ _format((ProtocolSemantics)it, document);
+ return;
+ } else if (it instanceof StateGraph) {
+ _format((StateGraph)it, document);
+ return;
+ } else if (it instanceof Trigger) {
+ _format((Trigger)it, document);
+ return;
+ } else if (it instanceof EObject) {
+ _format((EObject)it, document);
+ return;
+ } else if (it == null) {
+ _format((Void)null, document);
+ return;
+ } else if (it != null) {
+ _format(it, document);
+ return;
+ } else {
+ throw new IllegalArgumentException("Unhandled parameter types: " +
+ Arrays.<Object>asList(it, document).toString());
+ }
+ }
+}

Back to the top