Skip to content

Commit

Permalink
Remove joda from anorm
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek committed Jul 6, 2024
1 parent b4100d2 commit 3f809dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
8 changes: 4 additions & 4 deletions generator/app/controllers/Generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ object Generators {
),
CodeGenTarget(
metaData = Generator(
key = "anorm_2_8_scala_3_parsers",
name = "Anorm 2.8 Scala 3 parsers",
description = Some("Generates anorm parsers. Depends on apidoc_0_x_libs generators. See https://playframework.github.io/anorm/"),
key = "anorm_2_9_scala_3_parsers",
name = "Anorm 2.9 Scala 3 parsers",
description = Some("Generates anorm parsers. See https://playframework.github.io/anorm/"),
language = Some("Scala"),
attributes = Seq("scala_generator")
),
status = lib.generator.Status.Alpha,
codeGenerator = Some(scala.generator.anorm.ParserGenerator28Scala3)
codeGenerator = Some(scala.generator.anorm.ParserGenerator29Scala3)
),
CodeGenTarget(
metaData = Generator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,49 @@ object ParserGenerator24 extends ParserGenerator {
)
}

object ParserGenerator26 extends ParserGenerator {
override val version: ScalaVersion = ScalaVersion(2)
object ParserGenerator26 extends AbstractParserGenerator26(ScalaVersion(2))

class AbstractParserGenerator26(override val version: ScalaVersion) extends ParserGenerator {
override def attributes(ssd: ScalaService): ParserGeneratorPlayVersionSpecificAttributes = {
val dateImports = ssd.attributes.dateType match {
case DateTypeConfig.JodaLocalDate => Seq(
"play.api.libs.json.JodaReads._",
)
case _ => Nil
}
val dateTimeImports = ssd.attributes.dateTimeType match {
case DateTimeTypeConfig.JodaDateTime => Seq(
"play.api.libs.json.JodaReads._",
)
case _ => Nil
}
ParserGeneratorPlayVersionSpecificAttributes(
imports = Seq(
"anorm.{Column, MetaDataItem, TypeDoesNotMatch}",
"play.api.libs.json.{JsArray, JsObject, JsValue}",
"scala.util.{Failure, Success, Try}",
) ++ (dateImports ++ dateTimeImports).distinct
baseImports ++ jodaImports(ssd)
)
}

private[this] val baseImports: Seq[String] = {
Seq(
"anorm.{Column, MetaDataItem, TypeDoesNotMatch}",
"play.api.libs.json.{JsArray, JsObject, JsValue}",
"scala.util.{Failure, Success, Try}",
)
}

private[this] def jodaImports(ssd: ScalaService): Seq[String] = {
if (version.major >= 3) {
Nil
} else {
val dateImports = ssd.attributes.dateType match {
case DateTypeConfig.JodaLocalDate => Seq(
"play.api.libs.json.JodaReads._",
)
case _ => Nil
}
val dateTimeImports = ssd.attributes.dateTimeType match {
case DateTimeTypeConfig.JodaDateTime => Seq(
"play.api.libs.json.JodaReads._",
)
case _ => Nil
}
(dateImports ++ dateTimeImports).distinct
}
}
}

object ParserGenerator28Scala2 extends AbstractParserGenerator(ScalaVersion(2))
object ParserGenerator28Scala3 extends AbstractParserGenerator(ScalaVersion(3))
object ParserGenerator29Scala3 extends AbstractParserGenerator(ScalaVersion(3))
abstract class AbstractParserGenerator(override val version: ScalaVersion) extends ParserGenerator {
override def attributes(ssd: ScalaService): ParserGeneratorPlayVersionSpecificAttributes =
ParserGenerator26.attributes(ssd)
new AbstractParserGenerator26(version).attributes(ssd)
}

case class ParserGeneratorPlayVersionSpecificAttributes(imports: Seq[String])
Expand Down

0 comments on commit 3f809dd

Please sign in to comment.