Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2017-08-14 05:39:23 -0400
committerJuergen Haug2017-08-28 11:09:41 -0400
commit965e852cc5dc0a3a6891c5bd8962d596eb122238 (patch)
tree34ec02c82941ccb213cd0dd88e66eb5d96c96912
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
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src-gen/org/eclipse/etrice/core/common/ui/AbstractBaseUiModule.java5
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/autoedit/BaseAutoEditStrategyProvider.java7
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.xtend26
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java43
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/xtend-gen/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.java30
-rw-r--r--plugins/org.eclipse.etrice.core.common/.antlr-generator-3.2.0-patch.jarbin0 -> 1484649 bytes
-rw-r--r--plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.etrice.core.common/src-gen/org/eclipse/etrice/core/common/AbstractBaseRuntimeModule.java11
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/GenerateBase.mwe22
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/BaseConverterService.java5
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CCStringIndentation.xtend195
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConverter.java41
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConveter.java43
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting/BaseFormatter.xtend38
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting2/BaseFormatter.xtend74
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/util/CCStringIndentation.java147
-rw-r--r--plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/converter/CCStringIndentation.java403
-rw-r--r--plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting/BaseFormatter.java29
-rw-r--r--plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting2/BaseFormatter.java251
-rw-r--r--plugins/org.eclipse.etrice.core.fsm.ui/icons/correction_change.gifbin0 -> 136 bytes
-rw-r--r--plugins/org.eclipse.etrice.core.fsm.ui/src-gen/org/eclipse/etrice/core/fsm/ui/AbstractFSMUiModule.java5
-rw-r--r--plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/contentassist/FSMProposalProvider.xtend3
-rw-r--r--plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.xtend4
-rw-r--r--plugins/org.eclipse.etrice.core.fsm.ui/xtend-gen/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.java5
-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
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/icons/correction_change.gifbin0 -> 136 bytes
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src-gen/org/eclipse/etrice/core/ui/AbstractRoomUiModule.java5
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java23
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/handler/DetailCodePasteHandler.java16
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml17
-rw-r--r--plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/AbstractRoomRuntimeModule.java11
-rw-r--r--plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/services/RoomGrammarAccess.java71
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe22
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomRuntimeModule.java1
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting/RoomFormatter.java5
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting2/RoomFormatter.xtend90
-rw-r--r--plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/formatting2/RoomFormatter.java349
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath1
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/.classpath1
-rw-r--r--tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend187
-rw-r--r--tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java326
-rw-r--r--tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/.classpath1
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF5
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room52
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room304
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room30
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room263
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room19
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room53
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch4
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java69
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend88
-rw-r--r--tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java161
63 files changed, 3605 insertions, 426 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF
index 8a6ba1b45..fcd5cb719 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.core.common.ui/META-INF/MANIFEST.MF
@@ -27,6 +27,7 @@ Export-Package: org.eclipse.etrice.core.common.ui.autoedit,
org.eclipse.etrice.core.common.ui.contentassist.antlr,
org.eclipse.etrice.core.common.ui.contentassist.antlr.internal,
org.eclipse.etrice.core.common.ui.editor,
+ org.eclipse.etrice.core.common.ui.editor.model,
org.eclipse.etrice.core.common.ui.highlight,
org.eclipse.etrice.core.common.ui.hover,
org.eclipse.etrice.core.common.ui.internal,
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src-gen/org/eclipse/etrice/core/common/ui/AbstractBaseUiModule.java b/plugins/org.eclipse.etrice.core.common.ui/src-gen/org/eclipse/etrice/core/common/ui/AbstractBaseUiModule.java
index d7feccd49..dfc1f4746 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src-gen/org/eclipse/etrice/core/common/ui/AbstractBaseUiModule.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src-gen/org/eclipse/etrice/core/common/ui/AbstractBaseUiModule.java
@@ -87,6 +87,11 @@ public abstract class AbstractBaseUiModule extends org.eclipse.xtext.ui.DefaultU
binder.bind(org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreInitializer.class).annotatedWith(com.google.inject.name.Names.named("builderPreferenceInitializer")).to(org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.Initializer.class);
}
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public Class<? extends org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory> bindIContentFormatterFactory() {
+ return org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory.class;
+ }
+
// contributed by org.eclipse.xtext.ui.generator.labeling.LabelProviderFragment
public Class<? extends org.eclipse.jface.viewers.ILabelProvider> bindILabelProvider() {
return org.eclipse.etrice.core.common.ui.labeling.BaseLabelProvider.class;
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/autoedit/BaseAutoEditStrategyProvider.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/autoedit/BaseAutoEditStrategyProvider.java
index 917d40296..f57c65754 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/autoedit/BaseAutoEditStrategyProvider.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/autoedit/BaseAutoEditStrategyProvider.java
@@ -1,11 +1,18 @@
package org.eclipse.etrice.core.common.ui.autoedit;
+import org.eclipse.etrice.core.common.ui.editor.model.BaseTokenTypeToPartitionMapper;
import org.eclipse.jface.text.IDocument;
import org.eclipse.xtext.ui.editor.autoedit.DefaultAutoEditStrategyProvider;
public class BaseAutoEditStrategyProvider extends DefaultAutoEditStrategyProvider {
@Override
+ protected void configureIndentationEditStrategy(IEditStrategyAcceptor acceptor) {
+ acceptor.accept(defaultIndentLineAutoEditStrategy.get(), BaseTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION);
+ super.configureIndentationEditStrategy(acceptor);
+ }
+
+ @Override
protected void configureStringLiteral(IEditStrategyAcceptor acceptor) {
acceptor.accept(partitionInsert.newInstance("'''", "'''"), IDocument.DEFAULT_CONTENT_TYPE);
super.configureStringLiteral(acceptor);
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.xtend b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.xtend
new file mode 100644
index 000000000..85eb2f8c8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.xtend
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.common.ui.editor.model
+
+import org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper
+
+class BaseTokenTypeToPartitionMapper extends TerminalsTokenTypeToPartitionMapper {
+
+ override protected calculateId(String tokenName, int tokenType) {
+ switch tokenName {
+ case 'RULE_CC_STRING': STRING_LITERAL_PARTITION
+ default: super.calculateId(tokenName, tokenType)
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java
index 7a918b1d8..b512b7f6e 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/highlight/BaseSemanticHighlighter.java
@@ -3,20 +3,26 @@ package org.eclipse.etrice.core.common.ui.highlight;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
-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.common.converter.CC_StringConverter;
+import org.eclipse.etrice.core.common.services.BaseGrammarAccess;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
+import org.eclipse.xtext.xbase.lib.Pair;
+
+import com.google.inject.Inject;
public class BaseSemanticHighlighter implements ISemanticHighlightingCalculator {
+ @Inject
+ BaseGrammarAccess grammar;
+
@Override
- public void provideHighlightingFor(XtextResource resource,
- IHighlightedPositionAcceptor acceptor) {
+ public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
if (resource == null || resource.getParseResult() == null)
return;
@@ -25,29 +31,26 @@ public class BaseSemanticHighlighter implements ISemanticHighlightingCalculator
EObject obj = node.getGrammarElement();
if (obj instanceof RuleCall) {
- RuleCall ruleCall = (RuleCall) obj;
- String name = ruleCall.getRule().getName();
- if(name.equals("CC_STRING"))
- detailCodeStringHighlight(node, acceptor, CC_StringConveter.DELIM);
+ if(((RuleCall) obj).getRule() == grammar.getCC_STRINGRule()) {
+ detailCodeStringHighlight(node, acceptor);
+ }
}
}
}
- protected void detailCodeStringHighlight(INode node, IHighlightedPositionAcceptor acceptor, String delim) {
+ protected void detailCodeStringHighlight(INode node, IHighlightedPositionAcceptor acceptor) {
+ final String delim = CC_StringConverter.DELIM;
if (node.getText() == null || node.getText().length() < delim.length() * 2)
return;
- acceptor.addPosition(node.getTotalOffset(), delim.length(), DefaultHighlightingConfiguration.STRING_ID);
- acceptor.addPosition(node.getTotalEndOffset() - delim.length(), delim.length(), DefaultHighlightingConfiguration.STRING_ID);
-
- String detailCodeString = node.getText().substring(delim.length(), node.getText().length() - delim.length());
- CCStringIndentation ccStringIndent = new CCStringIndentation(detailCodeString);
- List<int[]> lineStartLength = ccStringIndent.highlight();
-
- int offest = node.getOffset() + delim.length();
- for (int[] startLength : lineStartLength) {
- acceptor.addPosition(offest + startLength[0], startLength[1], BaseHighlightingConfig.HL_CCSTRING);
- }
+ acceptor.addPosition(node.getOffset(), delim.length(), DefaultHighlightingConfiguration.STRING_ID);
+ acceptor.addPosition(node.getEndOffset() - delim.length(), delim.length(), DefaultHighlightingConfiguration.STRING_ID);
+
+ int offset = node.getOffset() + delim.length();
+ List<Pair<Integer, Integer>> lineStartLength = new CCStringIndentation(CC_StringConverter.stripDelim(node.getText())).highlight();
+ for (Pair<Integer, Integer> offsetLength : lineStartLength) {
+ acceptor.addPosition(offset + offsetLength.getKey(), offsetLength.getValue(), BaseHighlightingConfig.HL_CCSTRING);
+ }
}
}
diff --git a/plugins/org.eclipse.etrice.core.common.ui/xtend-gen/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.java b/plugins/org.eclipse.etrice.core.common.ui/xtend-gen/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.java
new file mode 100644
index 000000000..f3a151c15
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common.ui/xtend-gen/org/eclipse/etrice/core/common/ui/editor/model/BaseTokenTypeToPartitionMapper.java
@@ -0,0 +1,30 @@
+/**
+ * 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.common.ui.editor.model;
+
+import org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper;
+
+@SuppressWarnings("all")
+public class BaseTokenTypeToPartitionMapper extends TerminalsTokenTypeToPartitionMapper {
+ @Override
+ protected String calculateId(final String tokenName, final int tokenType) {
+ String _switchResult = null;
+ switch (tokenName) {
+ case "RULE_CC_STRING":
+ _switchResult = TerminalsTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION;
+ break;
+ default:
+ _switchResult = super.calculateId(tokenName, tokenType);
+ break;
+ }
+ return _switchResult;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.common/.antlr-generator-3.2.0-patch.jar b/plugins/org.eclipse.etrice.core.common/.antlr-generator-3.2.0-patch.jar
new file mode 100644
index 000000000..90516fd7a
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common/.antlr-generator-3.2.0-patch.jar
Binary files differ
diff --git a/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF
index efe3daad6..e7d6930f9 100644
--- a/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.core.common/META-INF/MANIFEST.MF
@@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.xtext;bundle-version="2.6.0";visibility:=reexport,
org.eclipse.emf.codegen.ecore;resolution:=optional,
org.eclipse.emf.mwe.utils;resolution:=optional,
org.eclipse.emf.mwe2.launch;resolution:=optional,
+ org.objectweb.asm;bundle-version="[5.0.1,6.0.0)";resolution:=optional,
org.eclipse.emf.ecore,
org.eclipse.emf.common,
org.antlr.runtime,
@@ -31,7 +32,7 @@ Export-Package: org.eclipse.etrice.core.common,
org.eclipse.etrice.core.common.basetest.impl,
org.eclipse.etrice.core.common.basetest.util,
org.eclipse.etrice.core.common.converter,
- org.eclipse.etrice.core.common.formatting,
+ org.eclipse.etrice.core.common.formatting2,
org.eclipse.etrice.core.common.generator,
org.eclipse.etrice.core.common.naming,
org.eclipse.etrice.core.common.parser.antlr,
@@ -40,6 +41,5 @@ Export-Package: org.eclipse.etrice.core.common,
org.eclipse.etrice.core.common.scoping,
org.eclipse.etrice.core.common.serializer,
org.eclipse.etrice.core.common.services,
- org.eclipse.etrice.core.common.util,
org.eclipse.etrice.core.common.validation
diff --git a/plugins/org.eclipse.etrice.core.common/src-gen/org/eclipse/etrice/core/common/AbstractBaseRuntimeModule.java b/plugins/org.eclipse.etrice.core.common/src-gen/org/eclipse/etrice/core/common/AbstractBaseRuntimeModule.java
index fad15a03d..01fcc042a 100644
--- a/plugins/org.eclipse.etrice.core.common/src-gen/org/eclipse/etrice/core/common/AbstractBaseRuntimeModule.java
+++ b/plugins/org.eclipse.etrice.core.common/src-gen/org/eclipse/etrice/core/common/AbstractBaseRuntimeModule.java
@@ -148,9 +148,14 @@ public abstract class AbstractBaseRuntimeModule extends org.eclipse.xtext.servic
return org.eclipse.etrice.core.common.generator.BaseGenerator.class;
}
- // contributed by org.eclipse.xtext.generator.formatting.FormatterFragment
- public Class<? extends org.eclipse.xtext.formatting.IFormatter> bindIFormatter() {
- return org.eclipse.etrice.core.common.formatting.BaseFormatter.class;
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public Class<? extends org.eclipse.xtext.formatting2.IFormatter2> bindIFormatter2() {
+ return org.eclipse.etrice.core.common.formatting2.BaseFormatter.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.common/src/org/eclipse/etrice/core/common/GenerateBase.mwe2 b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/GenerateBase.mwe2
index c3f00269e..51641d290 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/GenerateBase.mwe2
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/GenerateBase.mwe2
@@ -114,7 +114,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.common/src/org/eclipse/etrice/core/common/converter/BaseConverterService.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/BaseConverterService.java
index 84d44fe57..2a7778e59 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/BaseConverterService.java
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/BaseConverterService.java
@@ -18,12 +18,15 @@ import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter;
import com.google.inject.Inject;
+import com.google.inject.Singleton;
+@Singleton
public class BaseConverterService extends DefaultTerminalConverters {
private TimeConverter timeConverter = new TimeConverter();
private LongConverter longConverter = new LongConverter();
private DoubleConverter doubleConverter = new DoubleConverter();
+ private CC_StringConverter ccStringConverter = new CC_StringConverter();
@Inject
private QualifiedNameValueConverter fqnConverter;
@@ -50,6 +53,6 @@ public class BaseConverterService extends DefaultTerminalConverters {
@ValueConverter(rule = "CC_STRING")
public IValueConverter<String> getCC_StringConverter() {
- return new CC_StringConveter();
+ return ccStringConverter;
}
}
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CCStringIndentation.xtend b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CCStringIndentation.xtend
new file mode 100644
index 000000000..e8110e5f7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CCStringIndentation.xtend
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * 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.common.converter
+
+import java.util.List
+import java.util.regex.Pattern
+import org.eclipse.xtend.lib.annotations.Accessors
+import org.eclipse.xtext.util.Strings
+import com.google.common.collect.ImmutableList
+
+/**
+ * TODO: Handling mixed line endings
+ *
+ * Improvement: Too much strings matching => use token scanner
+ */
+class CCStringIndentation {
+
+ val static JAVA_NL = Strings.newLine
+ val static CRLF = "\r\n"
+ val static LF = "\n"
+ val static CR = "\r"
+
+ static def boolean hasLineBreak(String nodeText) {
+ Strings.countLineBreaks(nodeText) > 0;
+ }
+
+ static def String getLineEnding(String it) {
+ switch it {
+ case indexOf(CRLF) >= 0: CRLF
+ case indexOf(LF) >= 0: LF
+ case indexOf(CR) >= 0: CR
+ default: JAVA_NL
+ }
+ }
+
+ val String ccString
+ val String lineEnding // first lineEnding found (mixed line endings ?!)
+
+ @Accessors(PUBLIC_GETTER)
+ val ImmutableList<String> splittedLines
+ @Accessors(PUBLIC_GETTER)
+ val boolean ignoreFirst
+ @Accessors(PUBLIC_GETTER)
+ val boolean ignoreLast
+
+ /**
+ * CCString without delimiters. Caller should handle their own delims.
+ */
+ new(String ccString) {
+ this.ccString = ccString
+ lineEnding = getLineEnding(ccString) // use contents line ending
+ splittedLines = ImmutableList.copyOf(newArrayList => [ lines |
+ // split lines by lineEnding, keep all whitespace
+ val matcher = Pattern.compile(lineEnding).matcher(ccString)
+ var lastOffset = 0
+ while (matcher.find) {
+ lines += ccString.substring(lastOffset, matcher.start)
+ lastOffset = matcher.end
+ }
+ if (lastOffset < ccString.length) {
+ // put rest
+ lines += ccString.substring(lastOffset)
+ } else if (ccString.endsWith(lineEnding)) {
+ // empty last line is important
+ lines += ''
+ }
+ ])
+ ignoreFirst = splittedLines.size >= 2 && splittedLines.head.trim.empty
+ ignoreLast = splittedLines.size >= 2 && splittedLines.last.trim.empty
+ }
+
+ /**
+ * Returns ccString without editor white space and delims.
+ *
+ * @see #highlight()
+ */
+ def String removeEditorWhiteSpace() {
+ removeEditorWhiteSpace('')
+ }
+
+ protected def String removeEditorWhiteSpace(String indent) {
+ highlight.fold('', [lines, offsetLength |
+ lines + indent + ccString.substring(offsetLength.key, offsetLength.key + offsetLength.value)
+ ])
+ }
+
+ /**
+ * Returns whether editor indentation can be removed safely.
+ */
+ def boolean canRemoveEditorIndentation() {
+ splittedLines.size >= 2 && ignoreFirst && hasConsistentIndentation
+ }
+
+ /**
+ * Returns ccString replaced with given indentation if possible. Ignored lines are trimmed. No delims included.
+ *
+ * @see #highlight()
+ */
+ def String replaceEditorIndentation(String indentation) {
+ val indent = if(indentation === null) '' else indentation
+ if(canRemoveEditorIndentation) {
+ if(ignoreFirst && splittedLines.size == 2) {
+ removeEditorWhiteSpace('')
+ } else {
+ (if(ignoreFirst) lineEnding else '') + removeEditorWhiteSpace(indent)
+ }
+ } else {
+ val lines = <String>newLinkedList(splittedLines) => [
+ if(ignoreFirst) set(0, '')
+ if(ignoreLast) set(size - 1, '')
+ ]
+ lines.join(lineEnding)
+ }
+ }
+
+ /**
+ * Returns highlighted positions without editor's indentation.<br>
+ * Positions are pairs of (offset, length) relative to {@link #CCStringIndentation(String)}
+ *
+ * @see #removeEditorWhiteSpace()
+ */
+ def List<Pair<Integer, Integer>> highlight() {
+ val offsetLengthLines = newArrayList
+
+ val editorIndent = computeEditorIndent(false)
+ val skip = editorIndent.length
+
+ var offset = 0
+ for (var i = 0 ; i < splittedLines.length; i++) {
+ val line = splittedLines.get(i)
+
+ if (i == 0 && ignoreFirst) {
+ offset += line.length + lineEnding.length
+ }
+ else if (i == splittedLines.size - 1 && ignoreLast){
+ // skip
+ }
+ else {
+ offsetLengthLines += {
+ val NL = if (i < splittedLines.size - 1) lineEnding.length else 0
+ if (line.startsWith(editorIndent))
+ offset + skip -> line.length - skip + NL
+ else
+ offset -> line.length + NL
+ }
+ offset += line.length + lineEnding.length
+ }
+ }
+
+ return offsetLengthLines
+ }
+
+
+ /**
+ * Check consistent indentation
+ */
+ def boolean hasConsistentIndentation() {
+ computeEditorIndent(true) !== null
+ }
+
+ protected def String computeEditorIndent(boolean consistentOnly) {
+ // no editor indent
+ if(splittedLines.size <= 1 || !ignoreFirst)
+ return ''
+
+ // leading space -> line
+ val wsLinePairs = {
+ val begin = if(ignoreFirst) 1 else 0
+ val end = splittedLines.size - (if(ignoreLast) 1 else 0)
+ splittedLines.subList(begin, end).map[ line |
+ Strings.getLeadingWhiteSpace(line) -> line
+ ].toList
+ }
+
+ val (Iterable<String>) => String minWSComputor = [if(empty) '' else min]
+ val textIndent = minWSComputor.apply(wsLinePairs.filter[!value.trim.empty].map[key])
+ val consistent = wsLinePairs.map[key].filter[!empty].forall[nonEmptyIndent | nonEmptyIndent.startsWith(textIndent)]
+
+ switch this {
+ case consistent: textIndent
+ case consistentOnly: null
+ default: minWSComputor.apply(wsLinePairs.map[key].filter[!empty]) // minimal non-empty white space
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConverter.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConverter.java
new file mode 100644
index 000000000..703a6a92d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConverter.java
@@ -0,0 +1,41 @@
+package org.eclipse.etrice.core.common.converter;
+
+import org.eclipse.xtext.conversion.ValueConverterException;
+import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
+import org.eclipse.xtext.nodemodel.INode;
+
+public class CC_StringConverter extends AbstractLexerBasedConverter<String> {
+
+ static public String DELIM = "'''";
+
+ static public String addDelim(final String text) {
+ if(CCStringIndentation.hasLineBreak(text)) {
+ final String lineEnding = CCStringIndentation.getLineEnding(text);
+ return DELIM + lineEnding + text + DELIM;
+ }
+ return DELIM + text + DELIM;
+ }
+
+ static public String stripDelim(String nodeText) {
+ if (nodeText.startsWith(DELIM) && nodeText.endsWith(DELIM)) {
+ return nodeText.substring(DELIM.length(), nodeText.length() - DELIM.length());
+ }
+
+ return nodeText;
+ }
+
+ @Override
+ protected String toEscapedString(String value) {
+ return addDelim(value);
+ }
+
+ public String toValue(String string, INode node) {
+ if (string == null)
+ return null;
+ try {
+ return new CCStringIndentation(stripDelim(string)).removeEditorWhiteSpace();
+ } catch (IllegalArgumentException e) {
+ throw new ValueConverterException(e.getMessage(), node, e);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConveter.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConveter.java
deleted file mode 100644
index a5ec9d311..000000000
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/converter/CC_StringConveter.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.eclipse.etrice.core.common.converter;
-
-
-import org.eclipse.etrice.core.common.util.CCStringIndentation;
-import org.eclipse.xtext.conversion.ValueConverterException;
-import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
-import org.eclipse.xtext.nodemodel.INode;
-
-public class CC_StringConveter extends AbstractLexerBasedConverter<String> {
-
- public final static String DELIM = "'''";
- final static String CRLF = "\r\n";
- final static String LF = "\n";
-
- @Override
- protected String toEscapedString(String value) {
- String lineEnding = getLineEnding(value);
- return DELIM + lineEnding + value + lineEnding + DELIM;
- }
-
- public String toValue(String string, INode node) {
- if (string == null)
- return null;
- try {
- return new CCStringIndentation(stripDelim(string)).removeIndentation();
- } catch (IllegalArgumentException e) {
- throw new ValueConverterException(e.getMessage(), node, e);
- }
- }
-
- static public String stripDelim(String ccstring) {
- if(ccstring.startsWith(DELIM) && ccstring.endsWith(DELIM))
- return ccstring.substring(DELIM.length(), ccstring.length() - DELIM.length());
-
- return ccstring;
- }
-
- static public String getLineEnding(String ccstring) {
- if (ccstring.indexOf(CRLF) >= 0)
- return CRLF;
- return LF;
- }
-}
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting/BaseFormatter.xtend b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting/BaseFormatter.xtend
deleted file mode 100644
index cfe69c5f7..000000000
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting/BaseFormatter.xtend
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 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:
- * Eyrak Paen (initial contribution)
- *
- *******************************************************************************/
-package org.eclipse.etrice.core.common.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.common.services.BaseGrammarAccess
-
-/**
- * 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 BaseFormatter extends AbstractDeclarativeFormatter {
-
-// @Inject extension BaseGrammarAccess
-
- 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.common/src/org/eclipse/etrice/core/common/formatting2/BaseFormatter.xtend b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting2/BaseFormatter.xtend
new file mode 100644
index 000000000..10708c01e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/formatting2/BaseFormatter.xtend
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.common.formatting2
+
+import com.google.inject.Inject
+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.services.BaseGrammarAccess
+import org.eclipse.xtext.formatting2.AbstractFormatter2
+import org.eclipse.xtext.formatting2.IFormattableDocument
+
+class BaseFormatter extends AbstractFormatter2 {
+
+ @Inject extension BaseGrammarAccess
+
+ /**
+ * recursive keyword formatting
+ */
+ protected def void formatAllByKeywords(EObject it, extension IFormattableDocument document) {
+ allRegionsFor.keywordPairs('{', '}').forEach[
+ key.prepend[oneSpace]
+ interior[indent]
+ value.prepend[newLine]
+ ]
+ allRegionsFor.keywordPairs('(', ')').forEach[interior[noSpace]]
+ allRegionsFor.keyword('(').prepend[noSpace lowPriority]
+
+ allRegionsFor.keywords(',').forEach[append[oneSpace]]
+ allRegionsFor.keywords('.').forEach[surround[noSpace]]
+
+ allRegionsFor.keywords(':').forEach[prepend[noSpace] append[oneSpace]]
+
+ // TIME
+ allRegionsFor.keywords(getTIMEAccess.getSKeyword_0_1, getTIMEAccess.msKeyword_1_1, getTIMEAccess.usKeyword_2_1, getTIMEAccess.nsKeyword_3_1).forEach[
+ if(previousHiddenRegion.length > 1) prepend[oneSpace] else prepend[noSpace]
+ append[oneSpace lowPriority]
+ ]
+ }
+
+ def dispatch void format(Documentation it, extension IFormattableDocument document) {
+ // TODO
+ }
+
+ def dispatch void format(Import it, extension IFormattableDocument document) {
+ regionFor.keywords(importAccess.importKeyword_0, importAccess.modelKeyword_1_1).forEach[append[oneSpace]]
+ regionFor.keyword(importAccess.fromKeyword_1_0_1).surround[oneSpace]
+ }
+
+ def dispatch void format(AnnotationType it, extension IFormattableDocument document) {
+ regionFor.keyword(annotationTypeAccess.annotationTypeKeyword_0).append[oneSpace]
+ regionFor.keyword(annotationTypeAccess.targetKeyword_4).prepend[newLine]
+ attributes.forEach[prepend[newLine]]
+ }
+
+ def dispatch void format(Annotation it, extension IFormattableDocument document) {
+ regionFor.keyword(annotationAccess.commercialAtKeyword_0).append[noSpace]
+ attributes.forEach[prepend[newLine]]
+ }
+
+}
+ \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/util/CCStringIndentation.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/util/CCStringIndentation.java
deleted file mode 100644
index 5c6d9893f..000000000
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/util/CCStringIndentation.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package org.eclipse.etrice.core.common.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.etrice.core.common.converter.CC_StringConveter;
-import org.eclipse.xtext.util.Strings;
-
-public class CCStringIndentation {
-
- private String ccString;
- private List<String> splittedLines;
- private boolean ignoreFirst;
- private boolean ignoreLast;
- private String lineEnding;
-
- public CCStringIndentation(String ccString){
- this.ccString = ccString;
- this.lineEnding = CC_StringConveter.getLineEnding(ccString); // use contents line ending
- this.splittedLines = Strings.split(ccString, lineEnding);
- this.ignoreFirst = splittedLines.size() > 1 && splittedLines.get(0).isEmpty();
- this.ignoreLast = splittedLines.size() > 1 && splittedLines.get(splittedLines.size() - 1).trim().isEmpty();
- }
-
- /**
- * Remove editor's indentation from DetailCodeString
- *
- * @see #highlight()
- */
- public String removeIndentation() {
- List<int[]> offsetLengthList = highlight();
-
- StringBuffer buffer = new StringBuffer(ccString.length());
- for (int[] offsetLength : offsetLengthList)
- buffer.append(ccString.substring(offsetLength[0], offsetLength[0] + offsetLength[1]));
-
- return buffer.toString();
- }
-
- /**
- * Returns highlighted positions without editor's indentation
- *
- * @see #removeIndentation()
- */
- public List<int[]> highlight() {
- List<int[]> offsetLengthLines = new ArrayList<int[]>();
- if (ccString == null || ccString.isEmpty())
- return offsetLengthLines;
-
- String minIndent = calcMinIndent(false);
-
- int offset = 0;
- int skip = minIndent.length();
- List<String> lines = splittedLines;
- for (int i = 0; i < lines.size(); i++) {
- String line = lines.get(i);
-
- if (i == 0 && ignoreFirst) {
- offset += line.length() + lineEnding.length();
- continue;
- }
-
- if (i == lines.size() - 1 && ignoreLast)
- continue;
-
- int[] pos;
- if (line.startsWith(minIndent))
- pos = new int[] { offset + skip, line.length() - skip };
- else
- pos = new int[] { offset, line.length() };
- if (i < lines.size() - 1)
- pos[1] += lineEnding.length();
-
- offset += line.length() + lineEnding.length();
- offsetLengthLines.add(pos);
- }
-
- return offsetLengthLines;
- }
-
- /**
- * Check consistent indentation
- */
- public boolean validateIndentation() {
-
- return calcMinIndent(true) != null;
- }
-
- /**
- * TODO
- */
- public String fixInconsistentIndentation() {
- //use jface TabsToSpacesConverter
- return null;
- }
-
-
-
- /**
- * Returns the least indentation, or maybe null if consistent is set
- */
- private String calcMinIndent(boolean consistent) {
- if(splittedLines.size() <= 1)
- return "";
- List<String> lines = splittedLines.subList(((ignoreFirst) ? 1 : 0), splittedLines.size() - ((ignoreLast) ? 1 : 0));
- if (lines.isEmpty())
- return "";
-
- ArrayList<String> wsLines = new ArrayList<String>(lines.size());
- for (String line : lines)
- wsLines.add(Strings.getLeadingWhiteSpace(line));
-
- final String baseIndent = wsLines.get(0);
- String commonIndent = baseIndent;
- for(String wsLine : wsLines){
- if(!wsLine.isEmpty())
- commonIndent = com.google.common.base.Strings.commonPrefix(commonIndent, wsLine);
- }
-
- if (!consistent)
- return commonIndent;
-
- int afterMinIndentIndex = baseIndent.length();
-
- // 1. check if every line contains the minIndent
- if(!baseIndent.equals(commonIndent))
- return null;
-
- // 2. check if there is still space between minIndent and first terminal
- boolean containsTerminal = false;
- for (int i = 0; i < lines.size(); i++)
- containsTerminal |= lines.get(i).length() > wsLines.get(i).length();
-
- if (containsTerminal) {
- boolean terminalAfterMinIndent = false;
- for (String line : lines)
- if (line.length() > afterMinIndentIndex)
- terminalAfterMinIndent |= !Character.isWhitespace(line.charAt(afterMinIndentIndex));
-
- if (!terminalAfterMinIndent)
- return null;
- }
-
- return baseIndent;
- }
-
-}
diff --git a/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/converter/CCStringIndentation.java b/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/converter/CCStringIndentation.java
new file mode 100644
index 000000000..2f771fd7f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/converter/CCStringIndentation.java
@@ -0,0 +1,403 @@
+/**
+ * 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.common.converter;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.xtend.lib.annotations.AccessorType;
+import org.eclipse.xtend.lib.annotations.Accessors;
+import org.eclipse.xtext.util.Strings;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.Functions.Function2;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Pair;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+import org.eclipse.xtext.xbase.lib.Pure;
+
+/**
+ * TODO: Handling mixed line endings
+ *
+ * Improvement: Too much strings matching => use token scanner
+ */
+@SuppressWarnings("all")
+public class CCStringIndentation {
+ private final static String JAVA_NL = Strings.newLine();
+
+ private final static String CRLF = "\r\n";
+
+ private final static String LF = "\n";
+
+ private final static String CR = "\r";
+
+ public static boolean hasLineBreak(final String nodeText) {
+ int _countLineBreaks = Strings.countLineBreaks(nodeText);
+ return (_countLineBreaks > 0);
+ }
+
+ public static String getLineEnding(final String it) {
+ String _switchResult = null;
+ boolean _matched = false;
+ int _indexOf = it.indexOf(CCStringIndentation.CRLF);
+ boolean _greaterEqualsThan = (_indexOf >= 0);
+ if (_greaterEqualsThan) {
+ _matched=true;
+ _switchResult = CCStringIndentation.CRLF;
+ }
+ if (!_matched) {
+ int _indexOf_1 = it.indexOf(CCStringIndentation.LF);
+ boolean _greaterEqualsThan_1 = (_indexOf_1 >= 0);
+ if (_greaterEqualsThan_1) {
+ _matched=true;
+ _switchResult = CCStringIndentation.LF;
+ }
+ }
+ if (!_matched) {
+ int _indexOf_2 = it.indexOf(CCStringIndentation.CR);
+ boolean _greaterEqualsThan_2 = (_indexOf_2 >= 0);
+ if (_greaterEqualsThan_2) {
+ _matched=true;
+ _switchResult = CCStringIndentation.CR;
+ }
+ }
+ if (!_matched) {
+ _switchResult = CCStringIndentation.JAVA_NL;
+ }
+ return _switchResult;
+ }
+
+ private final String ccString;
+
+ private final String lineEnding;
+
+ @Accessors(AccessorType.PUBLIC_GETTER)
+ private final ImmutableList<String> splittedLines;
+
+ @Accessors(AccessorType.PUBLIC_GETTER)
+ private final boolean ignoreFirst;
+
+ @Accessors(AccessorType.PUBLIC_GETTER)
+ private final boolean ignoreLast;
+
+ /**
+ * CCString without delimiters. Caller should handle their own delims.
+ */
+ public CCStringIndentation(final String ccString) {
+ this.ccString = ccString;
+ String _lineEnding = CCStringIndentation.getLineEnding(ccString);
+ this.lineEnding = _lineEnding;
+ ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList();
+ final Procedure1<ArrayList<String>> _function = (ArrayList<String> lines) -> {
+ Pattern _compile = Pattern.compile(this.lineEnding);
+ final Matcher matcher = _compile.matcher(ccString);
+ int lastOffset = 0;
+ while (matcher.find()) {
+ {
+ int _start = matcher.start();
+ String _substring = ccString.substring(lastOffset, _start);
+ lines.add(_substring);
+ int _end = matcher.end();
+ lastOffset = _end;
+ }
+ }
+ int _length = ccString.length();
+ boolean _lessThan = (lastOffset < _length);
+ if (_lessThan) {
+ String _substring = ccString.substring(lastOffset);
+ lines.add(_substring);
+ } else {
+ boolean _endsWith = ccString.endsWith(this.lineEnding);
+ if (_endsWith) {
+ lines.add("");
+ }
+ }
+ };
+ ArrayList<String> _doubleArrow = ObjectExtensions.<ArrayList<String>>operator_doubleArrow(_newArrayList, _function);
+ ImmutableList<String> _copyOf = ImmutableList.<String>copyOf(_doubleArrow);
+ this.splittedLines = _copyOf;
+ this.ignoreFirst = ((this.splittedLines.size() >= 2) && IterableExtensions.<String>head(this.splittedLines).trim().isEmpty());
+ this.ignoreLast = ((this.splittedLines.size() >= 2) && IterableExtensions.<String>last(this.splittedLines).trim().isEmpty());
+ }
+
+ /**
+ * Returns ccString without editor white space and delims.
+ *
+ * @see #highlight()
+ */
+ public String removeEditorWhiteSpace() {
+ return this.removeEditorWhiteSpace("");
+ }
+
+ protected String removeEditorWhiteSpace(final String indent) {
+ List<Pair<Integer, Integer>> _highlight = this.highlight();
+ final Function2<String, Pair<Integer, Integer>, String> _function = (String lines, Pair<Integer, Integer> offsetLength) -> {
+ Integer _key = offsetLength.getKey();
+ Integer _key_1 = offsetLength.getKey();
+ Integer _value = offsetLength.getValue();
+ int _plus = ((_key_1).intValue() + (_value).intValue());
+ String _substring = this.ccString.substring((_key).intValue(), _plus);
+ return ((lines + indent) + _substring);
+ };
+ return IterableExtensions.<Pair<Integer, Integer>, String>fold(_highlight, "", _function);
+ }
+
+ /**
+ * Returns whether editor indentation can be removed safely.
+ */
+ public boolean canRemoveEditorIndentation() {
+ return (((this.splittedLines.size() >= 2) && this.ignoreFirst) && this.hasConsistentIndentation());
+ }
+
+ /**
+ * Returns ccString replaced with given indentation if possible. Ignored lines are trimmed. No delims included.
+ *
+ * @see #highlight()
+ */
+ public String replaceEditorIndentation(final String indentation) {
+ String _xblockexpression = null;
+ {
+ String _xifexpression = null;
+ if ((indentation == null)) {
+ _xifexpression = "";
+ } else {
+ _xifexpression = indentation;
+ }
+ final String indent = _xifexpression;
+ String _xifexpression_1 = null;
+ boolean _canRemoveEditorIndentation = this.canRemoveEditorIndentation();
+ if (_canRemoveEditorIndentation) {
+ String _xifexpression_2 = null;
+ if ((this.ignoreFirst && (this.splittedLines.size() == 2))) {
+ _xifexpression_2 = this.removeEditorWhiteSpace("");
+ } else {
+ String _xifexpression_3 = null;
+ if (this.ignoreFirst) {
+ _xifexpression_3 = this.lineEnding;
+ } else {
+ _xifexpression_3 = "";
+ }
+ String _removeEditorWhiteSpace = this.removeEditorWhiteSpace(indent);
+ _xifexpression_2 = (_xifexpression_3 + _removeEditorWhiteSpace);
+ }
+ _xifexpression_1 = _xifexpression_2;
+ } else {
+ String _xblockexpression_1 = null;
+ {
+ LinkedList<String> _newLinkedList = CollectionLiterals.<String>newLinkedList(((String[])Conversions.unwrapArray(this.splittedLines, String.class)));
+ final Procedure1<LinkedList<String>> _function = (LinkedList<String> it) -> {
+ if (this.ignoreFirst) {
+ it.set(0, "");
+ }
+ if (this.ignoreLast) {
+ int _size = it.size();
+ int _minus = (_size - 1);
+ it.set(_minus, "");
+ }
+ };
+ final LinkedList<String> lines = ObjectExtensions.<LinkedList<String>>operator_doubleArrow(_newLinkedList, _function);
+ _xblockexpression_1 = IterableExtensions.join(lines, this.lineEnding);
+ }
+ _xifexpression_1 = _xblockexpression_1;
+ }
+ _xblockexpression = _xifexpression_1;
+ }
+ return _xblockexpression;
+ }
+
+ /**
+ * Returns highlighted positions without editor's indentation.<br>
+ * Positions are pairs of (offset, length) relative to {@link #CCStringIndentation(String)}
+ *
+ * @see #removeEditorWhiteSpace()
+ */
+ public List<Pair<Integer, Integer>> highlight() {
+ final ArrayList<Pair<Integer, Integer>> offsetLengthLines = CollectionLiterals.<Pair<Integer, Integer>>newArrayList();
+ final String editorIndent = this.computeEditorIndent(false);
+ final int skip = editorIndent.length();
+ int offset = 0;
+ for (int i = 0; (i < ((Object[])Conversions.unwrapArray(this.splittedLines, Object.class)).length); i++) {
+ {
+ final String line = this.splittedLines.get(i);
+ if (((i == 0) && this.ignoreFirst)) {
+ int _offset = offset;
+ int _length = line.length();
+ int _length_1 = this.lineEnding.length();
+ int _plus = (_length + _length_1);
+ offset = (_offset + _plus);
+ } else {
+ if (((i == (this.splittedLines.size() - 1)) && this.ignoreLast)) {
+ } else {
+ Pair<Integer, Integer> _xblockexpression = null;
+ {
+ int _xifexpression = (int) 0;
+ int _size = this.splittedLines.size();
+ int _minus = (_size - 1);
+ boolean _lessThan = (i < _minus);
+ if (_lessThan) {
+ _xifexpression = this.lineEnding.length();
+ } else {
+ _xifexpression = 0;
+ }
+ final int NL = _xifexpression;
+ Pair<Integer, Integer> _xifexpression_1 = null;
+ boolean _startsWith = line.startsWith(editorIndent);
+ if (_startsWith) {
+ int _length_2 = line.length();
+ int _minus_1 = (_length_2 - skip);
+ int _plus_1 = (_minus_1 + NL);
+ _xifexpression_1 = Pair.<Integer, Integer>of(Integer.valueOf((offset + skip)), Integer.valueOf(_plus_1));
+ } else {
+ int _length_3 = line.length();
+ int _plus_2 = (_length_3 + NL);
+ _xifexpression_1 = Pair.<Integer, Integer>of(Integer.valueOf(offset), Integer.valueOf(_plus_2));
+ }
+ _xblockexpression = _xifexpression_1;
+ }
+ offsetLengthLines.add(_xblockexpression);
+ int _offset_1 = offset;
+ int _length_2 = line.length();
+ int _length_3 = this.lineEnding.length();
+ int _plus_1 = (_length_2 + _length_3);
+ offset = (_offset_1 + _plus_1);
+ }
+ }
+ }
+ }
+ return offsetLengthLines;
+ }
+
+ /**
+ * Check consistent indentation
+ */
+ public boolean hasConsistentIndentation() {
+ String _computeEditorIndent = this.computeEditorIndent(true);
+ return (_computeEditorIndent != null);
+ }
+
+ protected String computeEditorIndent(final boolean consistentOnly) {
+ String _xblockexpression = null;
+ {
+ if (((this.splittedLines.size() <= 1) || (!this.ignoreFirst))) {
+ return "";
+ }
+ List<Pair<String, String>> _xblockexpression_1 = null;
+ {
+ int _xifexpression = (int) 0;
+ if (this.ignoreFirst) {
+ _xifexpression = 1;
+ } else {
+ _xifexpression = 0;
+ }
+ final int begin = _xifexpression;
+ int _size = this.splittedLines.size();
+ int _xifexpression_1 = (int) 0;
+ if (this.ignoreLast) {
+ _xifexpression_1 = 1;
+ } else {
+ _xifexpression_1 = 0;
+ }
+ final int end = (_size - _xifexpression_1);
+ ImmutableList<String> _subList = this.splittedLines.subList(begin, end);
+ final Function1<String, Pair<String, String>> _function = (String line) -> {
+ String _leadingWhiteSpace = Strings.getLeadingWhiteSpace(line);
+ return Pair.<String, String>of(_leadingWhiteSpace, line);
+ };
+ List<Pair<String, String>> _map = ListExtensions.<String, Pair<String, String>>map(_subList, _function);
+ _xblockexpression_1 = IterableExtensions.<Pair<String, String>>toList(_map);
+ }
+ final List<Pair<String, String>> wsLinePairs = _xblockexpression_1;
+ final Function1<Iterable<String>, String> _function = (Iterable<String> it) -> {
+ String _xifexpression = null;
+ boolean _isEmpty = IterableExtensions.isEmpty(it);
+ if (_isEmpty) {
+ _xifexpression = "";
+ } else {
+ _xifexpression = IterableExtensions.<String>min(it);
+ }
+ return _xifexpression;
+ };
+ final Function1<? super Iterable<String>, ? extends String> minWSComputor = _function;
+ final Function1<Pair<String, String>, Boolean> _function_1 = (Pair<String, String> it) -> {
+ String _value = it.getValue();
+ String _trim = _value.trim();
+ boolean _isEmpty = _trim.isEmpty();
+ return Boolean.valueOf((!_isEmpty));
+ };
+ Iterable<Pair<String, String>> _filter = IterableExtensions.<Pair<String, String>>filter(wsLinePairs, _function_1);
+ final Function1<Pair<String, String>, String> _function_2 = (Pair<String, String> it) -> {
+ return it.getKey();
+ };
+ Iterable<String> _map = IterableExtensions.<Pair<String, String>, String>map(_filter, _function_2);
+ final String textIndent = minWSComputor.apply(_map);
+ final Function1<Pair<String, String>, String> _function_3 = (Pair<String, String> it) -> {
+ return it.getKey();
+ };
+ List<String> _map_1 = ListExtensions.<Pair<String, String>, String>map(wsLinePairs, _function_3);
+ final Function1<String, Boolean> _function_4 = (String it) -> {
+ boolean _isEmpty = it.isEmpty();
+ return Boolean.valueOf((!_isEmpty));
+ };
+ Iterable<String> _filter_1 = IterableExtensions.<String>filter(_map_1, _function_4);
+ final Function1<String, Boolean> _function_5 = (String nonEmptyIndent) -> {
+ return Boolean.valueOf(nonEmptyIndent.startsWith(textIndent));
+ };
+ final boolean consistent = IterableExtensions.<String>forall(_filter_1, _function_5);
+ String _switchResult = null;
+ boolean _matched = false;
+ if (consistent) {
+ _matched=true;
+ _switchResult = textIndent;
+ }
+ if (!_matched) {
+ if (consistentOnly) {
+ _matched=true;
+ _switchResult = null;
+ }
+ }
+ if (!_matched) {
+ final Function1<Pair<String, String>, String> _function_6 = (Pair<String, String> it) -> {
+ return it.getKey();
+ };
+ List<String> _map_2 = ListExtensions.<Pair<String, String>, String>map(wsLinePairs, _function_6);
+ final Function1<String, Boolean> _function_7 = (String it) -> {
+ boolean _isEmpty = it.isEmpty();
+ return Boolean.valueOf((!_isEmpty));
+ };
+ Iterable<String> _filter_2 = IterableExtensions.<String>filter(_map_2, _function_7);
+ _switchResult = minWSComputor.apply(_filter_2);
+ }
+ _xblockexpression = _switchResult;
+ }
+ return _xblockexpression;
+ }
+
+ @Pure
+ public ImmutableList<String> getSplittedLines() {
+ return this.splittedLines;
+ }
+
+ @Pure
+ public boolean isIgnoreFirst() {
+ return this.ignoreFirst;
+ }
+
+ @Pure
+ public boolean isIgnoreLast() {
+ return this.ignoreLast;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting/BaseFormatter.java b/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting/BaseFormatter.java
deleted file mode 100644
index bdccb7880..000000000
--- a/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting/BaseFormatter.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright (c) 2013 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:
- * Eyrak Paen (initial contribution)
- */
-package org.eclipse.etrice.core.common.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 BaseFormatter extends AbstractDeclarativeFormatter {
- @Override
- protected void configureFormatting(final FormattingConfig c) {
- }
-}
diff --git a/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting2/BaseFormatter.java b/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting2/BaseFormatter.java
new file mode 100644
index 000000000..1294b1e2e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common/xtend-gen/org/eclipse/etrice/core/common/formatting2/BaseFormatter.java
@@ -0,0 +1,251 @@
+/**
+ * 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.common.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.AnnotationAttribute;
+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.base.KeyValue;
+import org.eclipse.etrice.core.common.services.BaseGrammarAccess;
+import org.eclipse.xtext.Keyword;
+import org.eclipse.xtext.formatting2.AbstractFormatter2;
+import org.eclipse.xtext.formatting2.IFormattableDocument;
+import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
+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.resource.XtextResource;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Pair;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@SuppressWarnings("all")
+public class BaseFormatter extends AbstractFormatter2 {
+ @Inject
+ @Extension
+ private BaseGrammarAccess _baseGrammarAccess;
+
+ /**
+ * recursive keyword formatting
+ */
+ protected void formatAllByKeywords(final EObject it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _allRegionsFor = this.textRegionExtensions.allRegionsFor(it);
+ List<Pair<ISemanticRegion, ISemanticRegion>> _keywordPairs = _allRegionsFor.keywordPairs("{", "}");
+ final Consumer<Pair<ISemanticRegion, ISemanticRegion>> _function = (Pair<ISemanticRegion, ISemanticRegion> it_1) -> {
+ ISemanticRegion _key = it_1.getKey();
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.prepend(_key, _function_1);
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
+ it_2.indent();
+ };
+ document.<ISemanticRegion, ISemanticRegion>interior(it_1, _function_2);
+ ISemanticRegion _value = it_1.getValue();
+ final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_2) -> {
+ it_2.newLine();
+ };
+ document.prepend(_value, _function_3);
+ };
+ _keywordPairs.forEach(_function);
+ ISemanticRegionsFinder _allRegionsFor_1 = this.textRegionExtensions.allRegionsFor(it);
+ List<Pair<ISemanticRegion, ISemanticRegion>> _keywordPairs_1 = _allRegionsFor_1.keywordPairs("(", ")");
+ final Consumer<Pair<ISemanticRegion, ISemanticRegion>> _function_1 = (Pair<ISemanticRegion, ISemanticRegion> it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.<ISemanticRegion, ISemanticRegion>interior(it_1, _function_2);
+ };
+ _keywordPairs_1.forEach(_function_1);
+ ISemanticRegionsFinder _allRegionsFor_2 = this.textRegionExtensions.allRegionsFor(it);
+ ISemanticRegion _keyword = _allRegionsFor_2.keyword("(");
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
+ it_1.noSpace();
+ it_1.lowPriority();
+ };
+ document.prepend(_keyword, _function_2);
+ ISemanticRegionsFinder _allRegionsFor_3 = this.textRegionExtensions.allRegionsFor(it);
+ List<ISemanticRegion> _keywords = _allRegionsFor_3.keywords(",");
+ final Consumer<ISemanticRegion> _function_3 = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_4);
+ };
+ _keywords.forEach(_function_3);
+ ISemanticRegionsFinder _allRegionsFor_4 = this.textRegionExtensions.allRegionsFor(it);
+ List<ISemanticRegion> _keywords_1 = _allRegionsFor_4.keywords(".");
+ final Consumer<ISemanticRegion> _function_4 = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_5 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.surround(it_1, _function_5);
+ };
+ _keywords_1.forEach(_function_4);
+ ISemanticRegionsFinder _allRegionsFor_5 = this.textRegionExtensions.allRegionsFor(it);
+ List<ISemanticRegion> _keywords_2 = _allRegionsFor_5.keywords(":");
+ final Consumer<ISemanticRegion> _function_5 = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_6 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.prepend(it_1, _function_6);
+ final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_7);
+ };
+ _keywords_2.forEach(_function_5);
+ ISemanticRegionsFinder _allRegionsFor_6 = this.textRegionExtensions.allRegionsFor(it);
+ BaseGrammarAccess.TIMEElements _tIMEAccess = this._baseGrammarAccess.getTIMEAccess();
+ Keyword _sKeyword_0_1 = _tIMEAccess.getSKeyword_0_1();
+ BaseGrammarAccess.TIMEElements _tIMEAccess_1 = this._baseGrammarAccess.getTIMEAccess();
+ Keyword _msKeyword_1_1 = _tIMEAccess_1.getMsKeyword_1_1();
+ BaseGrammarAccess.TIMEElements _tIMEAccess_2 = this._baseGrammarAccess.getTIMEAccess();
+ Keyword _usKeyword_2_1 = _tIMEAccess_2.getUsKeyword_2_1();
+ BaseGrammarAccess.TIMEElements _tIMEAccess_3 = this._baseGrammarAccess.getTIMEAccess();
+ Keyword _nsKeyword_3_1 = _tIMEAccess_3.getNsKeyword_3_1();
+ List<ISemanticRegion> _keywords_3 = _allRegionsFor_6.keywords(_sKeyword_0_1, _msKeyword_1_1, _usKeyword_2_1, _nsKeyword_3_1);
+ final Consumer<ISemanticRegion> _function_6 = (ISemanticRegion it_1) -> {
+ IHiddenRegion _previousHiddenRegion = it_1.getPreviousHiddenRegion();
+ int _length = _previousHiddenRegion.getLength();
+ boolean _greaterThan = (_length > 1);
+ if (_greaterThan) {
+ final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.prepend(it_1, _function_7);
+ } else {
+ final Procedure1<IHiddenRegionFormatter> _function_8 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.prepend(it_1, _function_8);
+ }
+ final Procedure1<IHiddenRegionFormatter> _function_9 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ it_2.lowPriority();
+ };
+ document.append(it_1, _function_9);
+ };
+ _keywords_3.forEach(_function_6);
+ }
+
+ protected void _format(final Documentation it, @Extension final IFormattableDocument document) {
+ }
+
+ protected void _format(final Import it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ BaseGrammarAccess.ImportElements _importAccess = this._baseGrammarAccess.getImportAccess();
+ Keyword _importKeyword_0 = _importAccess.getImportKeyword_0();
+ BaseGrammarAccess.ImportElements _importAccess_1 = this._baseGrammarAccess.getImportAccess();
+ Keyword _modelKeyword_1_1 = _importAccess_1.getModelKeyword_1_1();
+ List<ISemanticRegion> _keywords = _regionFor.keywords(_importKeyword_0, _modelKeyword_1_1);
+ final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_1);
+ };
+ _keywords.forEach(_function);
+ ISemanticRegionsFinder _regionFor_1 = this.textRegionExtensions.regionFor(it);
+ BaseGrammarAccess.ImportElements _importAccess_2 = this._baseGrammarAccess.getImportAccess();
+ Keyword _fromKeyword_1_0_1 = _importAccess_2.getFromKeyword_1_0_1();
+ ISemanticRegion _keyword = _regionFor_1.keyword(_fromKeyword_1_0_1);
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
+ it_1.oneSpace();
+ };
+ document.surround(_keyword, _function_1);
+ }
+
+ protected void _format(final AnnotationType it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ BaseGrammarAccess.AnnotationTypeElements _annotationTypeAccess = this._baseGrammarAccess.getAnnotationTypeAccess();
+ Keyword _annotationTypeKeyword_0 = _annotationTypeAccess.getAnnotationTypeKeyword_0();
+ ISemanticRegion _keyword = _regionFor.keyword(_annotationTypeKeyword_0);
+ final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
+ it_1.oneSpace();
+ };
+ document.append(_keyword, _function);
+ ISemanticRegionsFinder _regionFor_1 = this.textRegionExtensions.regionFor(it);
+ BaseGrammarAccess.AnnotationTypeElements _annotationTypeAccess_1 = this._baseGrammarAccess.getAnnotationTypeAccess();
+ Keyword _targetKeyword_4 = _annotationTypeAccess_1.getTargetKeyword_4();
+ ISemanticRegion _keyword_1 = _regionFor_1.keyword(_targetKeyword_4);
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
+ it_1.newLine();
+ };
+ document.prepend(_keyword_1, _function_1);
+ EList<AnnotationAttribute> _attributes = it.getAttributes();
+ final Consumer<AnnotationAttribute> _function_2 = (AnnotationAttribute it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_2) -> {
+ it_2.newLine();
+ };
+ document.<AnnotationAttribute>prepend(it_1, _function_3);
+ };
+ _attributes.forEach(_function_2);
+ }
+
+ protected void _format(final Annotation it, @Extension final IFormattableDocument document) {
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ BaseGrammarAccess.AnnotationElements _annotationAccess = this._baseGrammarAccess.getAnnotationAccess();
+ Keyword _commercialAtKeyword_0 = _annotationAccess.getCommercialAtKeyword_0();
+ ISemanticRegion _keyword = _regionFor.keyword(_commercialAtKeyword_0);
+ final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
+ it_1.noSpace();
+ };
+ document.append(_keyword, _function);
+ EList<KeyValue> _attributes = it.getAttributes();
+ final Consumer<KeyValue> _function_1 = (KeyValue it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
+ it_2.newLine();
+ };
+ document.<KeyValue>prepend(it_1, _function_2);
+ };
+ _attributes.forEach(_function_1);
+ }
+
+ public void format(final Object it, final IFormattableDocument document) {
+ if (it instanceof XtextResource) {
+ _format((XtextResource)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 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());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.fsm.ui/icons/correction_change.gif b/plugins/org.eclipse.etrice.core.fsm.ui/icons/correction_change.gif
new file mode 100644
index 000000000..068e18d0f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.fsm.ui/icons/correction_change.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.core.fsm.ui/src-gen/org/eclipse/etrice/core/fsm/ui/AbstractFSMUiModule.java b/plugins/org.eclipse.etrice.core.fsm.ui/src-gen/org/eclipse/etrice/core/fsm/ui/AbstractFSMUiModule.java
index 45a1dc342..b335a747f 100644
--- a/plugins/org.eclipse.etrice.core.fsm.ui/src-gen/org/eclipse/etrice/core/fsm/ui/AbstractFSMUiModule.java
+++ b/plugins/org.eclipse.etrice.core.fsm.ui/src-gen/org/eclipse/etrice/core/fsm/ui/AbstractFSMUiModule.java
@@ -87,6 +87,11 @@ public abstract class AbstractFSMUiModule extends org.eclipse.xtext.ui.DefaultUi
binder.bind(org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreInitializer.class).annotatedWith(com.google.inject.name.Names.named("builderPreferenceInitializer")).to(org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.Initializer.class);
}
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public Class<? extends org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory> bindIContentFormatterFactory() {
+ return org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory.class;
+ }
+
// contributed by org.eclipse.xtext.ui.generator.labeling.LabelProviderFragment
public Class<? extends org.eclipse.jface.viewers.ILabelProvider> bindILabelProvider() {
return org.eclipse.etrice.core.fsm.ui.labeling.FSMLabelProvider.class;
diff --git a/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/contentassist/FSMProposalProvider.xtend b/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/contentassist/FSMProposalProvider.xtend
index 95b8cf3b5..1618ad318 100644
--- a/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/contentassist/FSMProposalProvider.xtend
+++ b/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/contentassist/FSMProposalProvider.xtend
@@ -3,10 +3,9 @@
*/
package org.eclipse.etrice.core.fsm.ui.contentassist
-import org.eclipse.etrice.core.fsm.ui.contentassist.AbstractFSMProposalProvider
-
/**
* see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to customize content assistant
*/
class FSMProposalProvider extends AbstractFSMProposalProvider {
+
}
diff --git a/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.xtend b/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.xtend
index c0c20db71..d3dd95d00 100644
--- a/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.xtend
+++ b/plugins/org.eclipse.etrice.core.fsm.ui/src/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.xtend
@@ -4,7 +4,7 @@
package org.eclipse.etrice.core.fsm.ui.quickfix
import com.google.inject.Inject
-import org.eclipse.etrice.core.common.converter.CC_StringConveter
+import org.eclipse.etrice.core.common.converter.CC_StringConverter
import org.eclipse.etrice.core.fsm.fSM.DetailCode
import org.eclipse.etrice.core.fsm.validation.FSMJavaValidator
import org.eclipse.xtext.formatting.IWhitespaceInformationProvider
@@ -37,7 +37,7 @@ class FSMQuickfixProvider extends DefaultQuickfixProvider {
// workaround
NodeModelUtils.findActualNodeFor(dc) => [
- context.xtextDocument.replace(offset, length, CC_StringConveter.DELIM + ccString + CC_StringConveter.DELIM)
+ context.xtextDocument.replace(offset, length, CC_StringConverter.addDelim(ccString))
]
])
}
diff --git a/plugins/org.eclipse.etrice.core.fsm.ui/xtend-gen/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.java b/plugins/org.eclipse.etrice.core.fsm.ui/xtend-gen/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.java
index 3b19fd792..d00af4618 100644
--- a/plugins/org.eclipse.etrice.core.fsm.ui/xtend-gen/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.java
+++ b/plugins/org.eclipse.etrice.core.fsm.ui/xtend-gen/org/eclipse/etrice/core/fsm/ui/quickfix/FSMQuickfixProvider.java
@@ -8,7 +8,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.etrice.core.common.converter.CC_StringConveter;
+import org.eclipse.etrice.core.common.converter.CC_StringConverter;
import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.fsm.validation.FSMJavaValidator;
import org.eclipse.xtext.formatting.ILineSeparatorInformation;
@@ -53,7 +53,8 @@ public class FSMQuickfixProvider extends DefaultQuickfixProvider {
IXtextDocument _xtextDocument = context.getXtextDocument();
int _offset = it.getOffset();
int _length = it.getLength();
- _xtextDocument.replace(_offset, _length, ((CC_StringConveter.DELIM + ccString) + CC_StringConveter.DELIM));
+ String _addDelim = CC_StringConverter.addDelim(ccString);
+ _xtextDocument.replace(_offset, _length, _addDelim);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
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());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/icons/correction_change.gif b/plugins/org.eclipse.etrice.core.room.ui/icons/correction_change.gif
new file mode 100644
index 000000000..068e18d0f
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/icons/correction_change.gif
Binary files differ
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src-gen/org/eclipse/etrice/core/ui/AbstractRoomUiModule.java b/plugins/org.eclipse.etrice.core.room.ui/src-gen/org/eclipse/etrice/core/ui/AbstractRoomUiModule.java
index 793766d3e..df718a6f7 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src-gen/org/eclipse/etrice/core/ui/AbstractRoomUiModule.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src-gen/org/eclipse/etrice/core/ui/AbstractRoomUiModule.java
@@ -72,6 +72,11 @@ public abstract class AbstractRoomUiModule extends org.eclipse.xtext.ui.DefaultU
return org.eclipse.xtext.builder.impl.PersistentDataAwareDirtyResource.class;
}
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public Class<? extends org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory> bindIContentFormatterFactory() {
+ return org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory.class;
+ }
+
// contributed by org.eclipse.xtext.ui.generator.labeling.LabelProviderFragment
public Class<? extends org.eclipse.jface.viewers.ILabelProvider> bindILabelProvider() {
return org.eclipse.etrice.core.ui.labeling.RoomLabelProvider.class;
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java
index df2230a4d..38348bd93 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiModule.java
@@ -13,8 +13,8 @@
package org.eclipse.etrice.core.ui;
import org.eclipse.etrice.core.common.ui.autoedit.BaseAutoEditStrategyProvider;
+import org.eclipse.etrice.core.common.ui.editor.model.BaseTokenTypeToPartitionMapper;
import org.eclipse.etrice.core.common.ui.hover.IKeywordHoverContentProvider;
-import org.eclipse.etrice.core.common.ui.hover.KeywordEObjectTextHover;
import org.eclipse.etrice.core.common.ui.hover.KeywordHoverProvider;
import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.core.ui.highlight.RoomHighlightingConfiguration;
@@ -30,6 +30,7 @@ import org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategyProvider;
import org.eclipse.xtext.ui.editor.hover.IEObjectHover;
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper;
+import org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
@@ -91,4 +92,24 @@ public class RoomUiModule extends org.eclipse.etrice.core.ui.AbstractRoomUiModul
public Class<? extends AbstractEditStrategyProvider> bindAbstractEditStrategyProvider() {
return BaseAutoEditStrategyProvider.class;
}
+
+ public Class<? extends ITokenTypeToPartitionTypeMapper> bindITokenTypeToPartitionTypeMapper(){
+ return BaseTokenTypeToPartitionMapper.class;
+ }
+
+ /*
+ // auto format for quick fix
+ public Class<? extends ITextEditComposer> bindITextEditComposer() {
+ return AutoFormatTextEditComposer.class;
+ }
+
+ public static class AutoFormatTextEditComposer extends DefaultTextEditComposer {
+
+ @Override
+ protected SaveOptions getSaveOptions() {
+ return SaveOptions.newBuilder().format().getOptions();
+ }
+
+ }
+ */
}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/handler/DetailCodePasteHandler.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/handler/DetailCodePasteHandler.java
deleted file mode 100644
index 19fda0acd..000000000
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/handler/DetailCodePasteHandler.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.eclipse.etrice.core.ui.handler;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-
-public class DetailCodePasteHandler extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml b/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml
index 7812a7309..ea3fb4d7a 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml
+++ b/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml
@@ -43,10 +43,6 @@ id="protocol_class" name="ProtocolClass">${xx: Enum('CommunicationType')} Proto
deleted="false" description="data class skeleton" enabled="true"
id="data_class" name="DataClass">DataClass ${DataClassName} {&#13;
Attribute ${Attr1}: ${atype:CrossReference('Attribute.type')}
- Operation ${Operation1}(${par}: ${type}): ${rtype} {&#13;
- "${UserCodeLine1}"&#13;
- "${UserCodeLine2}"&#13;
- }&#13;
${cursor}
}</template>
@@ -67,10 +63,9 @@ ${cursor}</template>
<template autoinsert="true" context="org.eclipse.etrice.core.Room.kw_Operation"
deleted="false" description="operation skeleton" enabled="true"
- id="operation" name="Operation">Operation ${name}(${param}: ${paramtype}): ${rtype} {&#13;
- "${UserCodeLine1}"&#13;
- "${UserCodeLine2}"&#13;
-}&#13;
+ id="operation" name="Operation">Operation ${name}(${param}: ${paramtype}): ${rtype} '''&#13;
+ ${cursor}
+'''&#13;
${cursor}</template>
<template autoinsert="true" context="org.eclipse.etrice.core.fsm.FSM.kw_State"
@@ -89,9 +84,9 @@ ${cursor}</template>
<template autoinsert="true" context="org.eclipse.etrice.core.fsm.FSM.DetailCode"
deleted="false" description="detail code" enabled="true" id="detail_code"
- name="detail code">{&#13;
- "${cursor}"&#13;
-}</template>
+ name="detail code"> '''&#13;
+ ${text}${cursor}&#13;
+'''&#13;</template>
<template autoinsert="true" context="org.eclipse.etrice.core.Room.kw_Port"
deleted="false" description="insert port" enabled="true" id="port"
diff --git a/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/AbstractRoomRuntimeModule.java b/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/AbstractRoomRuntimeModule.java
index 34e0cd3b4..6d84646be 100644
--- a/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/AbstractRoomRuntimeModule.java
+++ b/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/AbstractRoomRuntimeModule.java
@@ -148,9 +148,14 @@ public abstract class AbstractRoomRuntimeModule extends org.eclipse.xtext.servic
binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions.class);
}
- // contributed by org.eclipse.xtext.generator.formatting.FormatterFragment
- public Class<? extends org.eclipse.xtext.formatting.IFormatter> bindIFormatter() {
- return org.eclipse.etrice.core.formatting.RoomFormatter.class;
+ // contributed by org.eclipse.xtext.generator.formatting2.Formatter2Fragment
+ public Class<? extends org.eclipse.xtext.formatting2.IFormatter2> bindIFormatter2() {
+ return org.eclipse.etrice.core.formatting2.RoomFormatter.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.room/src-gen/org/eclipse/etrice/core/services/RoomGrammarAccess.java b/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/services/RoomGrammarAccess.java
index 0f3966c8e..cef8cbf58 100644
--- a/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/services/RoomGrammarAccess.java
+++ b/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/services/RoomGrammarAccess.java
@@ -4615,8 +4615,8 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//// **************************************************************
- //// AnnotationType and Annotation Rules
- //Annotation:
+ // // AnnotationType and Annotation Rules
+ // Annotation:
// '@' type=[AnnotationType|FQN] ('(' attributes+=KeyValue (',' attributes+=KeyValue)* ')')?;
public BaseGrammarAccess.AnnotationElements getAnnotationAccess() {
return gaBase.getAnnotationAccess();
@@ -4637,10 +4637,9 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//AnnotationType:
- // 'AnnotationType' name=ID docu=Documentation? '{'
- // 'target' '=' (targets+=super::AnnotationTargetType | '{' targets+=super::AnnotationTargetType (','
- // targets+=super::AnnotationTargetType)* '}') attributes+=AnnotationAttribute*
- // '}';
+ // 'AnnotationType' name=ID docu=Documentation? '{' 'target' '=' (targets+=super::AnnotationTargetType | '{'
+ // targets+=super::AnnotationTargetType (',' targets+=super::AnnotationTargetType)* '}')
+ // attributes+=AnnotationAttribute* '}';
public BaseGrammarAccess.AnnotationTypeElements getAnnotationTypeAccess() {
return gaBase.getAnnotationTypeAccess();
}
@@ -4680,26 +4679,37 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//// **************************************************************
- //// Import rules
+ // // Import rules
+ //
//// HOWTO: use a combination of URI global scopes and namespace aware local scope provider
+ //
//// this is configured in the work flow by
- //// fragment = scoping.ImportURIScopingFragment {}
+ // // fragment = scoping.ImportURIScopingFragment {}
+ //
//// and by overriding configureIScopeProviderDelegate in the runtime module with
+ //
//// ImportedNamespaceAwareLocalScopeProvider
- //// also configure in the RuntimeModule
+ // // also configure in the RuntimeModule
+ //
//// public Class<? extends ImportUriResolver> bindImportUriResolver() {
- //// return PlatformRelativeUriResolver.class;
+ // // return PlatformRelativeUriResolver.class;
+ //
//// }
- //// and in the UiRuntimeModule
+ // // and in the UiRuntimeModule
+ //
//// public Class<? extends org.eclipse.xtext.ui.editor.IURIEditorOpener> bindIURIEditorOpener() {
+ //
//// return GlobalNonPlatformURIEditorOpener.class;
- //// }
+ // // }
+ //
//// public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() {
- //// return ImportAwareHyperlinkHelper.class;
+ // // return ImportAwareHyperlinkHelper.class;
+ //
//// }
- //// the attribute 'importedNamespace' is picked up by the ImportedNamespaceAwareLocalScopeProvider
+ // // the attribute 'importedNamespace' is picked up by the ImportedNamespaceAwareLocalScopeProvider
+ //
//// the attribute 'importURI' is picked up by the ImportUriGlobalScopeProvider
- //Import:
+ // Import:
// 'import' (importedNamespace=ImportedFQN 'from' | 'model') importURI=STRING;
public BaseGrammarAccess.ImportElements getImportAccess() {
return gaBase.getImportAccess();
@@ -4720,12 +4730,9 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//// **************************************************************
- //// Documentation Rule
- //Documentation:
- // {Documentation}
- // '['
- // lines+=STRING*
- // ']';
+ // // Documentation Rule
+ // Documentation:
+ // {Documentation} '[' lines+=STRING* ']';
public BaseGrammarAccess.DocumentationElements getDocumentationAccess() {
return gaBase.getDocumentationAccess();
}
@@ -4735,8 +4742,8 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//// **************************************************************
- //// Time Rule
- //TIME ecore::ELong:
+ // // Time Rule
+ // TIME ecore::ELong:
// INT 's' | INT 'ms' | INT 'us' | INT 'ns'
public BaseGrammarAccess.TIMEElements getTIMEAccess() {
return gaBase.getTIMEAccess();
@@ -4747,10 +4754,7 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//enum LiteralType:
- // BOOL='ptBoolean' |
- // INT='ptInteger' |
- // REAL='ptReal' |
- // CHAR='ptCharacter';
+ // BOOL='ptBoolean' | INT='ptInteger' | REAL='ptReal' | CHAR='ptCharacter';
public BaseGrammarAccess.LiteralTypeElements getLiteralTypeAccess() {
return gaBase.getLiteralTypeAccess();
}
@@ -4770,7 +4774,7 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
//// Value Types for Attributes
- //Literal:
+ // Literal:
// BooleanLiteral | NumberLiteral | StringLiteral;
public BaseGrammarAccess.LiteralElements getLiteralAccess() {
return gaBase.getLiteralAccess();
@@ -4861,11 +4865,12 @@ public class RoomGrammarAccess extends AbstractGrammarElementFinder {
}
////DotDecimal hidden():
- //// ('+' | '-')? '.' INT;
- ////
- ////DecimalDot hidden():
- //// ('+' | '-')? INT '.';
- //DecimalExp hidden():
+ // // ('+' | '-')? '.' INT;
+ // //
+ // //DecimalDot hidden():
+ // // ('+' | '-')? INT '.';
+ // DecimalExp
+ //hidden():
// ('+' | '-')? INT '.' INT ('e' | 'E') ('+' | '-')? INT;
public BaseGrammarAccess.DecimalExpElements getDecimalExpAccess() {
return gaBase.getDecimalExpAccess();
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2 b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2
index 2ac176398..4bf2fdc1c 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2
@@ -115,7 +115,7 @@ Workflow {
fragment = builder.BuilderIntegrationFragment {}
// formatter API
- fragment = formatting.FormatterFragment {}
+ fragment = formatting2.Formatter2Fragment {}
// labeling API
fragment = labeling.LabelProviderFragment {}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomRuntimeModule.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomRuntimeModule.java
index ca4fe7ca4..37ac71a9b 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomRuntimeModule.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomRuntimeModule.java
@@ -98,4 +98,5 @@ public class RoomRuntimeModule extends org.eclipse.etrice.core.AbstractRoomRunti
public Class<? extends INamesAreUniqueValidationHelper> bindINamesAreUniqueValidationHelper(){
return FQNAreUniqueValidationHelper.class;
}
+
}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting/RoomFormatter.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting/RoomFormatter.java
index 777f7fd8c..644148cb7 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting/RoomFormatter.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting/RoomFormatter.java
@@ -12,7 +12,7 @@
package org.eclipse.etrice.core.formatting;
-import org.eclipse.etrice.core.common.converter.CC_StringConveter;
+import org.eclipse.etrice.core.common.converter.CC_StringConverter;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
import org.eclipse.xtext.formatting.impl.FormattingConfig;
@@ -24,6 +24,7 @@ import org.eclipse.xtext.util.Pair;
*
* Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
*/
+@Deprecated
public class RoomFormatter extends AbstractDeclarativeFormatter {
@Override
@@ -67,7 +68,7 @@ public class RoomFormatter extends AbstractDeclarativeFormatter {
}
for (Keyword k: f.findKeywords("do", "entry", "exit", "action", "cond", "usercode", "usercode1", "usercode2")) {
- c.setSpace(" ").between(k, f.findKeywords(CC_StringConveter.DELIM).get(0));
+ c.setSpace(" ").between(k, f.findKeywords(CC_StringConverter.DELIM).get(0));
}
c.setLinewrap(2).around(f.getImportRule());
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting2/RoomFormatter.xtend b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting2/RoomFormatter.xtend
new file mode 100644
index 000000000..8a4149e87
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/formatting2/RoomFormatter.xtend
@@ -0,0 +1,90 @@
+/*
+ * generated by Xtext
+ */
+package org.eclipse.etrice.core.formatting2;
+
+import com.google.inject.Inject
+import org.eclipse.emf.ecore.EObject
+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.fsm.fSM.DetailCode
+import org.eclipse.etrice.core.fsm.formatting2.FSMFormatter
+import org.eclipse.etrice.core.room.ActorClass
+import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.EnumerationType
+import org.eclipse.etrice.core.room.ExternalType
+import org.eclipse.etrice.core.room.GeneralProtocolClass
+import org.eclipse.etrice.core.room.Operation
+import org.eclipse.etrice.core.room.PortClass
+import org.eclipse.etrice.core.room.PrimitiveType
+import org.eclipse.etrice.core.room.RoomClass
+import org.eclipse.etrice.core.room.RoomModel
+import org.eclipse.etrice.core.room.SubSystemClass
+import org.eclipse.etrice.core.services.RoomGrammarAccess
+import org.eclipse.xtext.GrammarUtil
+import org.eclipse.xtext.Keyword
+import org.eclipse.xtext.formatting2.IFormattableDocument
+
+// In order to save effort, try writing generic rules. Use 'highPriority' to override them in specific rules.
+class RoomFormatter extends FSMFormatter {
+
+ @Inject extension RoomGrammarAccess
+
+ override void formatAllByKeywords(EObject it, extension IFormattableDocument document) {
+ super.formatAllByKeywords(it, document)
+
+ allRegionsFor.keywords('default', 'void', 'sends', 'sub', 'of', 'and', 'satisfied_by').forEach[
+ surround[oneSpace]
+ ]
+ allRegionsFor.keywords('/').forEach[surround[noSpace]]
+
+ // all pure text keyword => append[oneSpace]
+ val textKeywords = GrammarUtil.allRules(getGrammar).map[
+ eAllContents.filter(Keyword).filter[value != 'ref'].filter[value.toCharArray.forall[Character.isLetter(it)]].toIterable
+ ].flatten
+ allRegionsFor.keywords(textKeywords).forEach[append[oneSpace]]
+ }
+
+ def dispatch void format(RoomModel it, extension IFormattableDocument document) {
+ formatAllByKeywords(document)
+
+ // top level contents
+ eContents.head.prepend[newLines = 2]
+ eContents.tail.filter(DataClass).forEach[prepend[newLines = 2]]
+ eContents.tail.filter(GeneralProtocolClass).forEach[prepend[newLines = 2]]
+ eContents.tail.filter(ActorClass).forEach[prepend[newLines = 2]]
+ eContents.tail.filter(SubSystemClass).forEach[prepend[newLines = 2]]
+ eContents.tail.filter(AnnotationType).forEach[prepend[newLines = 2]]
+ eContents.tail.filter(AnnotationType).forEach[prepend[newLines = 2]]
+ eContents.tail.filter(Import).forEach[prependDefaultNewLines(document)]
+ eContents.tail.filter(PrimitiveType).forEach[prependDefaultNewLines(document)]
+ eContents.tail.filter(EnumerationType).forEach[prependDefaultNewLines(document)]
+ eContents.tail.filter(ExternalType).forEach[prependDefaultNewLines(document)]
+
+ eAllContents.forEach[
+ format // recursive
+ ]
+ }
+
+ def dispatch void format(RoomClass it, extension IFormattableDocument document) {
+ eContents.filter[!(it instanceof DetailCode || it instanceof Documentation)].forEach[prependDefaultNewLines(document)]
+ regionFor.keywords('usercode1', 'usercode2', 'usercode3', 'incoming', 'outgoing', 'regular', 'conjugated', 'Interface', 'Structure', 'Behavior').forEach[prependDefaultNewLines(document)]
+ }
+
+ def dispatch void format(PortClass it, extension IFormattableDocument document) {
+ eContents.filter[!(it instanceof DetailCode || it instanceof Documentation)].forEach[prependDefaultNewLines(document)]
+ }
+
+ def dispatch void format(Operation it, extension IFormattableDocument document) {
+ arguments.forEach[append[noSpace]]
+ }
+
+ def dispatch void format(Attribute it, extension IFormattableDocument document) {
+ regionFor.keywordPairs('[', ']').forEach[
+ key.prepend[oneSpace]
+ interior[noSpace]
+ ]
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/formatting2/RoomFormatter.java b/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/formatting2/RoomFormatter.java
new file mode 100644
index 000000000..83b7bc5e6
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/formatting2/RoomFormatter.java
@@ -0,0 +1,349 @@
+/**
+ * generated by Xtext
+ */
+package org.eclipse.etrice.core.formatting2;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import com.google.inject.Inject;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+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.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.formatting2.FSMFormatter;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.EnumerationType;
+import org.eclipse.etrice.core.room.ExternalType;
+import org.eclipse.etrice.core.room.GeneralProtocolClass;
+import org.eclipse.etrice.core.room.Operation;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.RoomClass;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.core.services.RoomGrammarAccess;
+import org.eclipse.xtext.AbstractRule;
+import org.eclipse.xtext.Grammar;
+import org.eclipse.xtext.GrammarUtil;
+import org.eclipse.xtext.Keyword;
+import org.eclipse.xtext.formatting2.IFormattableDocument;
+import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
+import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
+import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.IteratorExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+import org.eclipse.xtext.xbase.lib.Pair;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@SuppressWarnings("all")
+public class RoomFormatter extends FSMFormatter {
+ @Inject
+ @Extension
+ private RoomGrammarAccess _roomGrammarAccess;
+
+ @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("default", "void", "sends", "sub", "of", "and", "satisfied_by");
+ 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);
+ ISemanticRegionsFinder _allRegionsFor_1 = this.textRegionExtensions.allRegionsFor(it);
+ List<ISemanticRegion> _keywords_1 = _allRegionsFor_1.keywords("/");
+ final Consumer<ISemanticRegion> _function_1 = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.surround(it_1, _function_2);
+ };
+ _keywords_1.forEach(_function_1);
+ Grammar _grammar = this._roomGrammarAccess.getGrammar();
+ List<AbstractRule> _allRules = GrammarUtil.allRules(_grammar);
+ final Function1<AbstractRule, Iterable<Keyword>> _function_2 = (AbstractRule it_1) -> {
+ TreeIterator<EObject> _eAllContents = it_1.eAllContents();
+ Iterator<Keyword> _filter = Iterators.<Keyword>filter(_eAllContents, Keyword.class);
+ final Function1<Keyword, Boolean> _function_3 = (Keyword it_2) -> {
+ String _value = it_2.getValue();
+ return Boolean.valueOf((!Objects.equal(_value, "ref")));
+ };
+ Iterator<Keyword> _filter_1 = IteratorExtensions.<Keyword>filter(_filter, _function_3);
+ final Function1<Keyword, Boolean> _function_4 = (Keyword it_2) -> {
+ String _value = it_2.getValue();
+ char[] _charArray = _value.toCharArray();
+ final Function1<Character, Boolean> _function_5 = (Character it_3) -> {
+ return Boolean.valueOf(Character.isLetter((it_3).charValue()));
+ };
+ return Boolean.valueOf(IterableExtensions.<Character>forall(((Iterable<Character>)Conversions.doWrapArray(_charArray)), _function_5));
+ };
+ Iterator<Keyword> _filter_2 = IteratorExtensions.<Keyword>filter(_filter_1, _function_4);
+ return IteratorExtensions.<Keyword>toIterable(_filter_2);
+ };
+ List<Iterable<Keyword>> _map = ListExtensions.<AbstractRule, Iterable<Keyword>>map(_allRules, _function_2);
+ final Iterable<Keyword> textKeywords = Iterables.<Keyword>concat(_map);
+ ISemanticRegionsFinder _allRegionsFor_2 = this.textRegionExtensions.allRegionsFor(it);
+ List<ISemanticRegion> _keywords_2 = _allRegionsFor_2.keywords(((Keyword[])Conversions.unwrapArray(textKeywords, Keyword.class)));
+ final Consumer<ISemanticRegion> _function_3 = (ISemanticRegion it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.append(it_1, _function_4);
+ };
+ _keywords_2.forEach(_function_3);
+ }
+
+ protected void _format(final RoomModel it, @Extension final IFormattableDocument document) {
+ this.formatAllByKeywords(it, document);
+ EList<EObject> _eContents = it.eContents();
+ EObject _head = IterableExtensions.<EObject>head(_eContents);
+ final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
+ it_1.setNewLines(2);
+ };
+ document.<EObject>prepend(_head, _function);
+ EList<EObject> _eContents_1 = it.eContents();
+ Iterable<EObject> _tail = IterableExtensions.<EObject>tail(_eContents_1);
+ Iterable<DataClass> _filter = Iterables.<DataClass>filter(_tail, DataClass.class);
+ final Consumer<DataClass> _function_1 = (DataClass it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
+ it_2.setNewLines(2);
+ };
+ document.<DataClass>prepend(it_1, _function_2);
+ };
+ _filter.forEach(_function_1);
+ EList<EObject> _eContents_2 = it.eContents();
+ Iterable<EObject> _tail_1 = IterableExtensions.<EObject>tail(_eContents_2);
+ Iterable<GeneralProtocolClass> _filter_1 = Iterables.<GeneralProtocolClass>filter(_tail_1, GeneralProtocolClass.class);
+ final Consumer<GeneralProtocolClass> _function_2 = (GeneralProtocolClass it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_2) -> {
+ it_2.setNewLines(2);
+ };
+ document.<GeneralProtocolClass>prepend(it_1, _function_3);
+ };
+ _filter_1.forEach(_function_2);
+ EList<EObject> _eContents_3 = it.eContents();
+ Iterable<EObject> _tail_2 = IterableExtensions.<EObject>tail(_eContents_3);
+ Iterable<ActorClass> _filter_2 = Iterables.<ActorClass>filter(_tail_2, ActorClass.class);
+ final Consumer<ActorClass> _function_3 = (ActorClass it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it_2) -> {
+ it_2.setNewLines(2);
+ };
+ document.<ActorClass>prepend(it_1, _function_4);
+ };
+ _filter_2.forEach(_function_3);
+ EList<EObject> _eContents_4 = it.eContents();
+ Iterable<EObject> _tail_3 = IterableExtensions.<EObject>tail(_eContents_4);
+ Iterable<SubSystemClass> _filter_3 = Iterables.<SubSystemClass>filter(_tail_3, SubSystemClass.class);
+ final Consumer<SubSystemClass> _function_4 = (SubSystemClass it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_5 = (IHiddenRegionFormatter it_2) -> {
+ it_2.setNewLines(2);
+ };
+ document.<SubSystemClass>prepend(it_1, _function_5);
+ };
+ _filter_3.forEach(_function_4);
+ EList<EObject> _eContents_5 = it.eContents();
+ Iterable<EObject> _tail_4 = IterableExtensions.<EObject>tail(_eContents_5);
+ Iterable<AnnotationType> _filter_4 = Iterables.<AnnotationType>filter(_tail_4, AnnotationType.class);
+ final Consumer<AnnotationType> _function_5 = (AnnotationType it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_6 = (IHiddenRegionFormatter it_2) -> {
+ it_2.setNewLines(2);
+ };
+ document.<AnnotationType>prepend(it_1, _function_6);
+ };
+ _filter_4.forEach(_function_5);
+ EList<EObject> _eContents_6 = it.eContents();
+ Iterable<EObject> _tail_5 = IterableExtensions.<EObject>tail(_eContents_6);
+ Iterable<AnnotationType> _filter_5 = Iterables.<AnnotationType>filter(_tail_5, AnnotationType.class);
+ final Consumer<AnnotationType> _function_6 = (AnnotationType it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it_2) -> {
+ it_2.setNewLines(2);
+ };
+ document.<AnnotationType>prepend(it_1, _function_7);
+ };
+ _filter_5.forEach(_function_6);
+ EList<EObject> _eContents_7 = it.eContents();
+ Iterable<EObject> _tail_6 = IterableExtensions.<EObject>tail(_eContents_7);
+ Iterable<Import> _filter_6 = Iterables.<Import>filter(_tail_6, Import.class);
+ final Consumer<Import> _function_7 = (Import it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _filter_6.forEach(_function_7);
+ EList<EObject> _eContents_8 = it.eContents();
+ Iterable<EObject> _tail_7 = IterableExtensions.<EObject>tail(_eContents_8);
+ Iterable<PrimitiveType> _filter_7 = Iterables.<PrimitiveType>filter(_tail_7, PrimitiveType.class);
+ final Consumer<PrimitiveType> _function_8 = (PrimitiveType it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _filter_7.forEach(_function_8);
+ EList<EObject> _eContents_9 = it.eContents();
+ Iterable<EObject> _tail_8 = IterableExtensions.<EObject>tail(_eContents_9);
+ Iterable<EnumerationType> _filter_8 = Iterables.<EnumerationType>filter(_tail_8, EnumerationType.class);
+ final Consumer<EnumerationType> _function_9 = (EnumerationType it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _filter_8.forEach(_function_9);
+ EList<EObject> _eContents_10 = it.eContents();
+ Iterable<EObject> _tail_9 = IterableExtensions.<EObject>tail(_eContents_10);
+ Iterable<ExternalType> _filter_9 = Iterables.<ExternalType>filter(_tail_9, ExternalType.class);
+ final Consumer<ExternalType> _function_10 = (ExternalType it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _filter_9.forEach(_function_10);
+ TreeIterator<EObject> _eAllContents = it.eAllContents();
+ final Procedure1<EObject> _function_11 = (EObject it_1) -> {
+ document.<EObject>format(it_1);
+ };
+ IteratorExtensions.<EObject>forEach(_eAllContents, _function_11);
+ }
+
+ protected void _format(final RoomClass it, @Extension final IFormattableDocument document) {
+ EList<EObject> _eContents = it.eContents();
+ final Function1<EObject, Boolean> _function = (EObject it_1) -> {
+ return Boolean.valueOf((!((it_1 instanceof DetailCode) || (it_1 instanceof Documentation))));
+ };
+ Iterable<EObject> _filter = IterableExtensions.<EObject>filter(_eContents, _function);
+ final Consumer<EObject> _function_1 = (EObject it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _filter.forEach(_function_1);
+ ISemanticRegionsFinder _regionFor = this.textRegionExtensions.regionFor(it);
+ List<ISemanticRegion> _keywords = _regionFor.keywords("usercode1", "usercode2", "usercode3", "incoming", "outgoing", "regular", "conjugated", "Interface", "Structure", "Behavior");
+ final Consumer<ISemanticRegion> _function_2 = (ISemanticRegion it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _keywords.forEach(_function_2);
+ }
+
+ protected void _format(final PortClass it, @Extension final IFormattableDocument document) {
+ EList<EObject> _eContents = it.eContents();
+ final Function1<EObject, Boolean> _function = (EObject it_1) -> {
+ return Boolean.valueOf((!((it_1 instanceof DetailCode) || (it_1 instanceof Documentation))));
+ };
+ Iterable<EObject> _filter = IterableExtensions.<EObject>filter(_eContents, _function);
+ final Consumer<EObject> _function_1 = (EObject it_1) -> {
+ this.prependDefaultNewLines(it_1, document);
+ };
+ _filter.forEach(_function_1);
+ }
+
+ protected void _format(final Operation it, @Extension final IFormattableDocument document) {
+ EList<VarDecl> _arguments = it.getArguments();
+ final Consumer<VarDecl> _function = (VarDecl it_1) -> {
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.<VarDecl>append(it_1, _function_1);
+ };
+ _arguments.forEach(_function);
+ }
+
+ protected void _format(final Attribute 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) -> {
+ ISemanticRegion _key = it_1.getKey();
+ final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
+ it_2.oneSpace();
+ };
+ document.prepend(_key, _function_1);
+ final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
+ it_2.noSpace();
+ };
+ document.<ISemanticRegion, ISemanticRegion>interior(it_1, _function_2);
+ };
+ _keywordPairs.forEach(_function);
+ }
+
+ 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 Attribute) {
+ _format((Attribute)it, document);
+ return;
+ } else if (it instanceof Operation) {
+ _format((Operation)it, document);
+ return;
+ } else if (it instanceof PortClass) {
+ _format((PortClass)it, document);
+ return;
+ } else if (it instanceof RoomClass) {
+ _format((RoomClass)it, document);
+ return;
+ } else if (it instanceof RoomModel) {
+ _format((RoomModel)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());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath b/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath
index ef5811bf8..1fa3e6803 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
diff --git a/plugins/org.eclipse.etrice.ui.behavior/.classpath b/plugins/org.eclipse.etrice.ui.behavior/.classpath
index ef5811bf8..1fa3e6803 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/.classpath
+++ b/plugins/org.eclipse.etrice.ui.behavior/.classpath
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
diff --git a/tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend b/tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend
new file mode 100644
index 000000000..5446f57c1
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.common.tests/src-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.xtend
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * 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.common
+
+import com.google.inject.Inject
+import org.eclipse.etrice.core.common.converter.BaseConverterService
+import org.eclipse.etrice.core.common.converter.CC_StringConverter
+import org.eclipse.xtext.junit4.InjectWith
+import org.eclipse.xtext.junit4.XtextRunner
+import org.eclipse.xtext.util.Strings
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import static org.junit.Assert.*
+
+@RunWith(XtextRunner)
+@InjectWith(BaseTestInjectorProvider)
+class DetailCodeParseTest {
+
+ val NL = Strings.newLine
+ val DELIM = CC_StringConverter.DELIM
+
+ @Inject
+ BaseConverterService baseConverterService
+
+ protected def String toValue(String withoutDelim) {
+ baseConverterService.getCC_StringConverter.toValue(withoutDelim, null) => [ convertedWithoutDelim |
+ val convertedWithDelim = baseConverterService.getCC_StringConverter.toValue(DELIM + withoutDelim + DELIM, null)
+ assertEquals(convertedWithoutDelim, convertedWithDelim)
+ ]
+ }
+
+ @Test
+ def void noLineBreak() {
+ assertEquals('', toValue(''''''))
+ assertEquals(''''''.toString, toValue(''''''))
+
+ assertEquals(' ', toValue(''' '''))
+ assertEquals(''' '''.toString, toValue(''' '''))
+
+ assertEquals('\t', toValue(''' '''))
+ assertEquals(''' '''.toString, toValue(''' '''))
+
+ assertEquals(' text ', toValue(''' text '''))
+ assertEquals(''' text '''.toString, toValue(''' text '''))
+
+ assertEquals("'", toValue("'"))
+ assertEquals("''", toValue("''"))
+ assertEquals('"', toValue('"'))
+ }
+
+ @Test
+ def void singleLineBreak() {
+ assertEquals('', toValue('\r'))
+ assertEquals('', toValue('\r\n'))
+ assertEquals('', toValue('\n'))
+ assertEquals('''
+ '''.toString, toValue(NL))
+
+ '\t' + NL => [ text |
+ assertEquals('', toValue(text))
+ assertEquals('''
+ '''.toString, toValue(text))
+ ]
+
+ 'text' + NL => [ text |
+ assertEquals('text' + NL, toValue(text))
+ assertEquals('''text
+ '''.toString, toValue(text))
+ ]
+
+ ' text\t' + NL => [ text |
+
+ assertEquals(' text\t' + NL, toValue(text))
+ assertEquals(''' text
+ '''.toString, toValue(text))
+ ]
+
+ 'text' + NL + '\t' => [ text |
+ assertEquals('text' + NL, toValue(text))
+ assertEquals('''text
+ '''.toString, toValue(text))
+ ]
+
+ NL + 'text ' => [ text |
+ assertEquals('text ', toValue(text))
+ assertEquals('''
+ text '''.toString, toValue(text))
+ ]
+
+ ' ' + NL + 'text' => [ text |
+ assertEquals('text', toValue(text))
+ assertEquals('''
+ text'''.toString, toValue(text))
+ ]
+
+ NL + ' text ' => [ text |
+ assertEquals('text ', toValue(text))
+ assertEquals('''
+ text '''.toString, toValue(text))
+ ]
+
+ }
+
+ @Test
+ def void twoLineBreaks() {
+ NL + NL => [ text |
+ assertEquals(NL, toValue(text))
+ assertEquals('''
+
+ '''.toString, toValue(text))
+ ]
+
+ 'text' + NL + NL => [ text |
+ assertEquals('text' + NL + NL, toValue(text))
+ assertEquals('''text
+
+ '''.toString, toValue(text))
+ ]
+
+ 'text' + NL + '\t\t\t\tindent' + NL => [ text |
+ assertEquals('text' + NL + '\t\t\t\tindent' + NL, toValue(text))
+ assertEquals('''text
+ indent
+ '''.toString, toValue(text))
+ ]
+
+ NL + 'text' + NL => [ text |
+ assertEquals('text' + NL, toValue(text))
+ assertEquals('''
+text
+ '''.toString, toValue(text))
+ ]
+
+ NL + '\t\t\t\ttext\t' + NL => [ text |
+ assertEquals('text\t' + NL, toValue(text))
+ assertEquals('''
+ text
+ '''.toString, toValue(text))
+ ]
+
+ NL + 'text' + NL + 'text2 ' => [ text |
+ assertEquals('text' + NL + 'text2 ', toValue(text))
+ assertEquals('''
+ text
+ text2 '''.toString, toValue(text))
+ ]
+
+ NL + '\ttext' + NL + 'text2 ' => [ text |
+ assertEquals('\ttext' + NL + 'text2 ', toValue(text))
+ assertEquals('''
+ text
+ text2 '''.toString, toValue(text))
+ ]
+
+ NL + 'text' + NL + '\t\t\tindent' => [ text |
+ assertEquals('text' + NL + '\t\t\tindent', toValue(text))
+ assertEquals('''
+text
+ indent'''.toString, toValue(text))
+ ]
+ }
+
+ @Test
+ def void multiLineBreaks() {
+ NL + '\t\t\t ' + NL + NL + '\t\t ' + NL + '\t\t\ttext' + NL => [ text |
+ assertEquals(' ' + NL + NL + '\t\t ' + NL + 'text' + NL, toValue(text))
+ assertEquals('''
+
+
+
+ text
+ '''.toString, toValue(text))
+ ]
+ }
+
+}
diff --git a/tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java b/tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java
new file mode 100644
index 000000000..c1e083296
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.common.tests/xtend-gen/org/eclipse/etrice/core/common/DetailCodeParseTest.java
@@ -0,0 +1,326 @@
+/**
+ * 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.common;
+
+import com.google.inject.Inject;
+import org.eclipse.etrice.core.common.BaseTestInjectorProvider;
+import org.eclipse.etrice.core.common.converter.BaseConverterService;
+import org.eclipse.etrice.core.common.converter.CC_StringConverter;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.conversion.IValueConverter;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.util.Strings;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(XtextRunner.class)
+@InjectWith(BaseTestInjectorProvider.class)
+@SuppressWarnings("all")
+public class DetailCodeParseTest {
+ private final String NL = Strings.newLine();
+
+ private final String DELIM = CC_StringConverter.DELIM;
+
+ @Inject
+ private BaseConverterService baseConverterService;
+
+ protected String toValue(final String withoutDelim) {
+ IValueConverter<String> _cC_StringConverter = this.baseConverterService.getCC_StringConverter();
+ String _value = _cC_StringConverter.toValue(withoutDelim, null);
+ final Procedure1<String> _function = (String convertedWithoutDelim) -> {
+ IValueConverter<String> _cC_StringConverter_1 = this.baseConverterService.getCC_StringConverter();
+ final String convertedWithDelim = _cC_StringConverter_1.toValue(((this.DELIM + withoutDelim) + this.DELIM), null);
+ Assert.assertEquals(convertedWithoutDelim, convertedWithDelim);
+ };
+ return ObjectExtensions.<String>operator_doubleArrow(_value, _function);
+ }
+
+ @Test
+ public void noLineBreak() {
+ StringConcatenation _builder = new StringConcatenation();
+ String _value = this.toValue(_builder.toString());
+ Assert.assertEquals("", _value);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _string = _builder_1.toString();
+ StringConcatenation _builder_2 = new StringConcatenation();
+ String _value_1 = this.toValue(_builder_2.toString());
+ Assert.assertEquals(_string, _value_1);
+ StringConcatenation _builder_3 = new StringConcatenation();
+ _builder_3.append(" ");
+ String _value_2 = this.toValue(_builder_3.toString());
+ Assert.assertEquals(" ", _value_2);
+ StringConcatenation _builder_4 = new StringConcatenation();
+ _builder_4.append(" ");
+ String _string_1 = _builder_4.toString();
+ StringConcatenation _builder_5 = new StringConcatenation();
+ _builder_5.append(" ");
+ String _value_3 = this.toValue(_builder_5.toString());
+ Assert.assertEquals(_string_1, _value_3);
+ StringConcatenation _builder_6 = new StringConcatenation();
+ _builder_6.append("\t");
+ String _value_4 = this.toValue(_builder_6.toString());
+ Assert.assertEquals("\t", _value_4);
+ StringConcatenation _builder_7 = new StringConcatenation();
+ _builder_7.append("\t");
+ String _string_2 = _builder_7.toString();
+ StringConcatenation _builder_8 = new StringConcatenation();
+ _builder_8.append("\t");
+ String _value_5 = this.toValue(_builder_8.toString());
+ Assert.assertEquals(_string_2, _value_5);
+ StringConcatenation _builder_9 = new StringConcatenation();
+ _builder_9.append(" ");
+ _builder_9.append("text ");
+ String _value_6 = this.toValue(_builder_9.toString());
+ Assert.assertEquals(" text ", _value_6);
+ StringConcatenation _builder_10 = new StringConcatenation();
+ _builder_10.append(" ");
+ _builder_10.append("text ");
+ String _string_3 = _builder_10.toString();
+ StringConcatenation _builder_11 = new StringConcatenation();
+ _builder_11.append(" ");
+ _builder_11.append("text ");
+ String _value_7 = this.toValue(_builder_11.toString());
+ Assert.assertEquals(_string_3, _value_7);
+ String _value_8 = this.toValue("\'");
+ Assert.assertEquals("\'", _value_8);
+ String _value_9 = this.toValue("\'\'");
+ Assert.assertEquals("\'\'", _value_9);
+ String _value_10 = this.toValue("\"");
+ Assert.assertEquals("\"", _value_10);
+ }
+
+ @Test
+ public void singleLineBreak() {
+ String _value = this.toValue("\r");
+ Assert.assertEquals("", _value);
+ String _value_1 = this.toValue("\r\n");
+ Assert.assertEquals("", _value_1);
+ String _value_2 = this.toValue("\n");
+ Assert.assertEquals("", _value_2);
+ StringConcatenation _builder = new StringConcatenation();
+ String _string = _builder.toString();
+ String _value_3 = this.toValue(this.NL);
+ Assert.assertEquals(_string, _value_3);
+ final Procedure1<String> _function = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals("", _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ ("\t" + this.NL), _function);
+ final Procedure1<String> _function_1 = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals(("text" + this.NL), _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("text");
+ _builder_1.newLine();
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ ("text" + this.NL), _function_1);
+ final Procedure1<String> _function_2 = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals((" text\t" + this.NL), _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append(" ");
+ _builder_1.append("text\t");
+ _builder_1.newLine();
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (" text\t" + this.NL), _function_2);
+ final Procedure1<String> _function_3 = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals(("text" + this.NL), _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("text");
+ _builder_1.newLine();
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (("text" + this.NL) + "\t"), _function_3);
+ final Procedure1<String> _function_4 = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals("text ", _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("text ");
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (this.NL + "text "), _function_4);
+ final Procedure1<String> _function_5 = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals("text", _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("text");
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ ((" " + this.NL) + "text"), _function_5);
+ final Procedure1<String> _function_6 = (String text) -> {
+ String _value_4 = this.toValue(text);
+ Assert.assertEquals("text ", _value_4);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("text ");
+ String _string_1 = _builder_1.toString();
+ String _value_5 = this.toValue(text);
+ Assert.assertEquals(_string_1, _value_5);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (this.NL + " text "), _function_6);
+ }
+
+ @Test
+ public void twoLineBreaks() {
+ final Procedure1<String> _function = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals(this.NL, _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.newLine();
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (this.NL + this.NL), _function);
+ final Procedure1<String> _function_1 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals((("text" + this.NL) + this.NL), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("text");
+ _builder.newLine();
+ _builder.newLine();
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (("text" + this.NL) + this.NL), _function_1);
+ final Procedure1<String> _function_2 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals(((("text" + this.NL) + "\t\t\t\tindent") + this.NL), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("text");
+ _builder.newLine();
+ _builder.append("\t\t\t\t");
+ _builder.append("indent");
+ _builder.newLine();
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ ((("text" + this.NL) + "\t\t\t\tindent") + this.NL), _function_2);
+ final Procedure1<String> _function_3 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals(("text" + this.NL), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("text");
+ _builder.newLine();
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ ((this.NL + "text") + this.NL), _function_3);
+ final Procedure1<String> _function_4 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals(("text\t" + this.NL), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("text\t");
+ _builder.newLine();
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ ((this.NL + "\t\t\t\ttext\t") + this.NL), _function_4);
+ final Procedure1<String> _function_5 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals((("text" + this.NL) + "text2 "), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("text");
+ _builder.newLine();
+ _builder.append("text2 ");
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (((this.NL + "text") + this.NL) + "text2 "), _function_5);
+ final Procedure1<String> _function_6 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals((("\ttext" + this.NL) + "text2 "), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("\t");
+ _builder.append("text");
+ _builder.newLine();
+ _builder.append("text2 ");
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (((this.NL + "\ttext") + this.NL) + "text2 "), _function_6);
+ final Procedure1<String> _function_7 = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals((("text" + this.NL) + "\t\t\tindent"), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("text");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("indent");
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (((this.NL + "text") + this.NL) + "\t\t\tindent"), _function_7);
+ }
+
+ @Test
+ public void multiLineBreaks() {
+ final Procedure1<String> _function = (String text) -> {
+ String _value = this.toValue(text);
+ Assert.assertEquals(((((((" " + this.NL) + this.NL) + "\t\t ") + this.NL) + "text") + this.NL), _value);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append(" ");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t\t ");
+ _builder.newLine();
+ _builder.append("text");
+ _builder.newLine();
+ String _string = _builder.toString();
+ String _value_1 = this.toValue(text);
+ Assert.assertEquals(_string, _value_1);
+ };
+ ObjectExtensions.<String>operator_doubleArrow(
+ (((((((this.NL + "\t\t\t ") + this.NL) + this.NL) + "\t\t ") + this.NL) + "\t\t\ttext") + this.NL), _function);
+ }
+}
diff --git a/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF
index 41b0bf1af..596021e5b 100644
--- a/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.etrice.core.fsm.tests/META-INF/MANIFEST.MF
@@ -5,7 +5,8 @@ Bundle-Vendor: Eclipse eTrice
Bundle-Version: 1.1.1.qualifier
Bundle-SymbolicName: org.eclipse.etrice.core.fsm.tests; singleton:=true
Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.etrice.core.fsm,
+Require-Bundle: org.eclipse.etrice.core.common,
+ org.eclipse.etrice.core.fsm,
org.eclipse.etrice.core.fsm.ui,
org.eclipse.core.runtime,
org.eclipse.xtext.junit4;bundle-version="2.6.0",
diff --git a/tests/org.eclipse.etrice.core.room.tests/.classpath b/tests/org.eclipse.etrice.core.room.tests/.classpath
index b9247ca72..6f43376b3 100644
--- a/tests/org.eclipse.etrice.core.room.tests/.classpath
+++ b/tests/org.eclipse.etrice.core.room.tests/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="xtend-gen"/>
+ <classpathentry kind="src" path="src-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
diff --git a/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF
index 81b087191..c6acb3d89 100644
--- a/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.etrice.core.room.tests/META-INF/MANIFEST.MF
@@ -9,10 +9,11 @@ Require-Bundle: org.eclipse.etrice.core.room;bundle-version="1.1.1",
org.eclipse.etrice.core.common;bundle-version="1.1.1",
org.eclipse.etrice.core.fsm;bundle-version="1.1.1",
org.junit;bundle-version="4.8.1",
+ org.eclipse.xtext.junit4,
+ org.eclipse.xtext.xbase.junit,
org.eclipse.osgi;bundle-version="3.6.0",
org.eclipse.xtext;bundle-version="2.6.0",
org.eclipse.core.runtime;bundle-version="3.6.0",
- org.eclipse.emf.ecore,
- org.eclipse.xtend.core;bundle-version="2.7.3"
+ org.eclipse.emf.ecore
Bundle-Activator: org.eclipse.etrice.core.CoreTestsActivator
Bundle-ActivationPolicy: lazy
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room
new file mode 100644
index 000000000..76ebd8506
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/expected/DetailCode.room
@@ -0,0 +1,52 @@
+RoomModel DetailCode {
+
+ ActorClass ADetailCode {
+ Structure {
+ usercode1 {
+ "/*uc1*/"
+ }
+ usercode2 '''/*uc3*/'''
+ usercode3 '''/*uc3*/'''
+ }
+ Behavior {
+ Operation op1() '''text\r\n'''
+ Operation op2() '''
+ text\r\n
+ '''
+ StateMachine {
+ State state {
+ entry '''dfd'''
+ exit '''d
+ '''
+ }
+
+ Transition init: initial -> state {
+ action '''
+ /* maintain timers */
+ etTimerControlBlock* temp;
+ etTime t;
+
+ getTimeFromTarget(&t);
+ while (usedTcbsRoot != 0) {
+ if (isTimeGreater(&t, &(usedTcbsRoot->expTime))) {
+ timer_timeout(usedTcbsRoot->portIdx);
+ temp = usedTcbsRoot;
+ usedTcbsRoot = usedTcbsRoot->next;
+ if ((temp->pTime.sec == 0) && (temp->pTime.nSec == 0)) {
+ /* single shot timer */
+ returnTcb(temp);
+ } else {
+ /* periodic timer */
+ addTime(&temp->expTime, &temp->pTime);
+ putTcbToUsedList(temp);
+ }
+ } else {
+ break;
+ }
+ }
+ '''
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room
new file mode 100644
index 000000000..3d43c757c
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/ActorCommunicationTest.room
@@ -0,0 +1,304 @@
+/*removed comments and whitespace from detail code*/RoomModel ActorCommunicationTest {
+
+ import room.basic.types.* from "Types.room"
+ import room.basic.test.* from "Tests.room"
+ import room.basic.service.timing.* from "TimingService.room"
+
+ SubSystemClass SubSystem_ActorCommunicationTest {
+ @TestInstance
+ ActorRef singleThread_Appl: Appl
+ ActorRef timing: ATimingService
+ LayerConnection ref singleThread_Appl satisfied_by timing.timer
+ }
+
+ ActorClass Appl {
+ Structure {
+ ActorRef tester: Tester
+ ActorRef datadriven_Testee: Datadriven_Testee
+ ActorRef eventdriven_Testee: Eventdriven_Testee
+ ActorRef async_Testee: Async_Testee
+ Binding tester.data_counter and datadriven_Testee.data_counter
+ Binding tester.data_counter_finish and datadriven_Testee.counter_finish
+ Binding tester.event_counter and eventdriven_Testee.event_counter
+ Binding tester.async_counter1 and async_Testee.event_counter
+ Binding tester.async_counter2 and async_Testee.data_counter
+ }
+ Behavior {
+ }
+ }
+
+ async ActorClass Tester {
+ Interface {
+ conjugated Port event_counter: Eventdriven_PC
+ conjugated Port data_counter: Datadriven_PC
+ Port data_counter_finish: Datadriven_PC
+ conjugated Port async_counter1: Eventdriven_PC
+ conjugated Port async_counter2: Datadriven_PC
+ }
+ Structure {
+ external Port event_counter
+ external Port data_counter
+ external Port data_counter_finish
+ external Port async_counter1
+ external Port async_counter2
+ SAP timer: PTimer
+ Attribute data_caseId: int32
+ Attribute event_caseId: int32
+ Attribute async_caseId: int32
+ Attribute counter: int32
+ Attribute finish_counter: int32
+ Attribute data_finish_flag: boolean
+ Attribute data_result [10]: int16 = "{1,2,3,4,5,6,7,8,9,10}"
+ Attribute event_result [10]: int16 = "{101,102,103,104,105,106,107,108,109,110}"
+ Attribute async_result [10]: int16 = "{1051,1002,1053,1004,1055,1006,1057,1008,1059,1010}"
+ }
+ Behavior {
+ ctor {
+ "etUnit_open(\"log/testlog\",\"ActorCommunicationTest\");"
+ "etUnit_openTestSuite(\"org.eclipse.etrice.generator.common.tests\");"
+ }
+ dtor {
+ "etUnit_closeTestSuite();"
+ "etUnit_close();"
+ }
+ StateMachine {
+ Transition init: initial -> tester_run {
+ action {
+ "data_caseId=etUnit_openTestCase(\"Datadriven ActorCommunicationTest\");"
+ "event_caseId=etUnit_openTestCase(\"Eventdriven ActorCommunicationTest\");"
+ "async_caseId=etUnit_openTestCase(\"Async ActorCommunicationTest\");"
+ ""
+ "event_counter.caseId(event_caseId);"
+ "data_counter.caseId(data_caseId);"
+ "async_counter2.caseId(async_caseId);"
+ ""
+ "counter=0;"
+ "finish_counter=0;"
+ "data_finish_flag=false;"
+ "EXPECT_ORDER_START(data_caseId,data_result,10);"
+ "EXPECT_ORDER_START(event_caseId,event_result,10);"
+ "EXPECT_ORDER_START(async_caseId,async_result,10);"
+ "timer.startTimer(400);"
+ }
+ }
+ Transition tr0: tester_run -> tester_run {
+ triggers {
+ <timeout: timer guard {
+ "counter<10"
+ }>
+ }
+ action {
+ "counter++;"
+ "event_counter.in1(counter);"
+ "data_counter.in1(counter);"
+ "async_counter1.in1(counter);"
+ "async_counter2.in1(counter);"
+ }
+ }
+ Transition tr1: tester_run -> tester_run {
+ triggers {
+ <finish: event_counter>
+ }
+ action {
+ "EXPECT_ORDER_END(event_caseId,\"<|MODEL_LOCATION|>\",110);"
+ "etUnit_closeTestCase(event_caseId);"
+ "finish_counter++;"
+ }
+ }
+ Transition tr2: tester_run -> tester_run {
+ guard {
+ "data_counter_finish.finish==true&&data_finish_flag==false"
+ }
+ action {
+ "data_finish_flag=true;"
+ "EXPECT_ORDER_END(data_caseId,\"<|MODEL_LOCATION|>\",10);"
+ "etUnit_closeTestCase(data_caseId);"
+ "finish_counter++;"
+ }
+ }
+ Transition tr3: tester_run -> tester_run {
+ triggers {
+ <finish: async_counter1>
+ }
+ action {
+ "EXPECT_ORDER_END(async_caseId,\"<|MODEL_LOCATION|>\",1010);"
+ "etUnit_closeTestCase(async_caseId);"
+ "finish_counter++;"
+ }
+ }
+ Transition terminate: my tp0 -> my tp0 {
+ guard {
+ "finish_counter==3"
+ }
+ action {
+ "etUnit_testFinished(event_caseId);"
+ }
+ }
+ TransitionPoint tp0
+ State tester_run
+ }
+ }
+ }
+
+ async ActorClass Async_Testee {
+ Interface {
+ Port event_counter: Eventdriven_PC
+ Port data_counter: Datadriven_PC
+ }
+ Structure {
+ external Port event_counter
+ external Port data_counter
+ Attribute counter: int32
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> Idle {
+ action {
+ "counter=0;"
+ }
+ }
+ Transition tr0: Idle -> Idle {
+ guard {
+ "data_counter.in1!=counter&&data_counter.in1%2==1"
+ }
+ action {
+ "counter=data_counter.in1;"
+ "EXPECT_ORDER(data_counter.caseId,\"<|MODEL_LOCATION|>\",counter+1050);"
+ }
+ }
+ Transition tr1: Idle -> Idle {
+ triggers {
+ <in1: event_counter guard {
+ "data%2==0&&data<10"
+ }>
+ }
+ action {
+ "counter=data;"
+ "EXPECT_ORDER(data_counter.caseId,\"<|MODEL_LOCATION|>\",counter+1000);"
+ }
+ }
+ Transition tr2: Idle -> state0 {
+ triggers {
+ <in1: event_counter guard {
+ "data==10"
+ }>
+ }
+ action {
+ "event_counter.finish();"
+ }
+ }
+ State Idle
+ State state0
+ }
+ }
+ }
+
+ ActorClass Eventdriven_Testee {
+ Interface {
+ Port event_counter: Eventdriven_PC
+ }
+ Structure {
+ external Port event_counter
+ Attribute caseId: int32
+ Attribute counter: int32
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 {
+ action {
+ "counter=0;"
+ }
+ }
+ Transition tr0: state0 -> state0 {
+ triggers {
+ <in1: event_counter guard {
+ "data<10"
+ }>
+ }
+ action {
+ "EXPECT_ORDER(caseId,\"<|MODEL_LOCATION|>\",data+100);"
+ }
+ }
+ Transition tr1: state0 -> state1 {
+ triggers {
+ <in1: event_counter guard {
+ "data==10"
+ }>
+ }
+ action {
+ "event_counter.finish();"
+ }
+ }
+ Transition tr2: state0 -> state0 {
+ triggers {
+ <caseId: event_counter>
+ }
+ action {
+ "caseId=data;"
+ }
+ }
+ State state0
+ State state1
+ }
+ }
+ }
+
+ datadriven ActorClass Datadriven_Testee {
+ Interface {
+ Port data_counter: Datadriven_PC
+ conjugated Port counter_finish: Datadriven_PC
+ }
+ Structure {
+ external Port data_counter
+ external Port counter_finish
+ Attribute counter: int32
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 {
+ action {
+ "counter=0;"
+ "counter_finish.finish(false);"
+ }
+ }
+ Transition tr0: state0 -> state1 {
+ guard {
+ "data_counter.in1==10"
+ }
+ action {
+ "counter_finish.finish(true);"
+ }
+ }
+ Transition tr1: state0 -> state0 {
+ guard {
+ "data_counter.in1!=counter&&counter<10"
+ }
+ action {
+ "counter=data_counter.in1;"
+ "EXPECT_ORDER(data_counter.caseId,\"<|MODEL_LOCATION|>\",counter);"
+ }
+ }
+ State state0
+ State state1
+ }
+ }
+ }
+
+ datadriven ProtocolClass Datadriven_PC {
+ incoming {
+ Message caseId(data: int32)
+ Message in1(data: int32)
+ Message finish(data: boolean)
+ }
+ }
+
+ ProtocolClass Eventdriven_PC {
+ incoming {
+ Message caseId(data: int32)
+ Message in1(data: int32)
+ }
+ outgoing {
+ Message finish()
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room
new file mode 100644
index 000000000..32f0cf8f7
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Annotations.room
@@ -0,0 +1,30 @@
+RoomModel room.basic.annotations {
+
+ AnnotationType BehaviorManual {
+ target = ActorBehavior
+ }
+
+ AnnotationType DataLogging {
+ target = SubSystemClass
+ mandatory attribute pathlist: ptCharacter
+ }
+
+ AnnotationType Gnuplot {
+ target = SubSystemClass
+ mandatory attribute format: ptCharacter
+ mandatory attribute outputfile: ptCharacter
+ mandatory attribute width: ptInteger
+ mandatory attribute height: ptInteger
+ optional attribute fontsize: ptInteger
+ }
+
+ AnnotationType GnuplotGraph {
+ target = SubSystemClass
+ mandatory attribute paths: ptCharacter
+ optional attribute interval: ptInteger
+ optional attribute xtics: ptReal
+ optional attribute mxtics: ptInteger
+ optional attribute ymin: ptReal
+ optional attribute ymax: ptReal
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room
new file mode 100644
index 000000000..f22cf33df
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/TimingService.room
@@ -0,0 +1,263 @@
+/*removed comments and whitespace from detail code*/RoomModel room.basic.service.timing {
+
+ import room.basic.types.* from "Types.room"
+
+ async ActorClass ATimingService {
+ Interface {
+ SPP timer: PTimer
+ }
+ Structure {
+ usercode1 {
+ "#include\"osal/etTime.h\""
+ "#define ET_NB_OF_TCBS 30"
+ "typedef struct etTCB etTimerControlBlock;"
+ "struct etTCB{"
+ "etTime expTime;"
+ "etTime pTime;"
+ "int32 portIdx;"
+ "etTimerControlBlock*next;"
+ " };"
+ }
+ usercode2 {
+ "/*uc2*/"
+ }
+ usercode3 {
+ "/*uc3*/"
+ }
+ ServiceImplementation of timer
+ Attribute tcbs [30]: tcb
+ Attribute usedTcbsRoot: tcb ref
+ Attribute freeTcbsRoot: tcb ref
+ }
+ Behavior {
+ Operation getTcb(): tcb ref {
+ "etTimerControlBlock*temp=freeTcbsRoot;"
+ ""
+ "if(freeTcbsRoot!=0){"
+ "freeTcbsRoot=freeTcbsRoot->next;"
+ "temp->next=0;"
+ " }"
+ "return temp;"
+ }
+ Operation returnTcb(block: tcb ref) {
+ "block->next=freeTcbsRoot;"
+ "freeTcbsRoot=block;"
+ }
+ Operation removeTcbFromUsedList(idx: int32) {
+ "etTimerControlBlock*temp=usedTcbsRoot;"
+ "etTimerControlBlock*temp2=usedTcbsRoot;"
+ ""
+ "if(temp==0)return;"
+ ""
+ "if(usedTcbsRoot->portIdx==idx){"
+ " /*element found,the first one*/"
+ "usedTcbsRoot=usedTcbsRoot->next;"
+ "returnTcb(temp);"
+ "return;"
+ "}"
+ ""
+ "temp=temp->next;"
+ "while(temp!=0){"
+ "if(temp->portIdx==idx){"
+ "temp2->next=temp->next;"
+ "returnTcb(temp);"
+ "return;"
+ "}else{"
+ " /*try next*/"
+ "temp2=temp;"
+ "temp=temp->next;"
+ " }"
+ "}"
+ }
+ Operation putTcbToUsedList(block: tcb ref) {
+ "etTimerControlBlock*temp=usedTcbsRoot;"
+ "etTimerControlBlock*temp2=usedTcbsRoot;"
+ ""
+ "if(temp==0){"
+ " /*list empty put new block to root*/"
+ "block->next=0;"
+ "usedTcbsRoot=block;"
+ "return;"
+ " }"
+ ""
+ "while(1){"
+ "if(temp!=0){"
+ "if(isTimeGreater(&block->expTime,&temp->expTime)){"
+ " /*try next position*/"
+ "temp2=temp;"
+ "temp=temp->next;"
+ " }else{"
+ " /*right position found*/"
+ "block->next=temp;"
+ "if(temp==usedTcbsRoot){"
+ "usedTcbsRoot=block;"
+ " }else{"
+ "temp2->next=block;"
+ " }"
+ "return;"
+ " }"
+ " }else{"
+ " /*end of list reached*/"
+ "block->next=0;"
+ "temp2->next=block;"
+ "return;"
+ " }"
+ "}"
+ }
+ Operation isTimeGreater(t1: targetTime ref, t2: targetTime ref): boolean {
+ "if(t1->sec>t2->sec)return ET_TRUE;"
+ "if(t1->sec<t2->sec)return ET_FALSE;"
+ "if(t1->nSec>t2->nSec)return ET_TRUE;"
+ "return ET_FALSE;"
+ }
+ Operation addTime(t1: targetTime ref, t2: targetTime ref) {
+ "t1->sec+=t2->sec;"
+ "t1->nSec+=t2->nSec;"
+ "while(t1->nSec>=1000000000L){"
+ "t1->sec++;"
+ "t1->nSec-=1000000000L;"
+ "}"
+ }
+ StateMachine {
+ Transition tr0: initial -> Operational {
+ action {
+ "int i;"
+ "usedTcbsRoot=0;"
+ "freeTcbsRoot=&tcbs[0];"
+ "tcbs[ET_NB_OF_TCBS-1].next=0;"
+ "for(i=0;i<ET_NB_OF_TCBS-1;i++){"
+ "\ttcbs[i].next=&tcbs[i+1];"
+ "\t}"
+ }
+ }
+ Transition tr1: Operational -> Operational {
+ triggers {
+ <startTimeout: timer>
+ }
+ action {
+ "etTimerControlBlock*timer=getTcb();"
+ "etTime t;"
+ "if(timer!=0){"
+ "\tt.sec=time/1000;"
+ "\tt.nSec=(time%1000)*1000000L;"
+ "\ttimer->pTime.sec=0;"
+ "\ttimer->pTime.nSec=0;"
+ "\ttimer->portIdx=((etReplSubPort*)ifitem)->index;"
+ "\tgetTimeFromTarget(&(timer->expTime));"
+ "\taddTime(&(timer->expTime),&t);"
+ "\tputTcbToUsedList(timer);"
+ "\t}"
+ }
+ }
+ Transition tr3: Operational -> Operational {
+ triggers {
+ <startTimer: timer>
+ }
+ action {
+ "etTimerControlBlock*timer=getTcb();"
+ "etTime t;"
+ "if(timer!=0){"
+ "\tt.sec=time/1000;"
+ "\tt.nSec=(time%1000)*1000000L;"
+ "\ttimer->pTime=t;"
+ "\ttimer->portIdx=((etReplSubPort*)ifitem)->index;"
+ "\tgetTimeFromTarget(&(timer->expTime));"
+ "\taddTime(&(timer->expTime),&t);"
+ "\tputTcbToUsedList(timer);"
+ "\t}"
+ }
+ }
+ Transition tr4: Operational -> Operational {
+ triggers {
+ <kill: timer>
+ }
+ action {
+ "removeTcbFromUsedList(((etReplSubPort*)ifitem)->index);"
+ }
+ }
+ State Operational {
+ entry {
+ "/*prepare*/"
+ }
+ do {
+ "/*maintain timers*/"
+ "etTimerControlBlock*temp;"
+ "etTime t;"
+ ""
+ "getTimeFromTarget(&t);"
+ "while(usedTcbsRoot!=0){"
+ "\tif(isTimeGreater(&t,&(usedTcbsRoot->expTime))){"
+ "\t\ttimer[usedTcbsRoot->portIdx].timeout();"
+ "\t\ttemp=usedTcbsRoot;"
+ "\t\tusedTcbsRoot=usedTcbsRoot->next;"
+ "\t\tif((temp->pTime.sec==0)&&(temp->pTime.nSec==0)){"
+ "\t\t\t/*single shot timer*/"
+ "\t\t\treturnTcb(temp);"
+ "\t\t}else{"
+ "\t\t\t/*periodic timer*/"
+ "\t\t\taddTime(&temp->expTime,&temp->pTime);"
+ "\t\t\tputTcbToUsedList(temp);"
+ "\t\t\t}"
+ "\t\t}else{"
+ "\t\t\tbreak;"
+ "\t\t\t}"
+ "\t}"
+ }
+ }
+ }
+ }
+ }
+
+ ProtocolClass PTimer {
+ usercode1 {
+ "#define ET_TIMER_RUNNING 0x01"
+ "#define ET_TIMER_PERIODIC 0x02"
+ }
+ usercode2 {
+ "/*uc2*/"
+ }
+ incoming {
+ Message startTimer(time: uint32)
+ Message startTimeout(time: uint32)
+ Message kill()
+ }
+ outgoing {
+ Message timeout()
+ }
+ conjugated PortClass
+ {
+ handle incoming startTimer {
+ "if(status==0){"
+ "status=ET_TIMER_RUNNING|ET_TIMER_PERIODIC;"
+ "etPort_sendMessage(self,PTimer_IN_startTimer,sizeof(int32),&data__et);"
+ "}"
+ }
+ handle incoming startTimeout {
+ "if(status==0){"
+ "status=ET_TIMER_RUNNING;"
+ "etPort_sendMessage(self,PTimer_IN_startTimeout,sizeof(int32),&data__et);"
+ "}"
+ }
+ handle outgoing timeout {
+ "/*TODO:clear active bit in case of single shot timer*/"
+ "if(status!=0){"
+ "if(status==ET_TIMER_RUNNING){"
+ " /*single shot timer*/"
+ "status=0;"
+ " }"
+ " /*msg to fsm*/"
+ " (*receiveMessageFunc)(actor,self,msg);"
+ "}"
+ }
+ handle incoming kill {
+ "if(status!=0){"
+ "status=0;"
+ "etPort_sendMessage(self,PTimer_IN_kill,0,NULL);"
+ "}"
+ }
+ Attribute status: int8 = "0"
+ }
+ }
+ ExternalType tcb -> "etTimerControlBlock" default "{{0,0},{0,0},0,NULL}"
+ ExternalType targetTime -> "etTime" default "{0,0}"
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room
new file mode 100644
index 000000000..79ebd1a75
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatEqualsFormat/Types.room
@@ -0,0 +1,19 @@
+RoomModel room.basic.types {
+
+ PrimitiveType boolean: ptBoolean -> 'bool' default 'false'
+ PrimitiveType char: ptCharacter -> 'char' default '0'
+ PrimitiveType int8: ptInteger -> 'int8' default '0'
+ PrimitiveType int16: ptInteger -> 'int16' default '0'
+ PrimitiveType int32: ptInteger -> 'int32' default '0'
+ PrimitiveType int64: ptInteger -> 'int64' default '0'
+ PrimitiveType uint8: ptInteger -> 'uint8' default '0'
+ PrimitiveType uint16: ptInteger -> 'uint16' default '0'
+ PrimitiveType uint32: ptInteger -> 'uint32' default '0'
+ PrimitiveType uint64: ptInteger -> 'uint64' default '0'
+ PrimitiveType float32: ptReal -> 'float32' default '0'
+ PrimitiveType float64: ptReal -> 'float64' default '0'
+ PrimitiveType charPtr: ptCharacter -> 'charPtr' default '0'
+ PrimitiveType string: ptCharacter -> 'charPtr' default '0'
+ PrimitiveType etAddressId: ptInteger -> 'etAddressId' default '0'
+ ExternalType voidType -> 'void' default 'NULL'
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room
new file mode 100644
index 000000000..206e4690a
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/models/formatting/unformatted/DetailCode.room
@@ -0,0 +1,53 @@
+RoomModel DetailCode {
+
+ ActorClass ADetailCode {
+ Structure {
+ usercode1 {
+ "/*uc1*/"
+ }
+ usercode2 '''/*uc3*/'''
+ usercode3 '''
+ /*uc3*/'''
+ }
+ Behavior {
+ Operation op1() '''text\r\n'''
+ Operation op2() '''
+ text\r\n
+ '''
+ StateMachine {
+ State state {
+ entry '''dfd'''
+ exit '''d
+'''
+ }
+
+ Transition init : initial -> state {
+ action '''
+ /* maintain timers */
+ etTimerControlBlock* temp;
+ etTime t;
+
+ getTimeFromTarget(&t);
+ while (usedTcbsRoot != 0) {
+ if (isTimeGreater(&t, &(usedTcbsRoot->expTime))) {
+ timer_timeout(usedTcbsRoot->portIdx);
+ temp = usedTcbsRoot;
+ usedTcbsRoot = usedTcbsRoot->next;
+ if ((temp->pTime.sec == 0) && (temp->pTime.nSec == 0)) {
+ /* single shot timer */
+ returnTcb(temp);
+ } else {
+ /* periodic timer */
+ addTime(&temp->expTime, &temp->pTime);
+ putTcbToUsedList(temp);
+ }
+ } else {
+ break;
+ }
+ }
+ '''
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch b/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch
index 3fabf9600..6cb9c65b8 100644
--- a/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch
+++ b/tests/org.eclipse.etrice.core.room.tests/org.eclipse.etrice.core.room.tests.launch
@@ -11,7 +11,7 @@
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
-<booleanAttribute key="default" value="false"/>
+<booleanAttribute key="default" value="true"/>
<booleanAttribute key="includeOptional" value="false"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
@@ -36,7 +36,7 @@
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.platform.ide"/>
<booleanAttribute key="run_in_ui_thread" value="false"/>
-<stringAttribute key="selected_target_plugins" value="com.google.guava@default:default,com.google.inject@default:default,javax.inject@default:default,javax.xml@default:default,org.antlr.runtime@default:default,org.apache.log4j@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.win32.x86_64@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources.win32.x86_64@default:false,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi@-1:true,org.eclipse.xtend.core@default:default,org.eclipse.xtend.lib.macro@default:default,org.eclipse.xtend.lib@default:default,org.eclipse.xtext.common.types@default:default,org.eclipse.xtext.logging@default:false,org.eclipse.xtext.smap@default:default,org.eclipse.xtext.util@default:default,org.eclipse.xtext.xbase.lib@default:default,org.eclipse.xtext.xbase@default:default,org.eclipse.xtext@default:default,org.hamcrest.core@default:default,org.junit@default:default,org.objectweb.asm@default:default"/>
+<stringAttribute key="selected_target_plugins" value="com.google.guava*15.0.0.v201403281430@default:default,com.google.guava*21.0.0.v20170206-1425@default:default,com.google.inject@default:default,javax.inject@default:default,javax.xml@default:default,org.antlr.runtime*3.2.0.v201101311130@default:default,org.antlr.runtime*4.3.0.v201502022030@default:default,org.apache.log4j@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.win32.x86_64@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources.win32.x86_64@default:false,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi@-1:true,org.eclipse.xtend.core@default:default,org.eclipse.xtend.lib.macro@default:default,org.eclipse.xtend.lib@default:default,org.eclipse.xtext.common.types@default:default,org.eclipse.xtext.logging@default:false,org.eclipse.xtext.smap@default:default,org.eclipse.xtext.util@default:default,org.eclipse.xtext.xbase.lib@default:default,org.eclipse.xtext.xbase@default:default,org.eclipse.xtext@default:default,org.hamcrest.core@default:default,org.junit@default:default,org.objectweb.asm@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="org.eclipse.etrice.core.common@default:default,org.eclipse.etrice.core.fsm@default:default,org.eclipse.etrice.core.room.tests@default:default,org.eclipse.etrice.core.room@default:default,org.eclipse.etrice.logging@default:false"/>
<booleanAttribute key="show_selected_only" value="true"/>
<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
diff --git a/tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java b/tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java
new file mode 100644
index 000000000..cccecc6f5
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/src-gen/org/eclipse/etrice/core/room/tests/RoomInjectorProvider.java
@@ -0,0 +1,69 @@
+package org.eclipse.etrice.core.room.tests;
+/*
+ * generated by Xtext
+ */
+
+
+import org.eclipse.etrice.core.RoomRuntimeModule;
+import org.eclipse.etrice.core.RoomStandaloneSetup;
+import org.eclipse.xtext.junit4.GlobalRegistries;
+import org.eclipse.xtext.junit4.GlobalRegistries.GlobalStateMemento;
+import org.eclipse.xtext.junit4.IInjectorProvider;
+import org.eclipse.xtext.junit4.IRegistryConfigurator;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class RoomInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
+
+ protected GlobalStateMemento stateBeforeInjectorCreation;
+ protected GlobalStateMemento stateAfterInjectorCreation;
+ protected Injector injector;
+
+ static {
+ GlobalRegistries.initializeDefaults();
+ }
+
+ @Override
+ public Injector getInjector()
+ {
+ if (injector == null) {
+ stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
+ this.injector = internalCreateInjector();
+ stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
+ }
+ return injector;
+ }
+
+ protected Injector internalCreateInjector() {
+ return new RoomStandaloneSetup() {
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(createRuntimeModule());
+ }
+ }.createInjectorAndDoEMFRegistration();
+ }
+
+ protected RoomRuntimeModule createRuntimeModule() {
+ // make it work also with Maven/Tycho and OSGI
+ // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672
+ return new RoomRuntimeModule() {
+ @Override
+ public ClassLoader bindClassLoaderToInstance() {
+ return RoomInjectorProvider.class
+ .getClassLoader();
+ }
+ };
+ }
+
+ @Override
+ public void restoreRegistry() {
+ stateBeforeInjectorCreation.restoreGlobalState();
+ }
+
+ @Override
+ public void setupRegistry() {
+ getInjector();
+ stateAfterInjectorCreation.restoreGlobalState();
+ }
+}
diff --git a/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend
new file mode 100644
index 000000000..2a710a92d
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/src/org/eclipse/etrice/core/FormatterTest.xtend
@@ -0,0 +1,88 @@
+
+package org.eclipse.etrice.core
+
+import com.google.common.io.CharStreams
+import java.io.InputStreamReader
+import java.util.Map
+import java.util.regex.Pattern
+import org.eclipse.core.runtime.FileLocator
+import org.eclipse.emf.common.util.URI
+import org.eclipse.etrice.core.room.tests.RoomInjectorProvider
+import org.eclipse.xtext.junit4.InjectWith
+import org.eclipse.xtext.junit4.XtextRunner
+import org.eclipse.xtext.junit4.formatter.FormatterTester
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import static org.junit.Assert.*
+import static org.junit.Assert.assertNotEquals
+
+@RunWith(XtextRunner)
+@InjectWith(RoomInjectorProvider)
+class FormatterTest extends FormatterTester {
+
+ // does not work with comments or ccstring
+ val patterns = #[
+ Pattern.compile('''([^\w\s])\s+(\w)'''),
+ Pattern.compile('''([^\w\s])\s+([^\w\s])'''),
+ Pattern.compile('''(\w)\s+([^\w\s])''')
+ ]
+
+ @Test
+ def void unformatEqualsFormat(){
+
+ val expectedContents = newArrayList => [contents |
+ val entries = CoreTestsActivator.getInstance().getBundle().findEntries("models/formatting/unformatEqualsFormat/", "*.room", false)
+ while(entries.hasMoreElements) {
+ contents += CharStreams.toString(new InputStreamReader(FileLocator.toFileURL(entries.nextElement).openStream))
+ }
+ ]
+ assertTrue(!expectedContents.empty)
+
+ // expectation == format(unformat(expectation))
+ val (String) => String unformatter = [content |
+ val unformatted = patterns.fold(content, [replaced, pattern |pattern.matcher(replaced).replaceAll('$1$2')])
+ assertNotEquals(content, unformatted)
+ unformatted.replace('\r\n', ' ').replace('\n', ' ')
+ ]
+ expectedContents.forEach[expected |
+ println(unformatter.apply(expected))
+ assertFormatted[
+ expectation = expected
+ toBeFormatted = unformatter.apply(expected)
+ ]
+ ]
+ }
+
+ @Test
+ def void testManual(){
+
+ val (String) => Map<String, String> collector = [path |
+ val entries = CoreTestsActivator.getInstance().getBundle().findEntries(path, '*.room', false)
+ newHashMap => [contentMap |
+ while(entries.hasMoreElements) {
+ val entry = entries.nextElement
+ val name = URI.createURI(entry.toURI.toString).lastSegment
+ contentMap.put(name, CharStreams.toString(new InputStreamReader(FileLocator.toFileURL(entry).openStream)))
+ }
+ ]
+ ]
+
+ // fileName -> unformattedContent
+ val unformattedContents = collector.apply('models/formatting/expected/')
+ // fileName -> expectedContent
+ val expectedContents = collector.apply('models/formatting/expected/')
+
+ assertTrue(!unformattedContents.empty && expectedContents.keySet == unformattedContents.keySet)
+
+ // expectedContent == format(unformattedContent)
+ expectedContents.keySet.forEach[fileName |
+ assertFormatted[
+ expectation = expectedContents.get(fileName)
+ toBeFormatted = unformattedContents.get(fileName)
+ ]
+ ]
+ }
+
+
+}
diff --git a/tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java b/tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java
new file mode 100644
index 000000000..43be83aad
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.room.tests/xtend-gen/org/eclipse/etrice/core/FormatterTest.java
@@ -0,0 +1,161 @@
+package org.eclipse.etrice.core;
+
+import com.google.common.base.Objects;
+import com.google.common.io.CharStreams;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.etrice.core.CoreTestsActivator;
+import org.eclipse.etrice.core.room.tests.RoomInjectorProvider;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.junit4.formatter.FormatterTestRequest;
+import org.eclipse.xtext.junit4.formatter.FormatterTester;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.eclipse.xtext.xbase.lib.Functions.Function0;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.Functions.Function2;
+import org.eclipse.xtext.xbase.lib.InputOutput;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+
+@RunWith(XtextRunner.class)
+@InjectWith(RoomInjectorProvider.class)
+@SuppressWarnings("all")
+public class FormatterTest extends FormatterTester {
+ private final List<Pattern> patterns = new Function0<List<Pattern>>() {
+ public List<Pattern> apply() {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("([^\\w\\s])\\s+(\\w)");
+ Pattern _compile = Pattern.compile(_builder.toString());
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("([^\\w\\s])\\s+([^\\w\\s])");
+ Pattern _compile_1 = Pattern.compile(_builder_1.toString());
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append("(\\w)\\s+([^\\w\\s])");
+ Pattern _compile_2 = Pattern.compile(_builder_2.toString());
+ return Collections.<Pattern>unmodifiableList(CollectionLiterals.<Pattern>newArrayList(_compile, _compile_1, _compile_2));
+ }
+ }.apply();
+
+ @Test
+ public void unformatEqualsFormat() {
+ ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList();
+ final Procedure1<ArrayList<String>> _function = (ArrayList<String> contents) -> {
+ try {
+ CoreTestsActivator _instance = CoreTestsActivator.getInstance();
+ Bundle _bundle = _instance.getBundle();
+ final Enumeration<URL> entries = _bundle.findEntries("models/formatting/unformatEqualsFormat/", "*.room", false);
+ while (entries.hasMoreElements()) {
+ URL _nextElement = entries.nextElement();
+ URL _fileURL = FileLocator.toFileURL(_nextElement);
+ InputStream _openStream = _fileURL.openStream();
+ InputStreamReader _inputStreamReader = new InputStreamReader(_openStream);
+ String _string = CharStreams.toString(_inputStreamReader);
+ contents.add(_string);
+ }
+ } catch (Throwable _e) {
+ throw Exceptions.sneakyThrow(_e);
+ }
+ };
+ final ArrayList<String> expectedContents = ObjectExtensions.<ArrayList<String>>operator_doubleArrow(_newArrayList, _function);
+ boolean _isEmpty = expectedContents.isEmpty();
+ boolean _not = (!_isEmpty);
+ Assert.assertTrue(_not);
+ final Function1<String, String> _function_1 = (String content) -> {
+ String _xblockexpression = null;
+ {
+ final Function2<String, Pattern, String> _function_2 = (String replaced, Pattern pattern) -> {
+ Matcher _matcher = pattern.matcher(replaced);
+ return _matcher.replaceAll("$1$2");
+ };
+ final String unformatted = IterableExtensions.<Pattern, String>fold(this.patterns, content, _function_2);
+ Assert.assertNotEquals(content, unformatted);
+ String _replace = unformatted.replace("\r\n", " ");
+ _xblockexpression = _replace.replace("\n", " ");
+ }
+ return _xblockexpression;
+ };
+ final Function1<? super String, ? extends String> unformatter = _function_1;
+ final Consumer<String> _function_2 = (String expected) -> {
+ String _apply = unformatter.apply(expected);
+ InputOutput.<String>println(_apply);
+ final Procedure1<FormatterTestRequest> _function_3 = (FormatterTestRequest it) -> {
+ it.setExpectation(expected);
+ String _apply_1 = unformatter.apply(expected);
+ it.setToBeFormatted(_apply_1);
+ };
+ this.assertFormatted(_function_3);
+ };
+ expectedContents.forEach(_function_2);
+ }
+
+ @Test
+ public void testManual() {
+ final Function1<String, Map<String, String>> _function = (String path) -> {
+ HashMap<String, String> _xblockexpression = null;
+ {
+ CoreTestsActivator _instance = CoreTestsActivator.getInstance();
+ Bundle _bundle = _instance.getBundle();
+ final Enumeration<URL> entries = _bundle.findEntries(path, "*.room", false);
+ HashMap<String, String> _newHashMap = CollectionLiterals.<String, String>newHashMap();
+ final Procedure1<HashMap<String, String>> _function_1 = (HashMap<String, String> contentMap) -> {
+ try {
+ while (entries.hasMoreElements()) {
+ {
+ final URL entry = entries.nextElement();
+ URI _uRI = entry.toURI();
+ String _string = _uRI.toString();
+ org.eclipse.emf.common.util.URI _createURI = org.eclipse.emf.common.util.URI.createURI(_string);
+ final String name = _createURI.lastSegment();
+ URL _fileURL = FileLocator.toFileURL(entry);
+ InputStream _openStream = _fileURL.openStream();
+ InputStreamReader _inputStreamReader = new InputStreamReader(_openStream);
+ String _string_1 = CharStreams.toString(_inputStreamReader);
+ contentMap.put(name, _string_1);
+ }
+ }
+ } catch (Throwable _e) {
+ throw Exceptions.sneakyThrow(_e);
+ }
+ };
+ _xblockexpression = ObjectExtensions.<HashMap<String, String>>operator_doubleArrow(_newHashMap, _function_1);
+ }
+ return _xblockexpression;
+ };
+ final Function1<? super String, ? extends Map<String, String>> collector = _function;
+ final Map<String, String> unformattedContents = collector.apply("models/formatting/expected/");
+ final Map<String, String> expectedContents = collector.apply("models/formatting/expected/");
+ Assert.assertTrue(((!unformattedContents.isEmpty()) && Objects.equal(expectedContents.keySet(), unformattedContents.keySet())));
+ Set<String> _keySet = expectedContents.keySet();
+ final Consumer<String> _function_1 = (String fileName) -> {
+ final Procedure1<FormatterTestRequest> _function_2 = (FormatterTestRequest it) -> {
+ String _get = expectedContents.get(fileName);
+ it.setExpectation(_get);
+ String _get_1 = unformattedContents.get(fileName);
+ it.setToBeFormatted(_get_1);
+ };
+ this.assertFormatted(_function_2);
+ };
+ _keySet.forEach(_function_1);
+ }
+}

Back to the top