From 113264a617c479a94e32572a6f1cfdf09500bdd3 Mon Sep 17 00:00:00 2001
From: Daniel Slapman <danslapman@gmail.com>
Date: Sun, 22 Sep 2024 11:37:26 +0200
Subject: [PATCH] Update glass

---
 CHANGELOG.md                                             | 1 +
 build.sbt                                                | 9 +++++++--
 core/src/test/scala-2/morphling/samples/Person.scala     | 8 +-------
 core/src/test/scala-2/morphling/samples/Role.scala       | 5 ++---
 .../scala-2/morphling/samples/annotated/Server.scala     | 4 +---
 core/src/test/scala-3/morphling/samples/Person.scala     | 9 +--------
 core/src/test/scala-3/morphling/samples/Role.scala       | 6 ++----
 .../scala-3/morphling/samples/annotated/Server.scala     | 9 +++------
 8 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c324931..45ffcb7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 > unreleased
 
 - simulacrum-scalafix is removed
+- update `glass`
 
 ## version 3.1.0
 
diff --git a/build.sbt b/build.sbt
index 7e7c1eb..22208f7 100644
--- a/build.sbt
+++ b/build.sbt
@@ -12,7 +12,7 @@ val versions = Map(
   "paradise"                 -> "2.1.1",
   "bm4"                      -> "0.3.1",
   "scalatestplus-scalacheck" -> "3.2.11.0",
-  "glass"                    -> "0.1.0"
+  "glass"                    -> "0.3.0"
 )
 
 val scalaVersions = Seq("2.12.20", "2.13.14", "3.3.3")
@@ -37,7 +37,12 @@ lazy val morphling = (projectMatrix in file("core"))
           Seq("com.chuusai" %% "shapeless" % "2.3.3")
         case Some((3, _)) => Seq.empty[ModuleID]
       }
-    }
+    },
+    libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
+      case Some((2, y)) if y < 13 =>
+        Seq(compilerPlugin("org.scalamacros" % "paradise" % versions("paradise") cross CrossVersion.full))
+      case _ => Seq.empty[ModuleID]
+    })
   )
 
 lazy val `morphling-scalacheck` = (projectMatrix in file("scalacheck"))
diff --git a/core/src/test/scala-2/morphling/samples/Person.scala b/core/src/test/scala-2/morphling/samples/Person.scala
index c1433b6..2ada51a 100644
--- a/core/src/test/scala-2/morphling/samples/Person.scala
+++ b/core/src/test/scala-2/morphling/samples/Person.scala
@@ -9,6 +9,7 @@ import morphling.samples.annotated.AnnPerson
 
 import java.time.Instant
 
