From 659e50139dfb4614b791596e155f37fd7a6a2ad4 Mon Sep 17 00:00:00 2001
From: Chrissi <christopher@hbsc-werner.de>
Date: Tue, 11 Jun 2019 20:50:48 +0200
Subject: [PATCH] add new remove element from set in sync process

---
 .../generator/acr_model/SSetterAdd.scala      |  2 +-
 .../generator/acr_model/SSetterRemove.scala   | 16 +++++
 .../sync/GetterSetterGeneratingVisitor.scala  |  2 +
 .../generator/sync/SyncEnhancingVisitor.scala | 60 ++++++++++---------
 4 files changed, 52 insertions(+), 28 deletions(-)
 create mode 100644 src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterRemove.scala

diff --git a/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterAdd.scala b/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterAdd.scala
index 3e03d5a..061a85c 100644
--- a/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterAdd.scala
+++ b/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterAdd.scala
@@ -5,7 +5,7 @@ import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
 
 /** Add an element to a Set of elements.
   *
-  * @author Rico Bergmann
+  * @author Christopher Werner
   */
 class SSetterAdd(struc: SStructuralFeature, inner: STypedElement) extends SMethod(
   name = s"add${struc.getName.firstLetterToUpperCase}",
diff --git a/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterRemove.scala b/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterRemove.scala
new file mode 100644
index 0000000..7a5c3d5
--- /dev/null
+++ b/src/main/scala/org/rosi_project/model_sync/generator/acr_model/SSetterRemove.scala
@@ -0,0 +1,16 @@
+package org.rosi_project.model_sync.generator.acr_model
+
+import org.rosi_project.model_sync.generator.support.ExtendedString.stringToExtended
+import org.rosi_project.model_sync.generator.acr_model.types.PredefTypes
+
+/** Remove an element from a Set of elements.
+  *
+  * @author Christopher Werner
+  */
+class SSetterRemove(struc: SStructuralFeature, inner: STypedElement) extends SMethod(
+  name = s"remove${struc.getName.firstLetterToUpperCase}",
+  result = PredefTypes.Unit,
+  params = Seq(SMethodParameter(struc.getName.head.toString, inner)),
+  implementation = Seq(SMethodStatement(content = s"${struc.getName} -= ${struc.getName.head}", usedTypes = Set(struc.getTypeElement)))) {
+
+}
\ No newline at end of file
diff --git a/src/main/scala/org/rosi_project/model_sync/generator/sync/GetterSetterGeneratingVisitor.scala b/src/main/scala/org/rosi_project/model_sync/generator/sync/GetterSetterGeneratingVisitor.scala
index 4a8802f..477d165 100644
--- a/src/main/scala/org/rosi_project/model_sync/generator/sync/GetterSetterGeneratingVisitor.scala
+++ b/src/main/scala/org/rosi_project/model_sync/generator/sync/GetterSetterGeneratingVisitor.scala
@@ -23,6 +23,8 @@ class GetterSetterGeneratingVisitor extends SModelVisitor {
       if (attr.getTypeElement.isInstanceOf[GenericSequence]) {
         val adder = new SSetterAdd(attr, attr.getTypeElement.asInstanceOf[GenericSequence].typeParam)
         sClass.addMethod(adder)
+        val remover = new SSetterRemove(attr, attr.getTypeElement.asInstanceOf[GenericSequence].typeParam)
+        sClass.addMethod(remover)
       }
     })
 
diff --git a/src/main/scala/org/rosi_project/model_sync/generator/sync/SyncEnhancingVisitor.scala b/src/main/scala/org/rosi_project/model_sync/generator/sync/SyncEnhancingVisitor.scala
index 7fe5b4b..a46a23a 100644
--- a/src/main/scala/org/rosi_project/model_sync/generator/sync/SyncEnhancingVisitor.scala
+++ b/src/main/scala/org/rosi_project/model_sync/generator/sync/SyncEnhancingVisitor.scala
@@ -2,17 +2,18 @@ package org.rosi_project.model_sync.generator.sync
 
 import org.rosi_project.model_sync.generator.acr_model._
 
