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 3e03d5af0cfb3b0c67d1bfe2eb0dc332e60c174d..061a85c2a66d916c2ea69550fd42fe0aed6a81bb 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 0000000000000000000000000000000000000000..7a5c3d5f5243c942220593eb24e279207d908e2a --- /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 4a8802f05c7cfb3b8afb7189982fa13151347909..477d165584cc542cc1e97177b9acf0e0f63afbd0 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 7fe5b4bdc9a397c61d21f4dd09749b36920cef4a..a46a23abda9a5739abf12f3e730d7afb7c21e5f7 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()") }