+@Optics
 case class Person(
     name: String,
     birthDate: Instant,
@@ -19,13 +20,6 @@ case class Person(
 )
 
 object Person {
-  val name                                   = GenContains[Person](_.name)
-  val birthDate                              = GenContains[Person](_.birthDate)
-  val roles                                  = GenContains[Person](_.roles)
-  val updateCounter                          = GenContains[Person](_.updateCounter)
-  val stamp                                  = GenContains[Person](_.stamp)
-  val ignored: Contains[Person, Option[Any]] = GenContains[Person](_.ignored)
-
   private val instantIso = Equivalent[Long](Instant.ofEpochMilli _)(_.toEpochMilli)
 
   val schema: Schema[SSchema, Person] = rec(
diff --git a/core/src/test/scala-2/morphling/samples/Role.scala b/core/src/test/scala-2/morphling/samples/Role.scala
index 54dca9f..1b0d8c2 100644
--- a/core/src/test/scala-2/morphling/samples/Role.scala
+++ b/core/src/test/scala-2/morphling/samples/Role.scala
@@ -51,9 +51,8 @@ case object User extends Role {
   val prism = GenSubset[Role, User.type]
 }
 
+@Optics
 case class Administrator(department: String, subordinateCount: Int) extends Role
 object Administrator {
-  val department       = GenContains[Administrator](_.department)
-  val subordinateCount = GenContains[Administrator](_.subordinateCount)
-  val prism            = GenSubset[Role, Administrator]
+  val prism = GenSubset[Role, Administrator]
 }
diff --git a/core/src/test/scala-2/morphling/samples/annotated/Server.scala b/core/src/test/scala-2/morphling/samples/annotated/Server.scala
index 817d515..220b1f0 100644
--- a/core/src/test/scala-2/morphling/samples/annotated/Server.scala
+++ b/core/src/test/scala-2/morphling/samples/annotated/Server.scala
@@ -6,11 +6,9 @@ import morphling.annotated.Schema.*
 import morphling.protocol.annotated.Range
 import morphling.protocol.annotated.STypeAnn.*
 
+@Optics
 case class Server(host: String, port: Int)
 object Server {
-  val host = GenContains[Server](_.host)
-  val port = GenContains[Server](_.port)
-
   val schema: Schema[ASchema, Server] = rec(
     (
       required("host", sStr(), host),
diff --git a/core/src/test/scala-3/morphling/samples/Person.scala b/core/src/test/scala-3/morphling/samples/Person.scala
index fdb449c..d9c6f2e 100644
--- a/core/src/test/scala-3/morphling/samples/Person.scala
+++ b/core/src/test/scala-3/morphling/samples/Person.scala
@@ -18,14 +18,7 @@ case class Person(
     ignored: Option[Any]
 )
 
-object Person {
-  val name                                   = GenContains[Person](_.name)
-  val birthDate                              = GenContains[Person](_.birthDate)
-  val roles                                  = GenContains[Person](_.roles)
-  val updateCounter                          = GenContains[Person](_.updateCounter)
-  val stamp                                  = GenContains[Person](_.stamp)
-  val ignored: Contains[Person, Option[Any]] = GenContains[Person](_.ignored)
-
+object Person extends DeriveContains {
   private val instantIso = Equivalent[Long](Instant.ofEpochMilli(_))(_.toEpochMilli)
 
   val schema: Schema[SSchema, Person] = rec(
diff --git a/core/src/test/scala-3/morphling/samples/Role.scala b/core/src/test/scala-3/morphling/samples/Role.scala
index f96ab5d..cb18fe4 100644
--- a/core/src/test/scala-3/morphling/samples/Role.scala
+++ b/core/src/test/scala-3/morphling/samples/Role.scala
@@ -56,8 +56,6 @@ case object User extends Role {
 }
 
 case class Administrator(department: String, subordinateCount: Int) extends Role
-object Administrator {
-  val department       = GenContains[Administrator](_.department)
-  val subordinateCount = GenContains[Administrator](_.subordinateCount)
-  val prism            = GenSubset[Role, Administrator]
+object Administrator extends DeriveContains {
+  val prism = GenSubset[Role, Administrator]
 }
diff --git a/core/src/test/scala-3/morphling/samples/annotated/Server.scala b/core/src/test/scala-3/morphling/samples/annotated/Server.scala
index 817d515..7e68036 100644
--- a/core/src/test/scala-3/morphling/samples/annotated/Server.scala
+++ b/core/src/test/scala-3/morphling/samples/annotated/Server.scala
@@ -7,14 +7,11 @@ import morphling.protocol.annotated.Range
 import morphling.protocol.annotated.STypeAnn.*
 
 case class Server(host: String, port: Int)
-object Server {
-  val host = GenContains[Server](_.host)
-  val port = GenContains[Server](_.port)
-
+object Server extends DeriveContains {
   val schema: Schema[ASchema, Server] = rec(
     (
-      required("host", sStr(), host),
-      required("port", sInt(Range(1, 65535)), port)
+      required("host", sStr(), this.host),
+      required("port", sInt(Range(1, 65535)), this.port)
     ).mapN(Server.apply)
   )
 }