-/** Augments [[SClass SClasses]] with the necessary method calls to make it usable in a
-  * synchronization context.
-  *
-  * The following modifications are performed:
-  *  - the class (or its furthest parent) becomes a subclass of [[PlayerSync]]
-  *  - [[PlayerSync.buildClass()]] will be called in the constructor
-  *  - each setter will notify the synchronization context about the change
-  *
-  * @see [[ISynchronizationCompartment]]
-  * @author Rico Bergmann
-  */
+/**
+ * Augments [[SClass SClasses]] with the necessary method calls to make it usable in a
+ * synchronization context.
+ *
+ * The following modifications are performed:
+ *  - the class (or its furthest parent) becomes a subclass of [[PlayerSync]]
+ *  - [[PlayerSync.buildClass()]] will be called in the constructor
+ *  - each setter will notify the synchronization context about the change
+ *
+ * @see [[ISynchronizationCompartment]]
+ * @author Rico Bergmann
+ */
 class SyncEnhancingVisitor() extends SModelVisitor {
 
   override def visit(sModel: SModel): Unit = {
@@ -29,7 +30,7 @@ class SyncEnhancingVisitor() extends SModelVisitor {
   override def visit(sAttr: SAttribute): Unit = {
     // pass
   }
-  
+
   override def visit(sRef: SReference): Unit = {
     // pass
   }
@@ -42,25 +43,28 @@ class SyncEnhancingVisitor() extends SModelVisitor {
     // pass
   }
 
-  /** Tries to get the attribute's name from a setter method.
-    *
-    * A ''valid'' setter will have the following signature: `setXyz(x: T): Unit` (the parameter's
-    * name does not matter).
-    *
-    * Mind that the first letter will be left uppercase (i.e. `Xyz` will be returned although the
-    * actual attribute may be `xyz`)
-    *
-    * @param sMethod the method to analyze. May be any method (not necessarily a setter) but never
-    *                `null`.
-    * @return the attribute's name if `sMethod` was a valid setter. '''The first letter will be left
-    *         uppercase.'''
-    */
+  /**
+   * Tries to get the attribute's name from a setter method.
+   *
+   * A ''valid'' setter will have the following signature: `setXyz(x: T): Unit` (the parameter's
+   * name does not matter).
+   *
+   * Mind that the first letter will be left uppercase (i.e. `Xyz` will be returned although the
+   * actual attribute may be `xyz`)
+   *
+   * @param sMethod the method to analyze. May be any method (not necessarily a setter) but never
+   *                `null`.
+   * @return the attribute's name if `sMethod` was a valid setter. '''The first letter will be left
+   *         uppercase.'''
+   */
   private def extractSetterAttr(sMethod: SMethod): Option[String] = {
     sMethod.getName match {
       case SyncEnhancingVisitor.Setter(attrName) =>
         Option(attrName)
       case SyncEnhancingVisitor.Adder(attrName) =>
         Option(attrName)
+      case SyncEnhancingVisitor.Remover(attrName) =>
+        Option(attrName)
       case _ =>
         None
     }
@@ -69,10 +73,12 @@ class SyncEnhancingVisitor() extends SModelVisitor {
 
 }
 
-/** The companion contains some static values.
-  */
+/**
+ * The companion contains some static values.
+ */
 object SyncEnhancingVisitor {
   private val Setter = """set([A-Z][a-zA-z0-9]*)""".r
   private val Adder = """add([A-Z][a-zA-z0-9]*)""".r
+  private val Remover = """remove([A-Z][a-zA-z0-9]*)""".r
   private val PLAYER_SYNC_INIT = SMethodStatement("buildClass()")
 }
-- 
GitLab