From 4217aec071c902bffae68dc0c6ba1d73385ac12b Mon Sep 17 00:00:00 2001 From: kevin-delmas Date: Thu, 12 Dec 2024 17:36:45 +0100 Subject: [PATCH] Refactor code for compliance to linting --- .scalafix.conf | 85 +++++++++++++++++++ build.sbt | 8 +- project/plugins.sbt | 1 + .../pml/examples/mySys/MyProcPlatform.scala | 2 +- .../SimpleKeystonePlatform.scala | 2 +- .../simpleT1042/SimpleT1042Platform.scala | 2 +- .../pml/exporters/FileManager.scala | 6 +- .../pml/exporters/RelationExporter.scala | 24 +++--- .../pml/model/hardware/Composite.scala | 14 +-- .../model/relations/AuthorizeRelation.scala | 2 +- .../pml/model/relations/LinkRelation.scala | 2 +- .../pml/model/relations/ProvideRelation.scala | 2 +- .../pml/model/relations/RoutingRelation.scala | 2 +- .../pml/model/relations/UseRelation.scala | 2 +- .../pmlanalyzer/pml/model/utils/Message.scala | 2 +- .../pmlanalyzer/pml/model/utils/Owner.scala | 2 +- .../pmlanalyzer/pml/operators/Provided.scala | 9 +- .../pmlanalyzer/pml/operators/Route.scala | 4 +- .../dependability/executor/Simulator.scala | 4 +- .../exporters/AutomatonCeciliaExporter.scala | 4 +- .../BasicOperationCeciliaExporter.scala | 10 +-- .../exporters/CeciliaExporter.scala | 2 +- .../exporters/ExprCeciliaExporter.scala | 4 +- .../dependability/exporters/Folder.scala | 19 +++-- .../views/dependability/exporters/Model.scala | 56 +++++++----- .../exporters/PlatformCeciliaExporter.scala | 2 +- .../views/dependability/model/Copy.scala | 2 +- .../views/dependability/model/Event.scala | 12 +-- .../views/dependability/model/Id.scala | 10 +-- .../dependability/model/ModeAutomaton.scala | 2 +- .../views/dependability/model/System.scala | 4 +- .../views/dependability/model/Target.scala | 2 - .../dependability/model/Transition.scala | 2 +- .../dependability/model/Transporter.scala | 2 +- .../views/dependability/model/Variable.scala | 30 +++---- .../dependability/operators/IsFinite.scala | 2 +- .../model/formalisation/BDDFactory.scala | 13 +-- .../model/formalisation/ProblemElement.scala | 36 ++++---- .../model/relations/EquivalenceRelation.scala | 2 +- .../model/relations/ExclusiveRelation.scala | 2 +- .../model/relations/InterfereRelation.scala | 2 +- .../relations/NotInterfereRelation.scala | 2 +- .../model/relations/TransparentSet.scala | 2 +- .../InterferenceSpecification.scala | 8 +- .../TableBasedInterferenceSpecification.scala | 5 +- .../interference/operators/Analyse.scala | 2 +- .../interference/operators/PostProcess.scala | 2 +- .../patterns/examples/PhylogPatterns.scala | 7 +- .../patterns/exporters/LatexCodePrinter.scala | 22 ++--- .../exporters/LatexDiagramPrinter.scala | 2 +- .../views/patterns/model/PatternAST.scala | 30 +++---- .../configuration/ConfigurationTest.scala | 2 +- .../InterferenceTestExtension.scala | 4 +- 53 files changed, 285 insertions(+), 198 deletions(-) create mode 100644 .scalafix.conf diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..eff1034 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,85 @@ +rules = [ + DisableSyntax + LeakingImplicitClassVal + NoValInForComprehension + RedundantSyntax + NoAutoTupling + ArrayEquals, + ArraysInFormat, + ArraysToString, + AvoidSizeEqualsZero, + AvoidSizeNotEqualsZero, + AvoidToMinusOne, + BigDecimalScaleWithoutRoundingMode, + BoundedByFinalType, + BrokenOddness, + CatchException, + CatchExceptionImmediatelyRethrown, + CatchFatal, + CatchNpe, + CatchThrowable, + ClassNames, + CollectionNamingConfusion, + CollectionNegativeIndex, + ComparingFloatingPointTypes, + ComparisonToEmptyList, + ComparisonToEmptySet, + ComparisonWithSelf, + ConstantIf, + DivideByOne, + DoubleNegation, + DuplicateMapKey, + DuplicateSetValue, + EitherGet, + EmptyCaseClass, + EmptyFor, + EmptyIfBlock, + EmptyInterpolatedString, + EmptyMethod, + EmptySynchronizedBlock, + EmptyTryBlock, + EmptyWhileBlock, + FilterDotHead, + FilterDotHeadOption, + FilterDotIsEmpty, + FilterDotSize, + FilterOptionAndGet, + FinalModifierOnCaseClass, + FinalizerWithoutSuper, + FindAndNotEqualsNoneReplaceWithExists, + FindDotIsDefined, + IllegalFormatString, + ImpossibleOptionSizeCondition, + IncorrectNumberOfArgsToFormat, + IncorrectlyNamedExceptions, + InterpolationToString, + InvalidRegexTest, + //Not reliable with givens: LonelySealedTrait, + MapGetAndGetOrElse, + MethodReturningAny, + NanComparison, + NullAssignment, + NullParameter, + OptionGet, + OptionSize, + RepeatedCaseBody, + RepeatedIfElseBody, + StripMarginOnRegex, + SwallowedException, + TryGet, + UnreachableCatch, + UnsafeContains, + UnsafeStringContains, + //Would be nice to have: UnsafeTraversableMethods, + //Not reliable with implicits: UnusedMethodParameter, + VarCouldBeVal, + VariableShadowing, + WhileTrue +] +// Would be nice to add : DisableSyntax.noThrows = true +DisableSyntax.noNulls = true +DisableSyntax.noReturns = true +// Would be nice to add : DisableSyntax.noAsInstanceOf = true +// Would be nice to add : DisableSyntax.noIsInstanceOf = true +DisableSyntax.noFinalize = true +DisableSyntax.noValPatterns = true \ No newline at end of file diff --git a/build.sbt b/build.sbt index 1867257..c255f9c 100644 --- a/build.sbt +++ b/build.sbt @@ -97,10 +97,14 @@ lazy val commonSettings = Seq( crossPaths := false, publishTo := Some("releases" at "https://s01.oss.sonatype.org/" + "service/local/staging/deploy/maven2"), publishMavenStyle := true, - version := "1.0.1", + version := "1.1.0", scalaVersion := "3.2.2", sbtVersion := "1.8.2", - scalacOptions := Seq("-unchecked", "-deprecation", "-feature"), + scalafixOnCompile := true, + semanticdbEnabled := true, + scalafixDependencies += "io.github.dedis" %% "scapegoat-scalafix" % "1.1.4", + semanticdbVersion := scalafixSemanticdb.revision, + scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-Werror"), resolvers ++= Resolver.sonatypeOssRepos("releases"), resolvers ++= Resolver.sonatypeOssRepos("snapshots"), libraryDependencies ++= Seq( diff --git a/project/plugins.sbt b/project/plugins.sbt index 24d15ca..32b4153 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,3 +2,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0") addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.9.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1") diff --git a/src/main/scala/onera/pmlanalyzer/pml/examples/mySys/MyProcPlatform.scala b/src/main/scala/onera/pmlanalyzer/pml/examples/mySys/MyProcPlatform.scala index d2b9b9b..f6bceda 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/examples/mySys/MyProcPlatform.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/examples/mySys/MyProcPlatform.scala @@ -101,7 +101,7 @@ class MyProcPlatform(name: Symbol) extends Platform(name) { /** Composite representing Keystone ARM cores and their internal L1 cache * @group composite_def */ - class ARMCore(name: Symbol) extends Composite(name) { + class ARMCore(armName: Symbol) extends Composite(armName) { /** * Enable to provide the name implicitly diff --git a/src/main/scala/onera/pmlanalyzer/pml/examples/simpleKeystone/SimpleKeystonePlatform.scala b/src/main/scala/onera/pmlanalyzer/pml/examples/simpleKeystone/SimpleKeystonePlatform.scala index 542f16a..25c9812 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/examples/simpleKeystone/SimpleKeystonePlatform.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/examples/simpleKeystone/SimpleKeystonePlatform.scala @@ -101,7 +101,7 @@ class SimpleKeystonePlatform(name: Symbol) extends Platform(name) { /** Composite representing Keystone ARM cores and their internal L1 cache * @group composite_def */ - class ARMCore(name: Symbol) extends Composite(name) { + class ARMCore(armName: Symbol) extends Composite(armName) { /** * Enable to provide the name implicitly diff --git a/src/main/scala/onera/pmlanalyzer/pml/examples/simpleT1042/SimpleT1042Platform.scala b/src/main/scala/onera/pmlanalyzer/pml/examples/simpleT1042/SimpleT1042Platform.scala index 1c5bb29..5221088 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/examples/simpleT1042/SimpleT1042Platform.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/examples/simpleT1042/SimpleT1042Platform.scala @@ -37,7 +37,7 @@ class SimpleT1042Platform(name: Symbol) extends Platform(name) { * ----------------------------------------------------------- */ // Composite representing cores and their internal L1 cache - class CachedCore(name: Symbol) extends Composite(name) { + class CachedCore(coreName: Symbol) extends Composite(coreName) { def this()(implicit implicitName: Name) = { this(implicitName.value) diff --git a/src/main/scala/onera/pmlanalyzer/pml/exporters/FileManager.scala b/src/main/scala/onera/pmlanalyzer/pml/exporters/FileManager.scala index 53ca240..9719ca5 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/exporters/FileManager.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/exporters/FileManager.scala @@ -55,11 +55,11 @@ object FileManager { /** * find recursively a file by its name - * @param name name of the file to find + * @param fileName name of the file to find * @return the java File if found */ - def locate(name: String) : Option[File] = - OutputDirectory.recursiveLocateFirstFile(directory, (f: File) => f.getName == name) + def locate(fileName: String) : Option[File] = + OutputDirectory.recursiveLocateFirstFile(directory, (f: File) => f.getName == fileName) } diff --git a/src/main/scala/onera/pmlanalyzer/pml/exporters/RelationExporter.scala b/src/main/scala/onera/pmlanalyzer/pml/exporters/RelationExporter.scala index a6a10e3..e647951 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/exporters/RelationExporter.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/exporters/RelationExporter.scala @@ -59,6 +59,8 @@ object RelationExporter { * @param platform the platform providing the export features */ implicit class Ops(platform: Platform) { + import platform._ + private val routingExportName: String = platform.fullName + "RouteTable.txt" private val swAllocationExportName: String = platform.fullName + "AllocationTable.txt" private val dataAllocationExportName: String = platform.fullName + "DataTable.txt" @@ -79,7 +81,7 @@ object RelationExporter { */ def exportRouteTable(): Unit = { val writer = getWriter(routingExportName) - writer.write(s"Initiator, TargetService, Router, NextService(s)\n") + writer.write("Initiator, TargetService, Router, NextService(s)\n") platform.InitiatorRouting._values .map(p => s"${p._1._1}, ${p._1._2}, ${p._1._3}, ${p._2.toSeq.sortBy(_.name.name).mkString(", ")}\n") .toSeq @@ -97,7 +99,7 @@ object RelationExporter { */ def exportAllocationTable(): Unit = { val writer = getWriter(swAllocationExportName) - writer.write(s"Software, Initiator(s)\n") + writer.write("Software, Initiator(s)\n") platform.SWUseInitiator._values .map(p => s"${p._1}, ${p._2.toSeq.sortBy(_.name.name).mkString(", ")}\n") .toSeq @@ -115,8 +117,7 @@ object RelationExporter { */ def exportDataAllocationTable(): Unit = { val writer = getWriter(dataAllocationExportName) - writer.write(s"Data, Target\n") - import platform._ + writer.write("Data, Target\n") for (d <- Data.all.toSeq.sortBy(_.name.name)) writer.write(s"$d, ${d.hostingTargets.mkString(",")}\n") writer.flush() @@ -131,7 +132,7 @@ object RelationExporter { */ def exportSWTargetUsageTable(): Unit = { val writer = getWriter(swTargetUsage) - writer.write(s"Software, Target Service(s)\n") + writer.write("Software, Target Service(s)\n") platform.SWUseService._values .map(p => s"${p._1}, ${p._2.toSeq.sortBy(_.name.name).mkString(", ")}\n") .toSeq @@ -153,8 +154,7 @@ object RelationExporter { */ def exportDeactivatedComponents(): Unit = { val writer = getWriter(componentStatus) - writer.write(s"Component, Activated, Used\n") - import platform._ + writer.write("Component, Activated, Used\n") val restricted = platform.hardwareGraph() val hwLinks = restricted flatMap { p => p._2 map { x => (p._1, x) } } val used = hwLinks.flatMap { p => Set(p._1, p._2) }.toSet @@ -193,7 +193,7 @@ object RelationExporter { */ def exportPhysicalTransactions(): Unit = { val writer = getWriter(transactionTable) - writer.write(s"Transaction Name, Transaction Path\n") + writer.write("Transaction Name, Transaction Path\n") import platform._ for { (n,t) <- transactionsByName.toSeq.sortBy(_.toString()) @@ -210,6 +210,8 @@ object RelationExporter { * @param platform the configured platform with a library */ implicit class OpsLibrary(platform: Platform with TransactionLibrary) { + + import platform._ private def getWriter(name: String): FileWriter = { val file = FileManager.exportDirectory.getFile(name) @@ -227,8 +229,7 @@ object RelationExporter { */ def exportUserTransactions(): Unit = { val writer = getWriter(transactionTable) - writer.write(s"Transaction Name, Transaction Path\n") - import platform._ + writer.write("Transaction Name, Transaction Path\n") for { (n,t) <- transactionByUserName.toSeq.sortBy(_.toString()) } yield @@ -245,8 +246,7 @@ object RelationExporter { */ def exportUserScenarios(): Unit = { val writer = getWriter(scenarioTable) - writer.write(s"Scenario Name, Scenario Path\n") - import platform._ + writer.write("Scenario Name, Scenario Path\n") for { (n,s) <- scenarioByUserName.toSeq.sortBy(_._1.toString) t = s.map(transactionsByName).map( x => diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/Composite.scala b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/Composite.scala index fd4d828..b4f54ea 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/Composite.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/Composite.scala @@ -72,21 +72,21 @@ abstract class Composite(n: Symbol, _owner:Owner) extends Hardware { /** * Alternative constructor without implicit owner - * @param name the name of the composite + * @param compositeName the name of the composite * @param dummy dummy argument to avoid method signature conflict - * @param owner the implicit owner + * @param implicitOwner the implicit owner */ - def this(name: Symbol, dummy: Int = 0)(implicit owner: Owner) = { - this(name, owner) + def this(compositeName: Symbol, dummy: Int = 0)(implicit implicitOwner: Owner) = { + this(compositeName, implicitOwner) } /** * Alternative constructor without name, nor owner * @param implicitName the implicit name provided by the enclosing object - * @param owner the implicit owner + * @param implicitOwner the implicit owner */ - def this()(implicit implicitName: Name, owner: Owner) = { - this(Symbol(implicitName.value), owner) + def this()(implicit implicitName: Name, implicitOwner: Owner) = { + this(Symbol(implicitName.value), implicitOwner) } } diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/relations/AuthorizeRelation.scala b/src/main/scala/onera/pmlanalyzer/pml/model/relations/AuthorizeRelation.scala index 3233ea4..ca96455 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/relations/AuthorizeRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/relations/AuthorizeRelation.scala @@ -27,7 +27,7 @@ import onera.pmlanalyzer.pml.model.software.Application * @tparam L the left type * @tparam R the right type */ -case class AuthorizeRelation[L, R] private(iniValues: Map[L, Set[R]]) extends Relation[L, R](iniValues) +final case class AuthorizeRelation[L, R] private(iniValues: Map[L, Set[R]]) extends Relation[L, R](iniValues) object AuthorizeRelation { /** diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/relations/LinkRelation.scala b/src/main/scala/onera/pmlanalyzer/pml/model/relations/LinkRelation.scala index c99ece0..ff15933 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/relations/LinkRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/relations/LinkRelation.scala @@ -27,7 +27,7 @@ import sourcecode.Name * @param iniValues initial values of the relation * @tparam A the elements type */ -case class LinkRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends Endomorphism[A](iniValues) +final case class LinkRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends Endomorphism[A](iniValues) object LinkRelation { /** diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/relations/ProvideRelation.scala b/src/main/scala/onera/pmlanalyzer/pml/model/relations/ProvideRelation.scala index f91568b..25767f7 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/relations/ProvideRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/relations/ProvideRelation.scala @@ -28,7 +28,7 @@ import sourcecode.Name * @tparam L the left type * @tparam R the right type */ -case class ProvideRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues) +final case class ProvideRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues) object ProvideRelation { /** diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/relations/RoutingRelation.scala b/src/main/scala/onera/pmlanalyzer/pml/model/relations/RoutingRelation.scala index 5b4e85d..48e3a41 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/relations/RoutingRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/relations/RoutingRelation.scala @@ -28,7 +28,7 @@ import sourcecode.Name * @tparam L the left type * @tparam R the right type */ -case class RoutingRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues) +final case class RoutingRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues) object RoutingRelation { /** diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/relations/UseRelation.scala b/src/main/scala/onera/pmlanalyzer/pml/model/relations/UseRelation.scala index d521c79..56aef0a 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/relations/UseRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/relations/UseRelation.scala @@ -29,7 +29,7 @@ import sourcecode.Name * @tparam L the left type * @tparam R the right type */ -case class UseRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues) +final case class UseRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues) object UseRelation { /** diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/utils/Message.scala b/src/main/scala/onera/pmlanalyzer/pml/model/utils/Message.scala index 0eba942..3763d0b 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/utils/Message.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/utils/Message.scala @@ -33,7 +33,7 @@ object Message { s"[WARNING] The physical transaction $userName is not possible, check your link and route constraints" inline def impossibleRouteWarning(t:Service, from:Option[Application]): String = - s"""[WARNING] The target service $t cannot be reached ${if (from.isDefined) s"from ${from.get}" else ""}""" + s"""[WARNING] The target service $t cannot be reached ${if (from.isDefined) s"from ${from.getOrElse("unknown application")}" else ""}""" inline def multiPathTransactionWarning(userName: UserTransactionId, list: Iterable[(PhysicalTransactionId, PhysicalTransaction)]): String = s"""[WARNING] The transaction $userName addresses multiple physical transactions: diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/utils/Owner.scala b/src/main/scala/onera/pmlanalyzer/pml/model/utils/Owner.scala index 75081c7..51abb67 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/utils/Owner.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/utils/Owner.scala @@ -22,4 +22,4 @@ package onera.pmlanalyzer.pml.model.utils * * @param s the owner's name */ -case class Owner(s: Symbol) +final case class Owner(s: Symbol) diff --git a/src/main/scala/onera/pmlanalyzer/pml/operators/Provided.scala b/src/main/scala/onera/pmlanalyzer/pml/operators/Provided.scala index 8e34ccc..f6e596d 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/operators/Provided.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/operators/Provided.scala @@ -17,11 +17,6 @@ package onera.pmlanalyzer.pml.operators -import onera.pmlanalyzer.pml.model.hardware.{Composite, Hardware, Initiator, Platform, SimpleTransporter, Target, Transporter, Virtualizer} -import onera.pmlanalyzer.pml.model.relations.ProvideRelation -import onera.pmlanalyzer.pml.model.service.{Load, Service, Store} -import onera.pmlanalyzer.pml.model.software.Data -import onera.pmlanalyzer.pml.model.utils.Owner import onera.pmlanalyzer.pml.model.hardware.* import onera.pmlanalyzer.pml.model.relations.ProvideRelation import onera.pmlanalyzer.pml.model.service.{Load, Service, Store} @@ -133,7 +128,7 @@ object Provided { * @return set of declared component */ def directHardware: Set[Hardware] = { - import self._ + import self.* Initiator.allDirect ++ Target.allDirect ++ Virtualizer.allDirect ++ SimpleTransporter.allDirect ++ Composite.allDirect } } @@ -205,7 +200,7 @@ object Provided { given[L <: Platform: Typeable]: Provided[L, Hardware] with { def apply(a: L): Set[Hardware] = { - import a._ + import a.* Initiator.all ++ Target.all ++ Virtualizer.all ++ SimpleTransporter.all } diff --git a/src/main/scala/onera/pmlanalyzer/pml/operators/Route.scala b/src/main/scala/onera/pmlanalyzer/pml/operators/Route.scala index 534fb2e..c1ea909 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/operators/Route.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/operators/Route.scala @@ -88,7 +88,7 @@ object Route { * @param a the initiator * @param targets the set of targets */ - case class SimpleRouteIdentifyRouter(a: Initiator, targets: Iterable[Target]) { + final case class SimpleRouteIdentifyRouter(a: Initiator, targets: Iterable[Target]) { /** * PML keyword to specify the hardware routing the transactions @@ -148,7 +148,7 @@ object Route { * @param router the router * @param forbid if it is a blocking or routing constraint */ - case class SimpleRouterIdentifyNext(a: Initiator, targets: Iterable[Target], router: Hardware, forbid:Boolean) { + final case class SimpleRouterIdentifyNext(a: Initiator, targets: Iterable[Target], router: Hardware, forbid:Boolean) { /** * PML keyword to specify the link from [[router]] that is routed or blocked diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/executor/Simulator.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/executor/Simulator.scala index c9266af..5beefa3 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/executor/Simulator.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/executor/Simulator.scala @@ -44,9 +44,9 @@ object Simulator { } } - val immediate = fireable.collect { case e@DetermisticEvent(_, _, 0) => e } + val immediate = fireable.collect { case e@DeterministicEvent(_, _, 0) => e } if (immediate.isEmpty) { - val det = fireable.collect { case e@DetermisticEvent(_, _, i) if i != 0 => e } + val det = fireable.collect { case e@DeterministicEvent(_, _, i) if i != 0 => e } if (det.nonEmpty) { val min = det.minBy(_.delay).delay det.filter(_.delay == min) match { diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/AutomatonCeciliaExporter.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/AutomatonCeciliaExporter.scala index cd3b6fa..97d4fe2 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/AutomatonCeciliaExporter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/AutomatonCeciliaExporter.scala @@ -32,7 +32,7 @@ trait AutomatonCeciliaExporter { val events = allOf[T].flatMap(to => allOf[T].collect({ case from if from < to => - StochastiqueEventModel(x.eventMap(to.name).name) + StochasticEventModel(x.eventMap(to.name).name) })).toList.distinct val transitions = allOf[T].flatMap(to => allOf[T].collect({ @@ -80,7 +80,7 @@ trait AutomatonCeciliaExporter { val events = allOf[T].flatMap(to => allOf[T].collect({ case from if from < to => - StochastiqueEventModel(x.eventMap(to.name).name) + StochasticEventModel(x.eventMap(to.name).name) })).toList.distinct :+ DeterministicEventModel(x.epsilon.name) val transitionsFailure = allOf[T].flatMap(to => allOf[T].collect({ diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/BasicOperationCeciliaExporter.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/BasicOperationCeciliaExporter.scala index 798d8c1..db93b8f 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/BasicOperationCeciliaExporter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/BasicOperationCeciliaExporter.scala @@ -79,7 +79,7 @@ trait BasicOperationCeciliaExporter { Flow(Symbol("i1"), tyype, In) :: Flow(Symbol("i2"), tyype, In) :: Flow(Symbol("o"), CeciliaBoolean, Out) :: Nil, Nil, Nil, - s"""assert + """assert |o = (i1 = i2); |icone = (if o then 1 else 2); """.stripMargin) @@ -136,7 +136,7 @@ trait BasicOperationCeciliaExporter { (s"$subName.${model.result}",worstAssertions,SubComponent(Symbol(subName),model.model)) }) - private case class BestModelHelper[T: IsFinite : IsCriticityOrdering](size: Int) { + private final case class BestModelHelper[T: IsFinite : IsCriticityOrdering](size: Int) { val tyype: EnumeratedType = typeModel[T] val inputs: List[Flow] = (1 to size).map(i => Flow(Symbol(s"i$i"), tyype, In)).toList val operatorModel: OperatorModel = minOperator[T](size) @@ -181,7 +181,7 @@ trait BasicOperationCeciliaExporter { (s"$subName.${model.result}",worstAssertions,SubComponent(Symbol(subName),model.model)) }) - private case class WorstModelHelper[T: IsFinite : IsCriticityOrdering](size: Int) { + private final case class WorstModelHelper[T: IsFinite : IsCriticityOrdering](size: Int) { private val tyype = typeModel[T] val inputs: List[Flow] = (1 to size).map(i => Flow(Symbol(s"i$i"), tyype, In)).toList val result: Flow = Flow(Symbol("o"), tyype,Out) @@ -276,7 +276,7 @@ trait BasicOperationCeciliaExporter { ) } - case class WorstSchedulerTopHelper(size:Int) { + final case class WorstSchedulerTopHelper(size:Int) { val sonDirection: List[Flow] = (1 to size).map(i => Flow(Symbol(s"sonDirection$i"), typeModel[Direction.Value], In)).toList val fireOrders: List[Flow] = (1 to size).map(i => Flow(Symbol(s"sonFire$i"), typeModel[Fire.Value], Out)).toList private val fireOrdersAssertions = fireOrders.zip(sonDirection).map( p => @@ -301,7 +301,7 @@ trait BasicOperationCeciliaExporter { def authorizeOperator[FM: IsFinite]: OperatorModel = { val tyype = typeModel[FM] - val initial = Flow(Symbol(s"initial"), tyype, In) + val initial = Flow(Symbol("initial"), tyype, In) val reject = Flow(Symbol("reject"), CeciliaBoolean, In) val output = Flow(Symbol(s"authorize${nameOf[FM].name}"), tyype, Out) OperatorModel( diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/CeciliaExporter.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/CeciliaExporter.scala index f07128b..21108cc 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/CeciliaExporter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/CeciliaExporter.scala @@ -28,7 +28,7 @@ trait CeciliaExporter[T] { } trait CeciliaExporterOps { - implicit class ceciliaOps[T, O](x: T) { + implicit class CeciliaOps[T, O](x: T) { def toCecilia(implicit ev: CeciliaExporter.Aux[T, O]): O = ev.toCecilia(x) val ceciliaExportName : String = CeciliaExporter.ceciliaExportName(x) def exportAsCecilia(implicit ev: CeciliaExporter.Aux[T, O]) : Unit = { diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/ExprCeciliaExporter.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/ExprCeciliaExporter.scala index 77b46d3..009a23e 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/ExprCeciliaExporter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/ExprCeciliaExporter.scala @@ -24,7 +24,7 @@ import onera.pmlanalyzer.views.dependability.operators.allOf trait ExprCeciliaExporter { self:BasicOperationCeciliaExporter with TypeCeciliaExporter => - case class AssertionHelper(result:Map[TargetId,String], subComponentAssertions: Map[SubComponent, Seq[String]]) + final case class AssertionHelper(result:Map[TargetId,String], subComponentAssertions: Map[SubComponent, Seq[String]]) implicit def ExprCeciliaExporter[T] : Aux[Expr[T], AssertionHelper] = new CeciliaExporter[Expr[T]]{ type R = AssertionHelper @@ -80,7 +80,7 @@ trait ExprCeciliaExporter { AssertionHelper(allOf[TargetId].map(t => t -> s"$m^$id").toMap, Map.empty) case Worst(l*) if l.size == 1 => toCecilia(l.head) - case w@Worst(l*) if l.size > 1 => + case w@Worst(l*) => val lR = l.map(toCecilia) val lMap = lR.foldLeft(Map.empty[TargetId,List[String]])((acc,m) => { m.result.transform((k,v) => (for{a <- acc.get(k)} yield a :+ v) getOrElse List(v)) diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Folder.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Folder.scala index a0528ad..bd2f6b5 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Folder.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Folder.scala @@ -17,23 +17,26 @@ package onera.pmlanalyzer.views.dependability.exporters -import onera.pmlanalyzer.views.dependability.exporters.Folder.date -import onera.pmlanalyzer.views.dependability.exporters.Model._ +import onera.pmlanalyzer.views.dependability.exporters.Folder.{date, initialId} +import onera.pmlanalyzer.views.dependability.exporters.Model.* -import java.lang.{System => OS} +import java.lang.System as OS +import scala.collection.mutable import scala.xml.Elem sealed trait Folder { - val id: Int = Folder.folderNb + val id: Int = Folder.foldersIds.size + 1 + initialId val name: Symbol lazy val absolutePath: String - Folder.folderNb = Folder.folderNb + 1 + Folder.foldersIds += (id -> this) override def toString: String = s"Folder(name=${name.name},id=$id)" } object Folder { - var folderNb = 100 + + private val initialId : Int = 100 + private val foldersIds: mutable.Map[Int, Folder] = mutable.Map.empty val date: Long = OS.currentTimeMillis() } @@ -90,7 +93,7 @@ object SubFamilyFolder { def apply[T](name: Symbol, parent:FamilyFolder[T])(implicit m: ModelDescriptor[T]): SubFamilyFolder[T] = m.getFolder(name,parent) } -case class EntityFolder[T](name: Symbol, parent: SubFolder[T])(implicit m: ModelDescriptor[T]) extends SubFolder[T] { +final case class EntityFolder[T](name: Symbol, parent: SubFolder[T])(implicit m: ModelDescriptor[T]) extends SubFolder[T] { private val elements = scala.collection.mutable.Set.empty[VersionFolder[T]] def getVersionNb : Int = elements.size parent match { @@ -111,7 +114,7 @@ case class EntityFolder[T](name: Symbol, parent: SubFolder[T])(implicit m: Model } } -case class VersionFolder[T](parent: EntityFolder[T])(implicit m: ModelDescriptor[T]) extends CeciliaFolder { +final case class VersionFolder[T](parent: EntityFolder[T])(implicit m: ModelDescriptor[T]) extends CeciliaFolder { val name: Symbol = Symbol((parent.getVersionNb + 1).toString) override lazy val absolutePath: String = s"${parent.absolutePath};${name.name}" private var model: Option[T] = None diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Model.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Model.scala index 54e695f..2e0e79d 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Model.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/Model.scala @@ -47,7 +47,7 @@ case object Local extends Orientation{ val name: String = "local" } -case class Configuration(name: Symbol, conf: Map[State, String]) { +final case class Configuration(name: Symbol, conf: Map[State, String]) { def toElem: Elem = { {conf.map(p => )} @@ -55,7 +55,7 @@ case class Configuration(name: Symbol, conf: Map[State, String]) { } } -case class State(name: Symbol, tyype: CeciliaType, ini: String) { +final case class State(name: Symbol, tyype: CeciliaType, ini: String) { def toElem: Elem = tyype match { case CeciliaBoolean => case tyype: EnumeratedType => @@ -65,14 +65,14 @@ case class State(name: Symbol, tyype: CeciliaType, ini: String) { override def toString: String = name.name } -case class Flow(name: Symbol, tyype: CeciliaType, orientation: Orientation) { +final case class Flow(name: Symbol, tyype: CeciliaType, orientation: Orientation) { private var _owner: Option[BlockModel[_]] = None override def toString: String = name.name def add(to: BlockModel[_]): Unit = _owner = Some(to) - def owner: BlockModel[_] = _owner.get + def owner: Option[BlockModel[_]] = _owner def toElem(x: Int, y: Int, id: Int): Elem = tyype match { case CeciliaBoolean => @@ -99,6 +99,16 @@ sealed trait Model { object Model { + def linksToElem(links:List[(Flow,Flow)]) = { + for { + ((from, to), id) <- links.zipWithIndex + oFrom <- from.owner + oTo <- to.owner + } yield { + + } + } + trait ModelDescriptor[T] { private val families = collection.mutable.HashMap.empty[Path, FamilyFolder[T]] private val subFamilies = collection.mutable.HashMap.empty[Path, SubFamilyFolder[T]] @@ -292,7 +302,7 @@ sealed trait BlockModel[T] extends Model.EquiBlockFlowPlacer { val name: Symbol val parent: VersionFolder[T] val icon: ImageModel - val simul: List[ImageModel] + val simulationIcons: List[ImageModel] val flows: List[Flow] val code: String } @@ -301,7 +311,7 @@ sealed trait EventModel { val name: Symbol } -case class SynchroEventModel(name: Symbol, events: List[EventModel], tyype: String) extends EventModel +final case class SynchroEventModel(name: Symbol, events: List[EventModel], tyype: String) extends EventModel sealed trait ConcreteEventModel extends EventModel { val law: Elem @@ -313,7 +323,7 @@ sealed trait ConcreteEventModel extends EventModel { } } -case class DeterministicEventModel(name: Symbol) extends ConcreteEventModel { +final case class DeterministicEventModel(name: Symbol) extends ConcreteEventModel { val law: Elem = { @@ -321,7 +331,7 @@ case class DeterministicEventModel(name: Symbol) extends ConcreteEventModel { } } -case class StochastiqueEventModel(name: Symbol, lambda: Double = 10e-4) extends ConcreteEventModel { +final case class StochasticEventModel(name: Symbol, lambda: Double = 10e-4) extends ConcreteEventModel { val law: Elem = { @@ -329,15 +339,15 @@ case class StochastiqueEventModel(name: Symbol, lambda: Double = 10e-4) extends } } -case class ComponentModel( - name: Symbol, - parent: VersionFolder[ComponentModel], - icon: ImageModel, - simul: List[ImageModel], - flows: List[Flow], - events: List[ConcreteEventModel], - states: List[State], - code: String +final case class ComponentModel( + name: Symbol, + parent: VersionFolder[ComponentModel], + icon: ImageModel, + simulationIcons: List[ImageModel], + flows: List[Flow], + events: List[ConcreteEventModel], + states: List[State], + code: String ) extends BlockModel[ComponentModel] { parent.add(this) flows.foreach(_.add(this)) @@ -345,7 +355,7 @@ case class ComponentModel( def toElem: Elem = { - {simul.map(s => )}{flows.map(flow => flow.toElem(position(flow)._1, position(flow)._2, idOf(flow)))}{states.map(_.toElem)}{events.map(_.toElem)} + {simulationIcons.map(s => )}{flows.map(flow => flow.toElem(position(flow)._1, position(flow)._2, idOf(flow)))}{states.map(_.toElem)}{events.map(_.toElem)} {code} @@ -376,7 +386,7 @@ object ComponentModel { } -case class SubComponent(name: Symbol, tyype: BlockModel[_], x: Int = 0, y: Int = 0, mirrorV: Boolean = false, mirrorH: Boolean = false) { +final case class SubComponent(name: Symbol, tyype: BlockModel[_], x: Int = 0, y: Int = 0, mirrorV: Boolean = false, mirrorH: Boolean = false) { def toElem: Elem = { } @@ -388,7 +398,7 @@ class EquipmentModel( val name: Symbol, val parent: VersionFolder[EquipmentModel], val icon: ImageModel, - val simul: List[ImageModel], + val simulationIcons: List[ImageModel], val flows: List[Flow], val subs: List[SubComponent], val links: List[(Flow, Flow)], @@ -400,7 +410,7 @@ class EquipmentModel( def toElem: Elem = { - {simul.map(s => )}{flows.map(flow => flow.toElem(position(flow)._1, position(flow)._2, idOf(flow)))}{subs.map(_.toElem)}{links.zipWithIndex.map(l => )}{sync.map(s => { + {simulationIcons.map(s => )}{flows.map(flow => flow.toElem(position(flow)._1, position(flow)._2, idOf(flow)))}{subs.map(_.toElem)}{Model.linksToElem(links)}{sync.map(s => { {s.events.map(e => )} @@ -443,7 +453,7 @@ class SystemModel(val name: Symbol, def toElem: Elem = { - {subs.map(s => )}{links.zipWithIndex.map(l => )}{sync.map(s => { + {subs.map(s => )}{Model.linksToElem(links)}{sync.map(s => { {s.events.map(e => )} @@ -548,7 +558,7 @@ object OperatorModel { } } -case class FailureConditions(fc : Set[(String,String)], size:Int) extends Model { +final case class FailureConditions(fc : Set[(String,String)], size:Int) extends Model { def fileName(f:String,v: String): String = s"${f.replace(".","_")}_is_$v.seq" def toElem: Elem = { diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/PlatformCeciliaExporter.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/PlatformCeciliaExporter.scala index 796c14c..1bd71b6 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/PlatformCeciliaExporter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/exporters/PlatformCeciliaExporter.scala @@ -33,7 +33,7 @@ import scala.xml.XML trait PlatformCeciliaExporter { self: BasicOperationCeciliaExporter with SystemCeciliaExporter with TypeCeciliaExporter => - implicit class platformExportOps[ + implicit class PlatformExportOps[ FM : IsCriticityOrdering : IsFinite : IsShadowOrdering, T <: Platform with DependabilitySpecification.Aux[FM] : Typeable](a: T) { def exportAsCeciliaWithFM(): Unit = { diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Copy.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Copy.scala index 93202f4..ffacb4d 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Copy.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Copy.scala @@ -17,4 +17,4 @@ package onera.pmlanalyzer.views.dependability.model -case class Copy(targetNeeded:Set[TargetId], targetWritten:Set[TargetId]) +final case class Copy(targetNeeded:Set[TargetId], targetWritten:Set[TargetId]) diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Event.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Event.scala index eb92cb5..a2c0956 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Event.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Event.scala @@ -24,13 +24,13 @@ trait Event { override def toString: String = name.name } -case class SynchroEvent(name:Symbol, synchronizedEvents: Set[Event]) extends Event +final case class SynchroEvent(name:Symbol, synchronizedEvents: Set[Event]) extends Event trait ConcreteEvent extends Event { val owner: ModeAutomaton[_] } -case class StochasticEvent[T](name:Symbol, owner:ModeAutomaton[T]) extends ConcreteEvent +final case class StochasticEvent[T](name:Symbol, owner:ModeAutomaton[T]) extends ConcreteEvent object StochasticEvent{ def apply[T](name: Symbol, owner: ModeAutomaton[T]): StochasticEvent[T] = { @@ -40,13 +40,13 @@ object StochasticEvent{ } } -case class DetermisticEvent[T](name:Symbol, owner:ModeAutomaton[T], delay:Int) extends ConcreteEvent { +final case class DeterministicEvent[T](name:Symbol, owner:ModeAutomaton[T], delay:Int) extends ConcreteEvent { override def toString: String = name.name } -object DetermisticEvent{ - def apply[T](name: Symbol, owner: ModeAutomaton[T], delay:Int): DetermisticEvent[T] = { - val r = new DetermisticEvent[T](name, owner,delay) +object DeterministicEvent{ + def apply[T](name: Symbol, owner: ModeAutomaton[T], delay:Int): DeterministicEvent[T] = { + val r = new DeterministicEvent[T](name, owner,delay) Simulator.addEvent(r) r } diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Id.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Id.scala index 89392ea..d95ee57 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Id.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Id.scala @@ -38,7 +38,7 @@ trait IdBuilder[T<:Id]{ } } -case class VariableId private(name:Symbol) extends Id +final case class VariableId private(name:Symbol) extends Id object VariableId extends IdBuilder[VariableId]{ val noneId = new VariableId(Symbol("none")) @@ -56,7 +56,7 @@ object TargetId extends IdBuilder[TargetId]{ def apply(name: Symbol): TargetId = _memo.getOrElseUpdate(name, new TargetId(name)) } -case class SoftwareId private(name:Symbol) extends Id { +final case class SoftwareId private(name:Symbol) extends Id { override def toString: String = name.name } @@ -66,11 +66,11 @@ object SoftwareId extends IdBuilder[SoftwareId]{ def apply(name: Symbol): SoftwareId = _memo.getOrElseUpdate(name, new SoftwareId(name)) } -case class TransporterId(name:Symbol) extends Id { +final case class TransporterId(name:Symbol) extends Id { override def toString: String = name.name } -case class InitiatorId private(name:Symbol) extends Id { +final case class InitiatorId private(name:Symbol) extends Id { override def toString: String = name.name } @@ -80,4 +80,4 @@ object InitiatorId extends IdBuilder[InitiatorId]{ def apply(name: Symbol): InitiatorId = _memo.getOrElseUpdate(name, new InitiatorId(name)) } -case class AutomatonId(name:Symbol) extends Id \ No newline at end of file +final case class AutomatonId(name:Symbol) extends Id \ No newline at end of file diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/ModeAutomaton.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/ModeAutomaton.scala index bc80203..9287112 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/ModeAutomaton.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/ModeAutomaton.scala @@ -100,7 +100,7 @@ object SimpleFMAutomaton { class InputFMAutomaton[T: IsCriticityOrdering : IsFinite : IsShadowOrdering](val id: AutomatonId, val initialState: T) extends FMAutomaton[T] { val in: InputPort[T] = InputPort(Symbol("i")) val inputPorts: Set[InputPort[T]] = Set(in) - val epsilon: DetermisticEvent[T] = DetermisticEvent(Symbol("espilon"), this, 0) + val epsilon: DeterministicEvent[T] = DeterministicEvent(Symbol("espilon"), this, 0) val events: Set[Event] = allWithNone[T].map(x => StochasticEvent(x.name, this)).toSet[Event] + epsilon val eventMap: Map[Symbol, Event] = events.map(e => e.name -> e).toMap val transitions: Set[Transition[T]] = diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/System.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/System.scala index de6102c..08e7921 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/System.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/System.scala @@ -34,13 +34,13 @@ trait Owner { val componentOwner : mutable.HashMap[Component, Component] = mutable.HashMap.empty } -case class System(name:Symbol) { + class System(val name:Symbol) { implicit val context: Builder[SubComponent] with Linker with Owner = new Builder[SubComponent] with Linker with Owner {} override def toString: String = name.name - implicit class listExtensionMethods[T](l:List[OutputPort[T]]) { + extension[T](l:List[OutputPort[T]]) { def |+|(that : OutputPort[T]) : List[OutputPort[T]] = l :+ that def |++|(that : List[OutputPort[T]]) : List[OutputPort[T]] = l ++ that } diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Target.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Target.scala index c84e410..363d486 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Target.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Target.scala @@ -17,8 +17,6 @@ package onera.pmlanalyzer.views.dependability.model -import onera.pmlanalyzer.views.dependability.exporters.SubComponent -import onera.pmlanalyzer.views.dependability.operators.{IsCriticityOrdering, IsFinite, IsShadowOrdering} import onera.pmlanalyzer.views.dependability.exporters.{SubComponent, *} import onera.pmlanalyzer.views.dependability.model.CustomTypes.Request import onera.pmlanalyzer.views.dependability.operators.* diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transition.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transition.scala index 2ea9609..50bb6c6 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transition.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transition.scala @@ -24,4 +24,4 @@ package onera.pmlanalyzer.views.dependability.model * @param computeNewState the new state when the transaction will be fired * @tparam T the type of the owner state */ -case class Transition[T](guard:() => Boolean, e:Event, computeNewState: () => T) +final case class Transition[T](guard:() => Boolean, e:Event, computeNewState: () => T) diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transporter.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transporter.scala index 350cbd1..3a4b3a7 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transporter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Transporter.scala @@ -26,7 +26,7 @@ import onera.pmlanalyzer.views.dependability.operators.* abstract class Transporter [FM: IsCriticityOrdering : IsFinite : IsShadowOrdering](implicit owner: Owner) extends Component { val loadI: InputPort[List[Request[FM]]] = InputPort[List[Request[FM]]](Symbol("loadI")) val initialState: FM = min[FM] - val fMAutomaton: SimpleFMAutomaton[FM] = SimpleFMAutomaton[FM](AutomatonId(Symbol(s"fmAutomaton")),initialState) + val fMAutomaton: SimpleFMAutomaton[FM] = SimpleFMAutomaton[FM](AutomatonId(Symbol("fmAutomaton")),initialState) val storeO : OutputPort[Request[FM]] } diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Variable.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Variable.scala index a1029a0..d78897b 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/model/Variable.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/model/Variable.scala @@ -65,37 +65,37 @@ object ExprImplicits { implicit class TargetExtension[T](d:Target[T]) { def fmIs(v:Expr[T]): (TargetId,Expr[T]) = d.id -> v } - case class If[T](b:BoolExpr) { + final case class If[T](b:BoolExpr) { def Then(t:Expr[T]) : IT[T] = IT(b,t) } - case class IT[T](b:BoolExpr,t:Expr[T]) { + final case class IT[T](b:BoolExpr,t:Expr[T]) { def Else[U >: T](e: Expr[U]): ITE[U] = ITE(b, t, e) } } -case class ITE[T](i:BoolExpr, t: Expr[T], e:Expr[T]) extends Expr[T]{ +final case class ITE[T](i:BoolExpr, t: Expr[T], e:Expr[T]) extends Expr[T]{ def eval(): Option[T] = for(vi <- i.eval(); vt <- t.eval(); ve <- e.eval()) yield if(vi) vt else ve } -case class Const[T](x:T) extends Expr[T]{ +final case class Const[T](x:T) extends Expr[T]{ def eval():Some[T] = Some(x) } -case class DMap[T](m:Map[TargetId,Expr[T]]) extends Expr[Map[TargetId,T]]{ +final case class DMap[T](m:Map[TargetId,Expr[T]]) extends Expr[Map[TargetId,T]]{ def eval(): Option[Map[TargetId, T]] = { val values = m.transform((_,v) => v.eval()) if(values.values.exists(_.isEmpty)) None else - Some(values.transform((_,v) => v.get)) + Some(values.collect({case (k,Some(v)) => k -> v})) } } -case class Of[T](m:Variable[Map[TargetId,T]], id:TargetId) extends Expr[T]{ +final case class Of[T](m:Variable[Map[TargetId,T]], id:TargetId) extends Expr[T]{ def eval(): Option[T] = for {mv <- m.eval(); vv <- mv.get(id)} yield vv } -case class Worst[T](l:Expr[T]*)(implicit ev:IsCriticityOrdering[T], evF:IsFinite[T]) extends Expr[T] { +final case class Worst[T](l:Expr[T]*)(implicit ev:IsCriticityOrdering[T], evF:IsFinite[T]) extends Expr[T] { val ordering : IsCriticityOrdering[T] = ev val finite : IsFinite[T] = evF def eval(): Option[T] = { @@ -107,7 +107,7 @@ case class Worst[T](l:Expr[T]*)(implicit ev:IsCriticityOrdering[T], evF:IsFinite } } -case class Best[T](l:Expr[T]*)(implicit evO:IsCriticityOrdering[T], evF:IsFinite[T]) extends Expr[T] { +final case class Best[T](l:Expr[T]*)(implicit evO:IsCriticityOrdering[T], evF:IsFinite[T]) extends Expr[T] { val ordering : IsCriticityOrdering[T] = evO val finite : IsFinite[T] = evF def eval(): Option[T] = { @@ -121,11 +121,11 @@ case class Best[T](l:Expr[T]*)(implicit evO:IsCriticityOrdering[T], evF:IsFinite sealed trait BoolExpr extends Expr[Boolean] -case class Equal(l:Expr[_], r:Expr[_]) extends BoolExpr { +final case class Equal(l:Expr[_], r:Expr[_]) extends BoolExpr { def eval() : Option[Boolean] = for {vl <- l.eval(); vr <- r.eval()} yield vr == vl } -case class And(l:BoolExpr*) extends BoolExpr { +final case class And(l:BoolExpr*) extends BoolExpr { override def eval(): Option[Boolean] = { val and = for {e <- l; ve <- e.eval()} yield ve if(and.size != l.size) @@ -135,7 +135,7 @@ case class And(l:BoolExpr*) extends BoolExpr { } } -case class Or(l:BoolExpr*) extends BoolExpr { +final case class Or(l:BoolExpr*) extends BoolExpr { override def eval(): Option[Boolean] = { val or = for {e <- l; ve <- e.eval()} yield ve if(or.size != l.size) @@ -145,7 +145,7 @@ case class Or(l:BoolExpr*) extends BoolExpr { } } -case class Not(n:BoolExpr) extends BoolExpr { +final case class Not(n:BoolExpr) extends BoolExpr { override def eval(): Option[Boolean] = for {vn <- n.eval()} yield !vn } @@ -168,12 +168,12 @@ object Variable { // implicit def defLocalVar[T](f: => Option[T]) : LocalVariable[T] = LocalVariable(() => f) } -case class OutputPort[T](id : VariableId, evalFun : () => Option[T]) extends Variable[T] { +final case class OutputPort[T](id : VariableId, evalFun : () => Option[T]) extends Variable[T] { def eval(): Option[T] = for( x <- evalFun()) yield x def |+|(that : OutputPort[T]) : List[OutputPort[T]] = this :: that :: Nil } -case class LocalVariable[T](id: VariableId, evalFun : () => Option[T]) extends Variable[T] { +final case class LocalVariable[T](id: VariableId, evalFun : () => Option[T]) extends Variable[T] { def eval(): Option[T] = for( x <- evalFun()) yield x } diff --git a/src/main/scala/onera/pmlanalyzer/views/dependability/operators/IsFinite.scala b/src/main/scala/onera/pmlanalyzer/views/dependability/operators/IsFinite.scala index 340086b..bc05e30 100644 --- a/src/main/scala/onera/pmlanalyzer/views/dependability/operators/IsFinite.scala +++ b/src/main/scala/onera/pmlanalyzer/views/dependability/operators/IsFinite.scala @@ -27,7 +27,7 @@ trait IsFinite[T] { trait IsFiniteOps { - implicit class hasName[T](x: T)(implicit ev: IsFinite[T]) { + implicit class HasName[T](x: T)(implicit ev: IsFinite[T]) { def name: Symbol = ev.name(x) } diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/BDDFactory.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/BDDFactory.scala index 99863b2..9c5a20c 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/BDDFactory.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/BDDFactory.scala @@ -27,7 +27,6 @@ import scala.collection.mutable class SymbolBDDFactory extends GenBDDFactory[Symbol] { protected val _factory: JavaBDDFactory = initFactory(500, 500) protected val varMap: mutable.HashMap[Symbol, Int] = mutable.HashMap.empty - protected var _varCount = 0 protected val nbOfVar: Int = 500 } @@ -398,7 +397,6 @@ trait GenBDDFactory[Var] extends BaseBDDFactory[Var, JavaBDD] { implicit def toJavaBDD(variable: Var): JavaBDD = getVar(variable) } - protected var _varCount: Int protected val _factory: JavaBDDFactory protected val nbOfVar: Int protected val varMap: mutable.HashMap[Var, Int] @@ -431,11 +429,10 @@ trait GenBDDFactory[Var] extends BaseBDDFactory[Var, JavaBDD] { case Some(i) => getIthVar(i) case None => - _varCount = _varCount + 1 - - if ((_varCount % nbOfVar) == 0) - _factory.setVarNum(_varCount + nbOfVar) - val bdd = _factory.ithVar(_varCount) + val varId = varMap.size + 1 + if ((varId % nbOfVar) == 0) + _factory.setVarNum(varMap.size + nbOfVar) + val bdd = _factory.ithVar(varId) varMap += (variable -> bdd.`var`() ) bdd } @@ -447,7 +444,6 @@ trait GenBDDFactory[Var] extends BaseBDDFactory[Var, JavaBDD] { def reset(): Unit = { varMap.clear() _factory.reset() - _varCount = 0 _factory.setVarNum(nbOfVar) } @@ -583,7 +579,6 @@ trait GenBDDFactory[Var] extends BaseBDDFactory[Var, JavaBDD] { def dispose(): Unit = { _factory.done() varMap.clear() - _varCount = 0 } /** diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/ProblemElement.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/ProblemElement.scala index 42e45ad..e43e850 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/ProblemElement.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/formalisation/ProblemElement.scala @@ -47,17 +47,17 @@ trait Assert extends ProblemElement { def assert(s: Solver): Unit } -case class SimpleAssert(l: ALit) extends Assert { +final case class SimpleAssert(l: ALit) extends Assert { def assert(s: Solver): Unit = s.assertTrue(l.toLit(s)) } -case class AssertPB(l: Set[ALit], comp: Comparison, k: Int) extends Assert { +final case class AssertPB(l: Set[ALit], comp: Comparison, k: Int) extends Assert { def assert(s: Solver): Unit = s.assertPB(l.map(_.toLit(s)).toSeq.asJava, comp, k) } -case class MNode(id: NodeId) extends ProblemElement +final case class MNode(id: NodeId) extends ProblemElement -case class MGraph(nodes: Set[MNode], edges: Set[MEdge]) extends ProblemElement { +final case class MGraph(nodes: Set[MNode], edges: Set[MEdge]) extends ProblemElement { val toGraph: Solver => Graph = immutableHashMapMemo { s => { val g = new Graph(s) @@ -77,37 +77,37 @@ case class MGraph(nodes: Set[MNode], edges: Set[MEdge]) extends ProblemElement { } } -case class MEdge(from: MNode, to: MNode, id: EdgeId) extends ProblemElement +final case class MEdge(from: MNode, to: MNode, id: EdgeId) extends ProblemElement -case class MEdgeLit(edge: MEdge, graph: MGraph) extends ALit { +final case class MEdgeLit(edge: MEdge, graph: MGraph) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => graph.toGraph(s).getEdge(edge.id.name).l } } -case class MLit(id: LitId) extends ALit { +final case class MLit(id: LitId) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => new Lit(s, id.name) } } -case class And(l: ALit*) extends ALit { +final case class And(l: ALit*) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => and(l.map(_.toLit(s)).asJava) } } -case class Or(l: ALit*) extends ALit { +final case class Or(l: ALit*) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => or(l.map(_.toLit(s)).asJava) } } -case class Implies(l: ALit, r: ALit) extends ALit { +final case class Implies(l: ALit, r: ALit) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => implies(l.toLit(s), r.toLit(s)) } } -case class Not(l: ALit) extends ALit { +final case class Not(l: ALit) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => not(l.toLit(s)) } } -case class Equal(l: ALit, r: ALit) extends ALit { +final case class Equal(l: ALit, r: ALit) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => equal(l.toLit(s), r.toLit(s)) } } -case class Reaches(graph: MGraph, from: MNode, to: MNode) extends ALit { +final case class Reaches(graph: MGraph, from: MNode, to: MNode) extends ALit { val toLit: Solver => Lit = immutableHashMapMemo { s => { val g = graph.toGraph(s) g.reaches(g.getNode(from.id.name), g.getNode(to.id.name)) @@ -134,7 +134,7 @@ class Problem(val platform: Platform with InterferenceSpecification, def decodeUserModel(physicalModel: Set[PhysicalScenarioId]): Set[Set[UserScenarioId]] = platform match { case _ if physicalModel.isEmpty => Set.empty - case _ if maxSize.isDefined && physicalModel.size > maxSize.get => Set.empty + case _ if maxSize.exists(physicalModel.size > _) => Set.empty case spec: TransactionLibrary => val scenario = idToScenario .view @@ -167,7 +167,7 @@ class Problem(val platform: Platform with InterferenceSpecification, //FIXME Are we integrating exclusive service in the channel even if not used in the scenario? def decodeChannel(model: Set[PhysicalScenarioId]): Channel = { - if (maxSize.isDefined && model.size > maxSize.get) + if (maxSize.exists(model.size > _)) Set.empty else nodeToScenario @@ -176,8 +176,8 @@ class Problem(val platform: Platform with InterferenceSpecification, .flatMap(nodeToServices) } - def decodeModel(model: Set[MLit], isFree: Boolean): Set[Set[PhysicalScenarioId]] = { - if (maxSize.isDefined && model.size > maxSize.get) + def decodeModel(model: Set[MLit], modelIsFree: Boolean): Set[Set[PhysicalScenarioId]] = { + if (maxSize.exists(model.size > _)) Set.empty else if (model.size == 1 && groupedScenarios(model.head).size == 1) { Set.empty @@ -194,7 +194,7 @@ class Problem(val platform: Platform with InterferenceSpecification, for {m <- maxSize} yield s.assertPB(variables.values.toSeq.asJava, LEQ, m) if (model.size == 1) s.assertPB(variables.values.toSeq.asJava, GEQ, 2) - if (isFree) + if (modelIsFree) model .filter(m => litToNodeSet(m).exists(_.nonEmpty)) .foreach(l => s.assertAtMostOne(groupedScenarios(l).map(variables).asJava)) diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/EquivalenceRelation.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/EquivalenceRelation.scala index 3f431d2..6cc6dfb 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/EquivalenceRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/EquivalenceRelation.scala @@ -22,7 +22,7 @@ import onera.pmlanalyzer.pml.model.service.Service import onera.pmlanalyzer.pml.model.utils.Message import sourcecode.Name -case class EquivalenceRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends ReflexiveSymmetricEndomorphism[A](iniValues) +final case class EquivalenceRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends ReflexiveSymmetricEndomorphism[A](iniValues) object EquivalenceRelation{ trait Instances { diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/ExclusiveRelation.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/ExclusiveRelation.scala index fc1003c..2f3377d 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/ExclusiveRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/ExclusiveRelation.scala @@ -23,7 +23,7 @@ import onera.pmlanalyzer.pml.model.software.Application import sourcecode.Name import onera.pmlanalyzer.views.interference.model.specification.InterferenceSpecification.PhysicalTransactionId -case class ExclusiveRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends AntiReflexiveSymmetricEndomorphism[A](iniValues) +final case class ExclusiveRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends AntiReflexiveSymmetricEndomorphism[A](iniValues) object ExclusiveRelation{ trait GeneralInstances { diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/InterfereRelation.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/InterfereRelation.scala index 2c47d30..e097a39 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/InterfereRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/InterfereRelation.scala @@ -22,7 +22,7 @@ import onera.pmlanalyzer.pml.model.relations.Relation import onera.pmlanalyzer.pml.model.service.Service import onera.pmlanalyzer.views.interference.model.specification.InterferenceSpecification.PhysicalTransactionId -case class InterfereRelation[L,R] private(iniValues: Map[L, Set[R]]) extends Relation[L,R](iniValues) +final case class InterfereRelation[L,R] private(iniValues: Map[L, Set[R]]) extends Relation[L,R](iniValues) //FIXME TO ENSURE CORRECTNESS THE INTERFERE ENDOMORPHISMS SHOULD BE ANTI-REFLEXIVE AND SYMMETRIC TO BE // CONSISTENT WITH INTERFERENCE SPECIFICATION BASE TRAIT diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/NotInterfereRelation.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/NotInterfereRelation.scala index ad6ee5a..d14b7d9 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/NotInterfereRelation.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/NotInterfereRelation.scala @@ -23,7 +23,7 @@ import onera.pmlanalyzer.pml.model.service.Service import sourcecode.Name import onera.pmlanalyzer.views.interference.model.specification.InterferenceSpecification.PhysicalTransactionId -case class NotInterfereRelation[L,R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L,R](iniValues) +final case class NotInterfereRelation[L,R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L,R](iniValues) object NotInterfereRelation{ trait Instances { diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/TransparentSet.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/TransparentSet.scala index 9b86cca..740610c 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/TransparentSet.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/relations/TransparentSet.scala @@ -22,7 +22,7 @@ import onera.pmlanalyzer.views.interference.model.specification.InterferenceSpec import scala.collection.mutable.Set as MSet -case class TransparentSet[T]private(value:MSet[T])(using n:Name){ +final case class TransparentSet[T]private(value:MSet[T])(using n:Name){ val name:String = n.value } diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/InterferenceSpecification.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/InterferenceSpecification.scala index ef2ddfb..c47e25a 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/InterferenceSpecification.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/InterferenceSpecification.scala @@ -333,13 +333,13 @@ object InterferenceSpecification { def compare(that: Id): Int = id.name.compare(that.id.name) } - case class PhysicalTransactionId(id: Symbol) extends Id + final case class PhysicalTransactionId(id: Symbol) extends Id - case class PhysicalScenarioId(id: Symbol) extends Id + final case class PhysicalScenarioId(id: Symbol) extends Id - case class PhysicalMultiTransactionId(id: Symbol) extends Id + final case class PhysicalMultiTransactionId(id: Symbol) extends Id - case class ChannelId(id: Symbol) extends Id + final case class ChannelId(id: Symbol) extends Id def multiTransactionId(t: Iterable[PhysicalScenarioId]): PhysicalMultiTransactionId = PhysicalMultiTransactionId(Symbol(t.map(_.id.name).toArray.sorted.mkString("< ", " || ", " >"))) diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/TableBasedInterferenceSpecification.scala b/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/TableBasedInterferenceSpecification.scala index 2a0a391..123b338 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/TableBasedInterferenceSpecification.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/model/specification/TableBasedInterferenceSpecification.scala @@ -17,15 +17,12 @@ package onera.pmlanalyzer.views.interference.model.specification -import onera.pmlanalyzer.pml.model.configuration.TransactionLibrary -import onera.pmlanalyzer.pml.model.hardware.Platform -import onera.pmlanalyzer.pml.model.service.Service import onera.pmlanalyzer.pml.exporters.FileManager import onera.pmlanalyzer.pml.model.configuration.TransactionLibrary import onera.pmlanalyzer.pml.model.hardware.{Hardware, Platform} import onera.pmlanalyzer.pml.model.service.Service import onera.pmlanalyzer.pml.model.software.Application -import onera.pmlanalyzer.pml.operators.{Provided, *} +import onera.pmlanalyzer.pml.operators.* import onera.pmlanalyzer.views.interference.model.relations.* import onera.pmlanalyzer.views.interference.model.specification.InterferenceSpecification.PhysicalTransactionId diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/operators/Analyse.scala b/src/main/scala/onera/pmlanalyzer/views/interference/operators/Analyse.scala index 13a37cb..71820e2 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/operators/Analyse.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/operators/Analyse.scala @@ -512,7 +512,7 @@ object Analyse { writer write s"""Platform Name: ${platform.name.name} |File: ${platform.sourceFile.value} - |Date: ${java.time.LocalDateTime.now().toString} + |Date: ${java.time.LocalDateTime.now()} |------------------------------------------ |""".stripMargin diff --git a/src/main/scala/onera/pmlanalyzer/views/interference/operators/PostProcess.scala b/src/main/scala/onera/pmlanalyzer/views/interference/operators/PostProcess.scala index 2d765b6..73f8629 100644 --- a/src/main/scala/onera/pmlanalyzer/views/interference/operators/PostProcess.scala +++ b/src/main/scala/onera/pmlanalyzer/views/interference/operators/PostProcess.scala @@ -255,7 +255,7 @@ object PostProcess { .map(s => { val split = s.split(":") val services = split.head.split("[{, }]").filter(_.nonEmpty).toSeq - val size = split.last.split(" ").filter(_.nonEmpty).head.toInt + val size = (for {s <- split.last.split(" ").find(_.nonEmpty)} yield s.toInt).getOrElse(-1) services -> size }) .toSeq diff --git a/src/main/scala/onera/pmlanalyzer/views/patterns/examples/PhylogPatterns.scala b/src/main/scala/onera/pmlanalyzer/views/patterns/examples/PhylogPatterns.scala index bf9f15d..88ac010 100644 --- a/src/main/scala/onera/pmlanalyzer/views/patterns/examples/PhylogPatterns.scala +++ b/src/main/scala/onera/pmlanalyzer/views/patterns/examples/PhylogPatterns.scala @@ -49,8 +49,7 @@ object PhylogPatterns extends App { size 8 width patternWidth). strategy ("DO178: Implementation compliant with specification \\\\ DO254: Hardware usage compliant with specification" size 11 ). - evidence (alterationMitigated). - `given` ("Mitigation means implementation verified \\\\ (DO178B/C compliance)"). + evidence (alterationMitigated).`given` ("Mitigation means implementation verified \\\\ (DO178B/C compliance)"). `given`("Hardware configuration verified \\\\ (DO254 compliance)") @@ -62,8 +61,8 @@ object PhylogPatterns extends App { strategy("Safety Analysis at platform level"). evidence("Real-time objectives are fulfilled"). `given`("Safety objectives $\\mathcal{R}eq$,\\\\ configuration settings \\\\and application mapping"). - `given`(s"Mitigation means of RU2, RU3 and (E7)"). - `given`(s"Critical alteration from RU2") + `given`("Mitigation means of RU2, RU3 and (E7)"). + `given`("Critical alteration from RU2") val equipmentAnalysis = conclusion("Errors contained within equipment" short "equipmentAnalysis" size 8). strategy("Safety analysis at equipment level"). diff --git a/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexCodePrinter.scala b/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexCodePrinter.scala index 085cca5..986e7b2 100644 --- a/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexCodePrinter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexCodePrinter.scala @@ -61,13 +61,13 @@ object LatexCodePrinter{ if (spacing != 0) printer.write(s"\\hspace*{${5*spacing}pt}") } - private def print(conclusion: Claim)(implicit printer: FileWriter, spacing:Int): Unit = { + private def print(claim: Claim)(implicit printer: FileWriter, spacing:Int): Unit = { addSpacing - printer.write(s"\\texttt{Claim:} \\\\\n") - print(s"${ids(conclusion)} ${conclusion.label}")(printer,spacing + 1) - print(conclusion.strategy) - print(conclusion.evidences.toList) - conclusion.evidences foreach { + printer.write("\\texttt{Claim:} \\\\\n") + print(s"${ids(claim)} ${claim.label}")(printer,spacing + 1) + print(claim.strategy) + print(claim.evidences.toList) + claim.evidences foreach { case c:Claim => printer.write("\n") print(c) @@ -77,7 +77,7 @@ object LatexCodePrinter{ private def print(strategy: Strategy)(implicit printer: FileWriter, spacing:Int): Unit = { addSpacing - printer.write(s"\\texttt{Strategy:} \\\\\n") + printer.write("\\texttt{Strategy:} \\\\\n") print(s"${ids(strategy)} ${strategy.label}")(printer,spacing + 1) for (b <- strategy.backing) yield print(b)(printer,spacing + 1) for (b <- strategy.defeater) yield print(b)(printer,spacing + 1) @@ -85,13 +85,13 @@ object LatexCodePrinter{ private def print(backing: Backing)(implicit printer: FileWriter, spacing:Int): Unit = { addSpacing - printer.write(s"\\texttt{Backing:} \\\\\n") + printer.write("\\texttt{Backing:} \\\\\n") print(backing.label)(printer,spacing + 1) } private def print(defeater: Defeater)(implicit printer: FileWriter, spacing:Int): Unit = { addSpacing - printer.write(s"\\texttt{Defeaters:} \\\\\n") + printer.write("\\texttt{Defeaters:} \\\\\n") print(defeater.label)(printer,spacing + 1) } @@ -100,7 +100,7 @@ object LatexCodePrinter{ case Nil => case l => addSpacing - printer.write(s"\\texttt{Givens}:\\\\\n") + printer.write("\\texttt{Givens}:\\\\\n") l foreach( g => print(s"${ids(g)} ${g.label}")(printer,spacing +1 ) ) @@ -109,7 +109,7 @@ object LatexCodePrinter{ case Nil => case l => addSpacing - printer.write(s"\\texttt{Evidences}:\\\\\n") + printer.write("\\texttt{Evidences}:\\\\\n") l foreach(e => { print(s"${ids(e)} ${e.label}")(printer,spacing +1) }) diff --git a/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexDiagramPrinter.scala b/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexDiagramPrinter.scala index 618a868..5dc89b7 100644 --- a/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexDiagramPrinter.scala +++ b/src/main/scala/onera/pmlanalyzer/views/patterns/exporters/LatexDiagramPrinter.scala @@ -50,7 +50,7 @@ object LatexDiagramPrinter { def printDiagram(): File = { val writer = new FileWriter(file) writer.write( - s""" + """ |\\ifdefined\\standalone |\\documentclass{standalone} |\\usepackage[utf8]{inputenc} diff --git a/src/main/scala/onera/pmlanalyzer/views/patterns/model/PatternAST.scala b/src/main/scala/onera/pmlanalyzer/views/patterns/model/PatternAST.scala index d73c125..7d291fc 100644 --- a/src/main/scala/onera/pmlanalyzer/views/patterns/model/PatternAST.scala +++ b/src/main/scala/onera/pmlanalyzer/views/patterns/model/PatternAST.scala @@ -27,22 +27,22 @@ trait PatternAST { sealed trait Evidence extends PatternAST -case class Backing(label:String, implementation:Option[String] = None, textWidth:Option[Int] = None) extends PatternAST +final case class Backing(label:String, implementation:Option[String] = None, textWidth:Option[Int] = None) extends PatternAST -case class Defeater(label:String, implementation:Option[String] = None, textWidth:Option[Int] = None) extends PatternAST +final case class Defeater(label:String, implementation:Option[String] = None, textWidth:Option[Int] = None) extends PatternAST -case class Strategy(label:String, backing: Option[Backing] = None, defeater: Option[Defeater]=None, implementation:Option[String] = None, textWidth:Option[Int] = None) extends PatternAST{ +final case class Strategy(label:String, backing: Option[Backing] = None, defeater: Option[Defeater]=None, implementation:Option[String] = None, textWidth:Option[Int] = None) extends PatternAST{ def backing(s:String) : Strategy = copy(backing = Some(Backing(s))) def defeater(s:String): Strategy = copy(defeater = Some(Defeater(s))) } -case class FinalEvidence(label:String, implementation:Option[String] = None, textWidth: Option[Int] = None, refOf:Option[Claim]=None) extends Evidence +final case class FinalEvidence(label:String, implementation:Option[String] = None, textWidth: Option[Int] = None, refOf:Option[Claim]=None) extends Evidence -case class Given(label:String, implementation:Option[String] = None, textWidth: Option[Int] = None) extends Evidence +final case class Given(label:String, implementation:Option[String] = None, textWidth: Option[Int] = None) extends Evidence -case class Claim(label:String, short:Option[String], implementation:Option[String], textWidth:Option[Int], width:Option[Int], strategy: Strategy, evidences: Evidence*) extends Evidence { +final case class Claim(label:String, short:Option[String], implementation:Option[String], textWidth:Option[Int], width:Option[Int], strategy: Strategy, evidences: Evidence*) extends Evidence { def evidence (s:String) : Claim = Claim(label, short, implementation, textWidth, width, strategy, evidences :+ FinalEvidence(s):_*) def evidence (b:Builder) : Claim = @@ -69,14 +69,14 @@ object Claim{ val evidenceIdByLevel = collection.mutable.HashMap.empty[Int,Int].withDefaultValue(0) val givenIdByLevel = collection.mutable.HashMap.empty[Int,Int].withDefaultValue(0) - def getFreshId(level:Int, c:collection.mutable.Map[Int,Int]) : () => Int = { - c(level) = c(level) + 1 - val x = c(level) - () => (0 until level).map(i => c(i)).sum + x + def getFreshId(level:Int, ids:collection.mutable.Map[Int,Int]) : () => Int = { + ids(level) = ids(level) + 1 + val x = ids(level) + () => (0 until level).map(i => ids(i)).sum + x } - def byLevel(c: Claim, currentLevel: Int) : Map[PatternAST, () => String] = { - val cId = (for {s <- c.short if currentLevel == 0} yield () => s"($s)") getOrElse { + def byLevel(claim: Claim, currentLevel: Int) : Map[PatternAST, () => String] = { + val cId = (for {s <- claim.short if currentLevel == 0} yield () => s"($s)") getOrElse { val x = getFreshId(currentLevel,evidenceIdByLevel) () => s"(E${x()})" } @@ -84,7 +84,7 @@ object Claim{ val x = getFreshId(currentLevel,strategyIdByLevel) () => s"(W${x()})" } - c.evidences.flatMap{ + claim.evidences.flatMap{ case f:FinalEvidence => val x = getFreshId(currentLevel + 1,evidenceIdByLevel ) Set(f -> (() => s"(E${x()})")) @@ -93,13 +93,13 @@ object Claim{ Set(g -> (() => s"(G${x()})")) case c:Claim => byLevel(c,currentLevel + 1) - }.toMap + (c -> cId) + (c.strategy -> sId) + }.toMap + (claim -> cId) + (claim.strategy -> sId) } byLevel(c,0).transform((_,v) => v()) } } -case class Builder(content:String, short:Option[String], implementation:Option[String], textWidth:Option[Int], width:Option[Int]) { +final case class Builder(content:String, short:Option[String], implementation:Option[String], textWidth:Option[Int], width:Option[Int]) { def short(s:String) : Builder = Builder(content,Some(s),implementation,textWidth, width) def size(s:Int) : Builder = diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/configuration/ConfigurationTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/configuration/ConfigurationTest.scala index c920fd5..a186f58 100644 --- a/src/test/scala/onera/pmlanalyzer/pml/model/configuration/ConfigurationTest.scala +++ b/src/test/scala/onera/pmlanalyzer/pml/model/configuration/ConfigurationTest.scala @@ -46,7 +46,7 @@ class ConfigurationTest extends AnyFlatSpec with ScalaCheckPropertyChecks with s val smart1: Core = new Core() val smart2: Core = new Core() - class Core(name: Symbol) extends Composite(name) { + class Core(coreName: Symbol) extends Composite(coreName) { val core: Initiator = Initiator() val cache: Target = Target() diff --git a/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala b/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala index 1463247..d48b7cc 100644 --- a/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala +++ b/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala @@ -69,10 +69,10 @@ sealed trait ScenarioComparison { val s: Seq[String] } -case class Missing(s: Seq[String]) extends ScenarioComparison { +final case class Missing(s: Seq[String]) extends ScenarioComparison { override def toString: String = s.mkString("||") + " not found" } -case class Unknown(s: Seq[String]) extends ScenarioComparison { +final case class Unknown(s: Seq[String]) extends ScenarioComparison { override def toString: String = s.mkString("||") + " not expected" }