From 9347efd2dcd3e3fbbd7c8144fb066f05f91419c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sat, 21 Nov 2020 17:20:16 +0100 Subject: [PATCH 01/11] Cross compile to Scala 3.0.0-M1 --- CHANGELOG.md | 1 + build.sbt | 14 +++++++++----- .../main/scala/io/cucumber/scala/GlueAdaptor.scala | 2 +- .../main/scala/io/cucumber/scala/Implicits.scala | 6 +++--- .../main/scala/io/cucumber/scala/ScalaDsl.scala | 3 ++- .../examples/scalacalculator/RpnCalculator.scala | 4 ++-- project/I18nGenerator.scala | 2 +- project/ScalacOptions.scala | 14 ++++++++++++++ project/plugins.sbt | 3 +++ 9 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15003b25..82d108ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH - [Build] Setup formatting using `scalafmt` - [CI] Build & test on both JDK 8 and 11 +- [Build] Cross compilation with Scala 3.0.0-M1 ### Changed diff --git a/build.sbt b/build.sbt index dc2acd5c..c39df7fe 100644 --- a/build.sbt +++ b/build.sbt @@ -33,6 +33,7 @@ ThisBuild / homepage := Some( val scala211 = "2.11.12" val scala212 = "2.12.12" val scala213 = "2.13.3" +val scala3 = "3.0.0-M1" scalaVersion := scala213 @@ -52,9 +53,11 @@ lazy val commonSettings = Seq( case Some((2, 11)) => ScalacOptions.scalacOptions211 case Some((2, 12)) => ScalacOptions.scalacOptions212 case Some((2, 13)) => ScalacOptions.scalacOptions213 + case Some((3, 0)) => ScalacOptions.scalacOptions3 case _ => Seq() } - } + }, + scalacOptions ++= { if (isDotty.value) Seq("-source:3.0") else Nil } ) lazy val root = (project in file(".")) @@ -76,10 +79,11 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala")) "io.cucumber" % "cucumber-core" % cucumberVersion, // Users have to provide it (for JacksonDefaultDataTableTransformer) "com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion % Provided, - "com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided, + ("com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided).withDottyCompat(scalaVersion.value), + "junit" % "junit" % junitVersion % Test, "io.cucumber" % "cucumber-junit" % cucumberVersion % Test, - "org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test + ("org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test).withDottyCompat(scalaVersion.value) ), libraryDependencies ++= { CrossVersion.partialVersion(scalaVersion.value) match { @@ -103,7 +107,7 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala")) Seq(file) }.taskValue ) - .jvmPlatform(scalaVersions = Seq(scala213, scala212, scala211)) + .jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212, scala211)) // Examples project lazy val examples = (projectMatrix in file("examples")) @@ -117,7 +121,7 @@ lazy val examples = (projectMatrix in file("examples")) publishArtifact := false ) .dependsOn(cucumberScala % Test) - .jvmPlatform(scalaVersions = Seq(scala213, scala212)) + .jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212)) // Release & Publish diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/GlueAdaptor.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/GlueAdaptor.scala index 09fc1819..7fbd3207 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/GlueAdaptor.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/GlueAdaptor.scala @@ -16,7 +16,7 @@ class GlueAdaptor(glue: Glue) { // If the registry is not consistent, this indicates a mistake in the users definition and we want to let him know. registry.checkConsistency().left.foreach { - ex: IncorrectHookDefinitionException => + (ex: IncorrectHookDefinitionException) => throw ex } diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala index 31757559..05364511 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala @@ -33,7 +33,7 @@ object Implicits { table .asMaps[K, V](evK.runtimeClass, evV.runtimeClass) .asScala - .map(_.asScala.map(nullToNone).toMap) + .map(_.asScala.map(nullToNone(_)).toMap) .toSeq } @@ -79,7 +79,7 @@ object Implicits { table .asMap[K, V](evK.runtimeClass, evV.runtimeClass) .asScala - .map(nullToNone) + .map(nullToNone(_)) .toMap } @@ -172,7 +172,7 @@ object Implicits { classOf[java.util.Map[String, String]] ) .asScala - .map { case (k, v) => (k, v.asScala.map(nullToNone).toMap) } + .map { case (k, v) => (k, v.asScala.map(nullToNone(_)).toMap) } .toMap } diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala index b72a7dce..a3d7f0ca 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala @@ -1155,7 +1155,8 @@ private[scala] trait StepDsl extends BaseScalaDsl { * **/ def apply(f: => Unit): Unit = { - apply(() => f) + val fun0 = () => f + apply(fun0) } def apply(fun: Fun0): Unit = { diff --git a/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala b/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala index 09d4b3d9..e012c4c5 100644 --- a/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala +++ b/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala @@ -5,8 +5,8 @@ import scala.collection.mutable.Queue sealed trait Arg object Arg { - implicit def op(s: String) = Op(s) - implicit def value(v: Double) = Val(v) + implicit def op(s:String): Op = Op(s) + implicit def value(v:Double): Val = Val(v) } case class Op(value: String) extends Arg diff --git a/project/I18nGenerator.scala b/project/I18nGenerator.scala index bd750759..42ca9852 100644 --- a/project/I18nGenerator.scala +++ b/project/I18nGenerator.scala @@ -16,7 +16,7 @@ object I18nGenerator { private def keywordVal(kw: String): String = { val keyworkValName = java.text.Normalizer .normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC) - s"""val $keyworkValName = new Step("$keyworkValName")""" + s""" val $keyworkValName = new Step("$keyworkValName")""" } private def traitCode(language: String): String = { diff --git a/project/ScalacOptions.scala b/project/ScalacOptions.scala index 948e0900..fd7bfbb7 100644 --- a/project/ScalacOptions.scala +++ b/project/ScalacOptions.scala @@ -1,5 +1,19 @@ object ScalacOptions { + val scalacOptions3 = Seq( + "-rewrite", + "-deprecation", // Emit warning and location for usages of deprecated APIs. + "-explain", // Explain type errors in more detail. +// "-explaintypes", // Explain type errors in more detail. + "-feature", // Emit warning and location for usages of features that should be imported explicitly. + "-language:existentials", // Existential types (besides wildcard types) can be written and inferred + "-language:experimental.macros", // Allow macro definition (besides implementation and application) + "-language:higherKinds", // Allow higher-kinded types + "-language:implicitConversions", // Allow definition of implicit functions called views + "-unchecked", // Enable additional warnings where generated code depends on assumptions. + "-Xfatal-warnings" // Fail the compilation if there are any warnings. + ) + // Source: https://nathankleyn.com/2019/05/13/recommended-scalac-flags-for-2-13/ val scalacOptions213 = Seq( "-deprecation", // Emit warning and location for usages of deprecated APIs. diff --git a/project/plugins.sbt b/project/plugins.sbt index f9f51a59..89cab943 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,6 +4,9 @@ addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.6.0") // Scalafmt (formatter) addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") +// Scala 3 (Dotty) +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6") + // Release addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") From 87c8f018952ab08b79279ca1f906c72470fd7f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sun, 29 Nov 2020 11:56:41 +0100 Subject: [PATCH 02/11] Scala 3.0.0-M2 --- CHANGELOG.md | 2 +- build.sbt | 5 ++--- .../src/main/scala/io/cucumber/scala/Implicits.scala | 6 +++--- .../cucumber/examples/scalacalculator/RpnCalculator.scala | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d108ba..3c6f8fe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH - [Build] Setup formatting using `scalafmt` - [CI] Build & test on both JDK 8 and 11 -- [Build] Cross compilation with Scala 3.0.0-M1 +- [Build] Cross compilation with Scala 3.0.0-M2 ### Changed diff --git a/build.sbt b/build.sbt index c39df7fe..ee15d9b3 100644 --- a/build.sbt +++ b/build.sbt @@ -33,7 +33,7 @@ ThisBuild / homepage := Some( val scala211 = "2.11.12" val scala212 = "2.12.12" val scala213 = "2.13.3" -val scala3 = "3.0.0-M1" +val scala3 = "3.0.0-M2" scalaVersion := scala213 @@ -56,8 +56,7 @@ lazy val commonSettings = Seq( case Some((3, 0)) => ScalacOptions.scalacOptions3 case _ => Seq() } - }, - scalacOptions ++= { if (isDotty.value) Seq("-source:3.0") else Nil } + } ) lazy val root = (project in file(".")) diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala index 05364511..31757559 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/Implicits.scala @@ -33,7 +33,7 @@ object Implicits { table .asMaps[K, V](evK.runtimeClass, evV.runtimeClass) .asScala - .map(_.asScala.map(nullToNone(_)).toMap) + .map(_.asScala.map(nullToNone).toMap) .toSeq } @@ -79,7 +79,7 @@ object Implicits { table .asMap[K, V](evK.runtimeClass, evV.runtimeClass) .asScala - .map(nullToNone(_)) + .map(nullToNone) .toMap } @@ -172,7 +172,7 @@ object Implicits { classOf[java.util.Map[String, String]] ) .asScala - .map { case (k, v) => (k, v.asScala.map(nullToNone(_)).toMap) } + .map { case (k, v) => (k, v.asScala.map(nullToNone).toMap) } .toMap } diff --git a/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala b/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala index e012c4c5..3e038d48 100644 --- a/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala +++ b/examples/src/main/scala/cucumber/examples/scalacalculator/RpnCalculator.scala @@ -5,8 +5,8 @@ import scala.collection.mutable.Queue sealed trait Arg object Arg { - implicit def op(s:String): Op = Op(s) - implicit def value(v:Double): Val = Val(v) + implicit def op(s: String): Op = Op(s) + implicit def value(v: Double): Val = Val(v) } case class Op(value: String) extends Arg From 1245833d9e65f8dcb70f33357bcf31b6073f80c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sun, 29 Nov 2020 12:35:39 +0100 Subject: [PATCH 03/11] WIP shit --- .../io/cucumber/scala/ScalaDslStepsTest.scala | 32 ++-- .../steps/classes/MultipleInSameFile.scala | 8 +- .../scala/steps/classes/SingleFile.scala | 4 +- .../scala/steps/objects/StepsInObject.scala | 4 +- .../scala/steps/traits/StepsInTrait.scala | 4 +- .../src/test/scala/tests/cukes/StepDefs.scala | 148 +++++++++--------- project/ScalacOptions.scala | 1 + 7 files changed, 100 insertions(+), 101 deletions(-) diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslStepsTest.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslStepsTest.scala index b406ab15..d4449f17 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslStepsTest.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslStepsTest.scala @@ -39,9 +39,9 @@ class ScalaDslStepsTest { var invoked = false class Glue extends ScalaDsl with EN { - Given("Something") { () => + Given("Something") ((() => { invoked = true - } + })) } val glue = new Glue() @@ -62,10 +62,10 @@ class ScalaDslStepsTest { var thecolour = "" class Glue extends ScalaDsl with EN { - Given("""Oh boy, (\d+) (\s+) cukes""") { (num: Int, colour: String) => + Given("""Oh boy, (\d+) (\s+) cukes""") (((num: Int, colour: String) => { thenumber = num thecolour = colour - } + })) } val glue = new Glue() @@ -83,10 +83,10 @@ class ScalaDslStepsTest { def testDefThrowException(): Unit = { class GlueWithException extends ScalaDsl with EN { - Given("Something") { () => + Given("Something") ((() => { val x = 1 + 2 // A not useful line throw new PendingException() - } + })) } val glue = new GlueWithException() @@ -106,10 +106,10 @@ class ScalaDslStepsTest { def testDefNullParameters(): Unit = { class Glue extends ScalaDsl with EN { - Given("Something {}") { (str: String) => + Given("Something {}") (((str: String) => { // Nothing println(str) - } + })) } val glue = new Glue() @@ -154,9 +154,9 @@ class ScalaDslStepsTest { var invoked = false object Glue extends ScalaDsl with EN { - Given("Something") { () => + Given("Something") ((() => { invoked = true - } + })) } assertObjectStepDefinition( @@ -175,10 +175,10 @@ class ScalaDslStepsTest { var thecolour = "" object Glue extends ScalaDsl with EN { - Given("""Oh boy, (\d+) (\s+) cukes""") { (num: Int, colour: String) => + Given("""Oh boy, (\d+) (\s+) cukes""") (((num: Int, colour: String) => { thenumber = num thecolour = colour - } + })) } assertObjectStepDefinition( @@ -194,10 +194,10 @@ class ScalaDslStepsTest { def testObjectDefThrowException(): Unit = { object GlueWithException extends ScalaDsl with EN { - Given("Something") { () => + Given("Something") ((() => { val x = 1 + 2 // A not useful line throw new PendingException() - } + })) } assertObjectStepDefinitionThrow( @@ -215,10 +215,10 @@ class ScalaDslStepsTest { def testObjectDefNullParameters(): Unit = { object Glue extends ScalaDsl with EN { - Given("Something {}") { (str: String) => + Given("Something {}") (((str: String) => { // Nothing println(str) - } + })) } assertClassStepDefinitionThrow( diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala index 032e2d51..f6169f6d 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala @@ -20,16 +20,16 @@ class StepsA extends ScalaDsl with EN { // Nothing } - Given("""stepA""") { () => + Given("""stepA""") ((() => { // Nothing - } + })) } class StepsB extends ScalaDsl with EN { - When("""stepsB""") { () => + When("""stepsB""") ((() => { // Nothing - } + })) } diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/SingleFile.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/SingleFile.scala index f7519b78..66c56f58 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/SingleFile.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/SingleFile.scala @@ -4,8 +4,8 @@ import io.cucumber.scala.{EN, ScalaDsl} class StepsC extends ScalaDsl with EN { - Then("""stepsC""") { () => + Then("""stepsC""") ((() => { // Nothing - } + })) } diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala index feb7d8f9..3e870b71 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala @@ -20,8 +20,8 @@ object StepsInObject extends ScalaDsl with EN { // Nothing } - Given("""Given step""") { () => + Given("""Given step""") ((() => { // Nothing - } + })) } diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala index 7c1b5478..8e9e628f 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala @@ -20,9 +20,9 @@ trait TraitWithSteps extends ScalaDsl with EN { // Nothing } - Given("""Given step""") { () => + Given("""Given step""") ((() => { // Nothing - } + })) } diff --git a/cucumber-scala/src/test/scala/tests/cukes/StepDefs.scala b/cucumber-scala/src/test/scala/tests/cukes/StepDefs.scala index 36babd95..6114e7c7 100644 --- a/cucumber-scala/src/test/scala/tests/cukes/StepDefs.scala +++ b/cucumber-scala/src/test/scala/tests/cukes/StepDefs.scala @@ -15,124 +15,122 @@ import scala.jdk.CollectionConverters._ @nowarn class CukesStepDefinitions extends ScalaDsl with EN { - Given("""I have {} {string} in my belly""") { (howMany: Int, what: String) => - } + Given("""I have {} {string} in my belly""") (((howMany: Int, what: String) => { + })) var calorieCount = 0.0 - Given("""^I have the following foods :$""") { (table: DataTable) => + Given("""^I have the following foods :$""") (((table: DataTable) => { val maps: JList[JMap[String, String]] = table.asMaps(classOf[String], classOf[String]) calorieCount = maps.asScala.map(_.get("CALORIES")).map(_.toDouble).fold(0.0)(_ + _) - } - And("""have eaten {double} calories today""") { (calories: Double) => + })) + And("""have eaten {double} calories today""") (((calories: Double) => { assertEquals(calories, calorieCount, 0.0) - } + })) var intBelly: Int = 0 - Given("""I have eaten an int {int}""") { (arg0: Int) => + Given("""I have eaten an int {int}""") (((arg0: Int) => { intBelly = arg0 - } - Then("""^I should have one hundred in my belly$""") { () => + })) + Then("""^I should have one hundred in my belly$""") ((() => { assertEquals(100, intBelly) - } + })) var longBelly: Long = 0L - Given("""I have eaten a long {long}""") { (arg0: Long) => + Given("""I have eaten a long {long}""") (((arg0: Long) => { longBelly = arg0 - } - Then("""^I should have long one hundred in my belly$""") { () => + })) + Then("""^I should have long one hundred in my belly$""") ((() => { assertEquals(100L, longBelly) - } + })) var stringBelly: String = "" - Given("""^I have eaten "(.*)"$""") { (arg0: String) => + Given("""^I have eaten "(.*)"$""") (((arg0: String) => { stringBelly = arg0 - } - Then("""^I should have numnumnum in my belly$""") { () => + })) + Then("""^I should have numnumnum in my belly$""") ((() => { assertEquals("numnumnum", stringBelly) - } + })) var doubleBelly: Double = 0.0 - Given("""I have eaten {double} doubles""") { (arg0: Double) => + Given("""I have eaten {double} doubles""") (((arg0: Double) => { doubleBelly = arg0 - } - Then("""^I should have one and a half doubles in my belly$""") { () => + })) + Then("""^I should have one and a half doubles in my belly$""") ((() => { assertEquals(1.5, doubleBelly, 0.0) - } + })) var floatBelly: Float = 0.0f - Given("""I have eaten {} floats""") { (arg0: Float) => + Given("""I have eaten {} floats""") (((arg0: Float) => { floatBelly = arg0 - } - Then("""^I should have one and a half floats in my belly$""") { () => + })) + Then("""^I should have one and a half floats in my belly$""") ((() => { assertEquals(1.5f, floatBelly, 0.0) - } + })) var shortBelly: Short = 0.toShort - Given("""I have eaten a short {short}""") { (arg0: Short) => + Given("""I have eaten a short {short}""") (((arg0: Short) => { shortBelly = arg0 - } - Then("""^I should have short one hundred in my belly$""") { () => + })) + Then("""^I should have short one hundred in my belly$""") ((() => { assertEquals(100.toShort, shortBelly) - } + })) var byteBelly: Byte = 0.toByte - Given("""I have eaten a byte {byte}""") { (arg0: Byte) => + Given("""I have eaten a byte {byte}""") (((arg0: Byte) => { byteBelly = arg0 - } - Then("""^I should have two byte in my belly$""") { () => + })) + Then("""^I should have two byte in my belly$""") ((() => { assertEquals(2.toByte, byteBelly) - } + })) var bigDecimalBelly: BigDecimal = BigDecimal(0) - Given("""I have eaten {bigdecimal} big decimals""") { - (arg0: java.math.BigDecimal) => + Given("""I have eaten {bigdecimal} big decimals""") (((arg0: java.math.BigDecimal) => { bigDecimalBelly = arg0 - } - Then("""^I should have one and a half big decimals in my belly$""") { () => + })) + Then("""^I should have one and a half big decimals in my belly$""") ((() => { assertEquals(BigDecimal(1.5), bigDecimalBelly) - } + })) var bigIntBelly: BigInt = BigInt(0) - Given("""I have eaten {biginteger} big int""") { - (arg0: java.math.BigInteger) => + Given("""I have eaten {biginteger} big int""") (((arg0: java.math.BigInteger) => { bigIntBelly = arg0.intValue() - } - Then("""^I should have a ten big int in my belly$""") { () => + })) + Then("""^I should have a ten big int in my belly$""") ((() => { assertEquals(BigInt(10), bigIntBelly) - } + })) var charBelly: Char = 'A' - Given("""I have eaten char '{char}'""") { (arg0: Char) => + Given("""I have eaten char '{char}'""") (((arg0: Char) => { charBelly = 'C' - } - Then("""^I should have character C in my belly$""") { () => + })) + Then("""^I should have character C in my belly$""") ((() => { assertEquals('C', charBelly) - } + })) var boolBelly: Boolean = false - Given("""I have eaten boolean {boolean}""") { (arg0: Boolean) => + Given("""I have eaten boolean {boolean}""") (((arg0: Boolean) => { boolBelly = arg0 - } - Then("""^I should have truth in my belly$""") { () => + })) + Then("""^I should have truth in my belly$""") ((() => { assertEquals(true, boolBelly) - } + })) - Given("""I have a table the sum of all rows should be {int} :""") { - (value: Int, table: DataTable) => + Given("""I have a table the sum of all rows should be {int} :""") (( + (value: Int, table: DataTable) => { assertEquals( value, table @@ -142,62 +140,62 @@ class CukesStepDefinitions extends ScalaDsl with EN { .map(String.valueOf(_: String).toInt) .foldLeft(0)(_ + _) ) - } + })) var snake: Snake = null - Given("""I see in the distance ... {snake}""") { (s: Snake) => + Given("""I see in the distance ... {snake}""") (((s: Snake) => { snake = s - } - Then("""^I have a snake of length (\d+) moving (.*)$""") { - (size: Int, dir: String) => + })) + Then("""^I have a snake of length (\d+) moving (.*)$""") (( + (size: Int, dir: String) => { assertEquals(size, snake.length) assertEquals(Symbol(dir), snake.direction) - } + })) var person: Person = null - Given("""I have a person {person}""") { (p: Person) => + Given("""I have a person {person}""") (((p: Person) => { person = p - } + })) - Then("""^he should say \"(.*)\"""") { s: String => + Then("""^he should say \"(.*)\"""") (((s: String) => { assertEquals(person.hello, s) - } + })) var cukes: JList[Cukes] = null - Given("^I have eaten the following cukes$") { cs: JList[Cukes] => + Given("^I have eaten the following cukes$") (((cs: JList[Cukes]) => { cukes = cs - } + })) - Then("""I should have eaten {int} cukes""") { total: Int => + Then("""I should have eaten {int} cukes""") (( (total: Int) => { assertEquals(total, cukes.asScala.map(_.number).sum) - } + })) - And("^they should have been (.*)$") { colors: String => + And("^they should have been (.*)$") (((colors: String) => { assertEquals(colors, cukes.asScala.map(_.color).mkString(", ")) - } + })) var gin: Int = 13 var vermouth: Int = 42 var maritinis: Int = 0 - Given("^I drink gin and vermouth$") { () => + Given("^I drink gin and vermouth$") ((() => { gin = 13 vermouth = 42 - } + })) When("^I shake my belly$") { //note the lack of () => maritinis += vermouth * gin } - Then("^I should have lots of martinis$") { () => + Then("^I should have lots of martinis$") ((() => { assertEquals(13 * 42, maritinis) - } + })) } @nowarn class ThenDefs extends ScalaDsl with EN { - Then("""^I am "([^"]*)"$""") { (arg0: String) => } + Then("""^I am "([^"]*)"$""") (((arg0: String) => { })) } diff --git a/project/ScalacOptions.scala b/project/ScalacOptions.scala index fd7bfbb7..a148a2e7 100644 --- a/project/ScalacOptions.scala +++ b/project/ScalacOptions.scala @@ -2,6 +2,7 @@ object ScalacOptions { val scalacOptions3 = Seq( "-rewrite", + "-source:3.0-migration", "-deprecation", // Emit warning and location for usages of deprecated APIs. "-explain", // Explain type errors in more detail. // "-explaintypes", // Explain type errors in more detail. From a1253aa31013156a9e5f37449315b0873fceada7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sun, 20 Dec 2020 15:54:02 +0100 Subject: [PATCH 04/11] scala 3 m3 --- CHANGELOG.md | 2 +- build.sbt | 11 ++++++----- project/build.properties | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5e0a7a..119991a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH - [Build] Setup formatting using `scalafmt` - [CI] Build & test on both JDK 8 and 11 -- [Build] Cross compilation with Scala 3.0.0-M2 +- [Build] Cross compilation with Scala 3.0.0-M3 ### Changed diff --git a/build.sbt b/build.sbt index 6198905f..561b4898 100644 --- a/build.sbt +++ b/build.sbt @@ -33,7 +33,7 @@ ThisBuild / homepage := Some( val scala211 = "2.11.12" val scala212 = "2.12.12" val scala213 = "2.13.3" -val scala3 = "3.0.0-M2" +val scala3 = "3.0.0-M3" scalaVersion := scala213 @@ -53,7 +53,7 @@ lazy val commonSettings = Seq( case Some((2, 11)) => ScalacOptions.scalacOptions211 case Some((2, 12)) => ScalacOptions.scalacOptions212 case Some((2, 13)) => ScalacOptions.scalacOptions213 - case Some((3, 0)) => ScalacOptions.scalacOptions3 + case Some((3, 0)) => ScalacOptions.scalacOptions3 case _ => Seq() } } @@ -77,11 +77,12 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala")) libraryDependencies ++= Seq( "io.cucumber" % "cucumber-core" % cucumberVersion, // Users have to provide it (for JacksonDefaultDataTableTransformer) - ("com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided).withDottyCompat(scalaVersion.value), - + ("com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided) + .withDottyCompat(scalaVersion.value), "junit" % "junit" % junitVersion % Test, "io.cucumber" % "cucumber-junit" % cucumberVersion % Test, - ("org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test).withDottyCompat(scalaVersion.value) + ("org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test) + .withDottyCompat(scalaVersion.value) ), libraryDependencies ++= { CrossVersion.partialVersion(scalaVersion.value) match { diff --git a/project/build.properties b/project/build.properties index 0837f7a1..c06db1bb 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.13 +sbt.version=1.4.5 From 6581b15637bd142da105c7eeab43ba903c81c905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sun, 20 Dec 2020 15:56:20 +0100 Subject: [PATCH 05/11] scala 3 m3 --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 89cab943..4401c4b0 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -5,7 +5,7 @@ addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.6.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") // Scala 3 (Dotty) -addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6") +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.1") // Release addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") From 23e58d10b1cd5fba94afb70957e69654a411506c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Tue, 22 Dec 2020 18:31:45 +0100 Subject: [PATCH 06/11] wip scala 3 macro --- build.sbt | 10 +- .../io/cucumber/scala/ScalaTypeHelper.scala | 0 .../scala-2/io/cucumber/scala/StepDsl.scala | 1544 ++++++++++ .../scala-3.0/io/cucumber/scala/Macros.scala | 41 + .../scala-3.0/io/cucumber/scala/StepDsl.scala | 82 + .../io/cucumber/scala/BaseScalaDsl.scala | 12 + .../io/cucumber/scala/DataTableTypeDsl.scala | 97 + .../scala/DefaultTransformerDsl.scala | 90 + .../io/cucumber/scala/DocStringTypeDsl.scala | 24 + .../scala/io/cucumber/scala/HookDsl.scala | 143 + .../io/cucumber/scala/ParameterTypeDsl.scala | 754 +++++ .../scala/io/cucumber/scala/ScalaDsl.scala | 2646 ----------------- .../cucumber/scala/ScalaStepDefinition.scala | 4 +- .../io/cucumber/scala/ScalaStepDetails.scala | 4 +- 14 files changed, 2800 insertions(+), 2651 deletions(-) rename cucumber-scala/src/main/{scala => scala-2}/io/cucumber/scala/ScalaTypeHelper.scala (100%) create mode 100644 cucumber-scala/src/main/scala-2/io/cucumber/scala/StepDsl.scala create mode 100644 cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala create mode 100644 cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala create mode 100644 cucumber-scala/src/main/scala/io/cucumber/scala/BaseScalaDsl.scala create mode 100644 cucumber-scala/src/main/scala/io/cucumber/scala/DataTableTypeDsl.scala create mode 100644 cucumber-scala/src/main/scala/io/cucumber/scala/DefaultTransformerDsl.scala create mode 100644 cucumber-scala/src/main/scala/io/cucumber/scala/DocStringTypeDsl.scala create mode 100644 cucumber-scala/src/main/scala/io/cucumber/scala/HookDsl.scala create mode 100644 cucumber-scala/src/main/scala/io/cucumber/scala/ParameterTypeDsl.scala diff --git a/build.sbt b/build.sbt index 15f93c18..177bc742 100644 --- a/build.sbt +++ b/build.sbt @@ -94,8 +94,14 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala")) unmanagedSourceDirectories in Compile ++= { val sourceDir = (sourceDirectory in Compile).value CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, n)) if n <= 11 => Seq(sourceDir / "scala-2.11") - case _ => Seq() + case Some((2, n)) if n > 11 => + Seq(sourceDir / "scala-2") + case Some((2, n)) if n <= 11 => + Seq(sourceDir / "scala-2", sourceDir / "scala-2.11") + case Some((3, 0)) => + Seq(sourceDir / "scala-3.0") + case _ => + Seq() } }, // Generate I18n traits diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaTypeHelper.scala b/cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala similarity index 100% rename from cucumber-scala/src/main/scala/io/cucumber/scala/ScalaTypeHelper.scala rename to cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala diff --git a/cucumber-scala/src/main/scala-2/io/cucumber/scala/StepDsl.scala b/cucumber-scala/src/main/scala-2/io/cucumber/scala/StepDsl.scala new file mode 100644 index 00000000..3ed75915 --- /dev/null +++ b/cucumber-scala/src/main/scala-2/io/cucumber/scala/StepDsl.scala @@ -0,0 +1,1544 @@ +package io.cucumber.scala + +private[scala] trait StepDsl extends BaseScalaDsl { + self => + + final class Step(name: String) { + def apply(regex: String): StepBody = new StepBody(name, regex) + } + + final class Fun0(val f: Function0[Any]) + + object Fun0 { + + implicit def function0AsFun0(f: Function0[Any]): Fun0 = new Fun0(f) + + } + + final class StepBody(name: String, regex: String) { + + /* + * apply0 needs to be able to handle both calls by value and reference. + * + * Call by value: + * + * And("^multipy the things$") { + * z = x * y; + * } + * + * Call by reference: + * + * And("^multipy the things$") { ()=> + * z = x * y; + * } + * + * Call by value has the signature => Unit while call by reference has the signature () => Any + * + * Due to type erasure both would end up with the signature () => Unit. + * + * Fun0 and the implicit conversion lets us work around this. + * + **/ + def apply(f: => Unit): Unit = { + val fun0 = () => f + apply(fun0) + } + + def apply(fun: Fun0): Unit = { + register() { + case Nil => fun.f() + case _ => + throw new IncorrectStepDefinitionException() + } + } + + /* + * Generated apply1 to apply22 below + */ + def apply[T1](f: (T1) => Any)(implicit m1: Manifest[T1]): Unit = { + register(m1) { + case List(a1: AnyRef) => + f(a1.asInstanceOf[T1]) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2]( + f: (T1, T2) => Any + )(implicit m1: Manifest[T1], m2: Manifest[T2]): Unit = { + register(m1, m2) { + case List(a1: AnyRef, a2: AnyRef) => + f(a1.asInstanceOf[T1], a2.asInstanceOf[T2]) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3]( + f: (T1, T2, T3) => Any + )(implicit m1: Manifest[T1], m2: Manifest[T2], m3: Manifest[T3]): Unit = { + register(m1, m2, m3) { + case List(a1: AnyRef, a2: AnyRef, a3: AnyRef) => + f(a1.asInstanceOf[T1], a2.asInstanceOf[T2], a3.asInstanceOf[T3]) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4](f: (T1, T2, T3, T4) => Any)(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4] + ): Unit = { + register(m1, m2, m3, m4) { + case List(a1: AnyRef, a2: AnyRef, a3: AnyRef, a4: AnyRef) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5](f: (T1, T2, T3, T4, T5) => Any)(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5] + ): Unit = { + register(m1, m2, m3, m4, m5) { + case List(a1: AnyRef, a2: AnyRef, a3: AnyRef, a4: AnyRef, a5: AnyRef) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6]( + f: (T1, T2, T3, T4, T5, T6) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6] + ): Unit = { + register(m1, m2, m3, m4, m5, m6) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7]( + f: (T1, T2, T3, T4, T5, T6, T7) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8]( + f: (T1, T2, T3, T4, T5, T6, T7, T8) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9]( + f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8, m9) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( + f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( + f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( + f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( + f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( + f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14] + ): Unit = { + register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16], + m17: Manifest[T17] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef, + a17: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16], + m17: Manifest[T17], + m18: Manifest[T18] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef, + a17: AnyRef, + a18: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16], + m17: Manifest[T17], + m18: Manifest[T18], + m19: Manifest[T19] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef, + a17: AnyRef, + a18: AnyRef, + a19: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16], + m17: Manifest[T17], + m18: Manifest[T18], + m19: Manifest[T19], + m20: Manifest[T20] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19, + m20 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef, + a17: AnyRef, + a18: AnyRef, + a19: AnyRef, + a20: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19], + a20.asInstanceOf[T20] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16], + m17: Manifest[T17], + m18: Manifest[T18], + m19: Manifest[T19], + m20: Manifest[T20], + m21: Manifest[T21] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19, + m20, + m21 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef, + a17: AnyRef, + a18: AnyRef, + a19: AnyRef, + a20: AnyRef, + a21: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19], + a20.asInstanceOf[T20], + a21.asInstanceOf[T21] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + def apply[ + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22 + ]( + f: ( + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22 + ) => Any + )(implicit + m1: Manifest[T1], + m2: Manifest[T2], + m3: Manifest[T3], + m4: Manifest[T4], + m5: Manifest[T5], + m6: Manifest[T6], + m7: Manifest[T7], + m8: Manifest[T8], + m9: Manifest[T9], + m10: Manifest[T10], + m11: Manifest[T11], + m12: Manifest[T12], + m13: Manifest[T13], + m14: Manifest[T14], + m15: Manifest[T15], + m16: Manifest[T16], + m17: Manifest[T17], + m18: Manifest[T18], + m19: Manifest[T19], + m20: Manifest[T20], + m21: Manifest[T21], + m22: Manifest[T22] + ): Unit = { + register( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19, + m20, + m21, + m22 + ) { + case List( + a1: AnyRef, + a2: AnyRef, + a3: AnyRef, + a4: AnyRef, + a5: AnyRef, + a6: AnyRef, + a7: AnyRef, + a8: AnyRef, + a9: AnyRef, + a10: AnyRef, + a11: AnyRef, + a12: AnyRef, + a13: AnyRef, + a14: AnyRef, + a15: AnyRef, + a16: AnyRef, + a17: AnyRef, + a18: AnyRef, + a19: AnyRef, + a20: AnyRef, + a21: AnyRef, + a22: AnyRef + ) => + f( + a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19], + a20.asInstanceOf[T20], + a21.asInstanceOf[T21], + a22.asInstanceOf[T22] + ) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + private def register( + manifests: Manifest[_ <: Any]* + )(pf: PartialFunction[List[Any], Any]): Unit = { + val types = manifests.map(ScalaTypeHelper.asJavaType) + registry.registerStep( + ScalaStepDetails(Utils.frame(self), name, regex, types, pf) + ) + } + + } + +} diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala new file mode 100644 index 00000000..765b8f26 --- /dev/null +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala @@ -0,0 +1,41 @@ +package io.cucumber.scala + +import scala.quoted._ + +// TODO rename +case class MyType(me: Class[_], args: Seq[MyType] = Seq()) + +object Macros { + + inline def parameterTypes[T1](fn: T1 => Any): Seq[String] = { + ${ getTypes[T1]() } + } + + private def getTypes[T1]()(using Type[T1], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1])) + } + + private def getTypesFromRepr(using q: Quotes)(reprs: Seq[q.reflect.TypeRepr]): Expr[Seq[String]] = { + + import q.reflect._ + + def getMyType(tpr: TypeRepr): MyType = { + val output: MyType = tpr.classSymbol match { + case Some(clazz) => + val typeParameters: Seq[MyType] = tpr match { + case a: AppliedType => a.args.map(at => getMyType(at)) + case _ => Seq() + } + MyType(Class.forName(clazz.fullName), typeParameters) + case None => + report.error(s"Unable to handle the type ${tpr.show}, please open an issue at https://github.com/cucumber/cucumber-jvm-scala") + throw new Exception(s"Error when applying macro") + } + output + } + + Expr(reprs.map(i => getMyType(i).toString)) + } + +} diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala new file mode 100644 index 00000000..b56d5ae5 --- /dev/null +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala @@ -0,0 +1,82 @@ +package io.cucumber.scala + +private[scala] trait StepDsl extends BaseScalaDsl { + self => + + final class Step(name: String) { + def apply(regex: String): StepBody = new StepBody(name, regex) + } + + final class Fun0(val f: Function0[Any]) + + object Fun0 { + + implicit def function0AsFun0(f: Function0[Any]): Fun0 = new Fun0(f) + + } + + final class StepBody(name: String, regex: String) { + + /* + * apply0 needs to be able to handle both calls by value and reference. + * + * Call by value: + * + * And("^multipy the things$") { + * z = x * y; + * } + * + * Call by reference: + * + * And("^multipy the things$") { ()=> + * z = x * y; + * } + * + * Call by value has the signature => Unit while call by reference has the signature () => Any + * + * Due to type erasure both would end up with the signature () => Unit. + * + * Fun0 and the implicit conversion lets us work around this. + * + **/ + def apply(f: => Unit): Unit = { + val fun0 = () => f + apply(fun0) + } + + def apply(fun: Fun0): Unit = { + register(Seq()) { + case Nil => fun.f() + case _ => + throw new IncorrectStepDefinitionException() + } + } + + /* + * Generated apply1 to apply22 below + */ + inline def apply[T1](f: (T1) => Any): Unit = { + val types = Macros.parameterTypes(f) + register(types) { + case List(a1: AnyRef) => + f(a1.asInstanceOf[T1]) + case _ => + throw new IncorrectStepDefinitionException() + } + } + + // TODO other methods + + private def register( + types: Seq[String] + )(pf: PartialFunction[List[Any], Any]): Unit = { + // TODO map types + println(types) + registry.registerStep( + ScalaStepDetails(Utils.frame(self), name, regex, Seq(), pf) + ) + } + + } + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/BaseScalaDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/BaseScalaDsl.scala new file mode 100644 index 00000000..19890347 --- /dev/null +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/BaseScalaDsl.scala @@ -0,0 +1,12 @@ +package io.cucumber.scala + +private[scala] trait BaseScalaDsl { + + val NO_REPLACEMENT = Seq[String]() + val EMPTY_TAG_EXPRESSION = "" + val DEFAULT_BEFORE_ORDER = 1000 + val DEFAULT_AFTER_ORDER = 1000 + + private[scala] val registry: ScalaDslRegistry = new ScalaDslRegistry() + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/DataTableTypeDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/DataTableTypeDsl.scala new file mode 100644 index 00000000..5c798871 --- /dev/null +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/DataTableTypeDsl.scala @@ -0,0 +1,97 @@ +package io.cucumber.scala + +import scala.reflect.ClassTag + +private[scala] trait DataTableTypeDsl extends BaseScalaDsl { + + /** Register a data table type. + */ + def DataTableType: DataTableTypeBody = DataTableType(NO_REPLACEMENT) + + /** Register a data table type with a replacement. + *

+ * A data table can only represent absent and non-empty strings. By replacing + * a known value (for example [empty]) a data table can also represent + * empty strings. + * + * @param replaceWithEmptyString a string that will be replaced with an empty string. + */ + def DataTableType(replaceWithEmptyString: String): DataTableTypeBody = + DataTableType(Seq(replaceWithEmptyString)) + + private def DataTableType(replaceWithEmptyString: Seq[String]) = + new DataTableTypeBody(replaceWithEmptyString) + + final class DataTableTypeBody(replaceWithEmptyString: Seq[String]) { + + def apply[T]( + body: DataTableEntryDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableEntryTypeDetails[T](replaceWithEmptyString, body, ev) + ) + } + + def apply[T]( + body: DataTableOptionalEntryDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableOptionalEntryTypeDetails[T]( + replaceWithEmptyString, + body, + ev + ) + ) + } + + def apply[T]( + body: DataTableRowDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableRowTypeDetails[T](replaceWithEmptyString, body, ev) + ) + } + + def apply[T]( + body: DataTableOptionalRowDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableOptionalRowTypeDetails[T]( + replaceWithEmptyString, + body, + ev + ) + ) + } + + def apply[T]( + body: DataTableCellDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableCellTypeDetails[T](replaceWithEmptyString, body, ev) + ) + } + + def apply[T]( + body: DataTableOptionalCellDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableOptionalCellTypeDetails[T]( + replaceWithEmptyString, + body, + ev + ) + ) + } + + def apply[T]( + body: DataTableDefinitionBody[T] + )(implicit ev: ClassTag[T]): Unit = { + registry.registerDataTableType( + ScalaDataTableTableTypeDetails[T](replaceWithEmptyString, body, ev) + ) + } + + } + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/DefaultTransformerDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/DefaultTransformerDsl.scala new file mode 100644 index 00000000..fc10a87e --- /dev/null +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/DefaultTransformerDsl.scala @@ -0,0 +1,90 @@ +package io.cucumber.scala + +import io.cucumber.scala.Aliases.{ + DefaultDataTableCellTransformerBody, + DefaultDataTableEntryTransformerBody, + DefaultParameterTransformerBody +} + +private[scala] trait DefaultTransformerDsl extends BaseScalaDsl { + + /** Register default parameter type transformer. + * + * @param body converts `String` argument to an instance of the `Type` argument + */ + def DefaultParameterTransformer( + body: DefaultParameterTransformerBody + ): Unit = { + registry.registerDefaultParameterTransformer( + ScalaDefaultParameterTransformerDetails(body) + ) + } + + /** Register default data table cell transformer. + * + * @param body converts `String` argument to an instance of the `Type` argument + */ + def DefaultDataTableCellTransformer( + body: DefaultDataTableCellTransformerBody + ): Unit = { + DefaultDataTableCellTransformer(NO_REPLACEMENT)(body) + } + + /** Register default data table cell transformer with a replacement. + *

+ * A data table can only represent absent and non-empty strings. By replacing + * a known value (for example [empty]) a data table can also represent + * empty strings. + * * + * + * @param replaceWithEmptyString a string that will be replaced with an empty string. + * @param body converts `String` argument to an instance of the `Type` argument + */ + def DefaultDataTableCellTransformer( + replaceWithEmptyString: String + )(body: DefaultDataTableCellTransformerBody): Unit = { + DefaultDataTableCellTransformer(Seq(replaceWithEmptyString))(body) + } + + private def DefaultDataTableCellTransformer( + replaceWithEmptyString: Seq[String] + )(body: DefaultDataTableCellTransformerBody): Unit = { + registry.registerDefaultDataTableCellTransformer( + ScalaDefaultDataTableCellTransformerDetails(replaceWithEmptyString, body) + ) + } + + /** Register default data table entry transformer. + * + * @param body converts `Map[String,String]` argument to an instance of the `Type` argument + */ + def DefaultDataTableEntryTransformer( + body: DefaultDataTableEntryTransformerBody + ): Unit = { + DefaultDataTableEntryTransformer(NO_REPLACEMENT)(body) + } + + /** Register default data table cell transformer with a replacement. + *

+ * A data table can only represent absent and non-empty strings. By replacing + * a known value (for example [empty]) a data table can also represent + * empty strings. + * + * @param replaceWithEmptyString a string that will be replaced with an empty string. + * @param body converts `Map[String,String]` argument to an instance of the `Type` argument + */ + def DefaultDataTableEntryTransformer( + replaceWithEmptyString: String + )(body: DefaultDataTableEntryTransformerBody): Unit = { + DefaultDataTableEntryTransformer(Seq(replaceWithEmptyString))(body) + } + + private def DefaultDataTableEntryTransformer( + replaceWithEmptyString: Seq[String] + )(body: DefaultDataTableEntryTransformerBody): Unit = { + registry.registerDefaultDataTableEntryTransformer( + ScalaDefaultDataTableEntryTransformerDetails(replaceWithEmptyString, body) + ) + } + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/DocStringTypeDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/DocStringTypeDsl.scala new file mode 100644 index 00000000..e0fe92e5 --- /dev/null +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/DocStringTypeDsl.scala @@ -0,0 +1,24 @@ +package io.cucumber.scala + +import io.cucumber.scala.Aliases.DocStringDefinitionBody + +import scala.reflect.ClassTag + +private[scala] trait DocStringTypeDsl extends BaseScalaDsl { + + /** Register doc string type. + * + * @param contentType Name of the content type. + * @param body a function that creates an instance of T + * from the doc string + * @tparam T type to convert to + */ + def DocStringType[T]( + contentType: String + )(body: DocStringDefinitionBody[T])(implicit ev: ClassTag[T]): Unit = { + registry.registerDocStringType( + ScalaDocStringTypeDetails[T](contentType, body, ev) + ) + } + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/HookDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/HookDsl.scala new file mode 100644 index 00000000..46aca8da --- /dev/null +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/HookDsl.scala @@ -0,0 +1,143 @@ +package io.cucumber.scala + +sealed trait HookType + +object HookType { + + case object BEFORE extends HookType + + case object BEFORE_STEP extends HookType + + case object AFTER extends HookType + + case object AFTER_STEP extends HookType + +} + +private[scala] trait HookDsl extends BaseScalaDsl { + self => + + /** Defines an before hook. + */ + def Before: HookBody = Before(EMPTY_TAG_EXPRESSION, DEFAULT_BEFORE_ORDER) + + /** Defines an before hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + */ + def Before(tagExpression: String): HookBody = + Before(tagExpression, DEFAULT_BEFORE_ORDER) + + /** Defines an before hook. + * + * @param order the order in which this hook should run. Higher numbers are run first + */ + def Before(order: Int): HookBody = Before(EMPTY_TAG_EXPRESSION, order) + + /** Defines an before hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + * @param order the order in which this hook should run. Higher numbers are run first + */ + def Before(tagExpression: String, order: Int) = + new HookBody(HookType.BEFORE, tagExpression, order, Utils.frame(self)) + + /** Defines an before step hook. + */ + def BeforeStep: HookBody = + BeforeStep(EMPTY_TAG_EXPRESSION, DEFAULT_BEFORE_ORDER) + + /** Defines an before step hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + */ + def BeforeStep(tagExpression: String): HookBody = + BeforeStep(tagExpression, DEFAULT_BEFORE_ORDER) + + /** Defines an before step hook. + * + * @param order the order in which this hook should run. Higher numbers are run first + */ + def BeforeStep(order: Int): HookBody = BeforeStep(EMPTY_TAG_EXPRESSION, order) + + /** Defines an before step hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + * @param order the order in which this hook should run. Higher numbers are run first + */ + def BeforeStep(tagExpression: String, order: Int) = + new HookBody(HookType.BEFORE_STEP, tagExpression, order, Utils.frame(self)) + + /** Defines and after hook. + */ + def After: HookBody = After(EMPTY_TAG_EXPRESSION, DEFAULT_AFTER_ORDER) + + /** Defines and after hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + */ + def After(tagExpression: String): HookBody = + After(tagExpression, DEFAULT_AFTER_ORDER) + + /** Defines and after hook. + * + * @param order the order in which this hook should run. Higher numbers are run first + */ + def After(order: Int): HookBody = After(EMPTY_TAG_EXPRESSION, order) + + /** Defines and after hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + * @param order the order in which this hook should run. Higher numbers are run first + */ + def After(tagExpression: String, order: Int) = + new HookBody(HookType.AFTER, tagExpression, order, Utils.frame(self)) + + /** Defines and after step hook. + */ + def AfterStep: HookBody = AfterStep(EMPTY_TAG_EXPRESSION, DEFAULT_AFTER_ORDER) + + /** Defines and after step hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + */ + def AfterStep(tagExpression: String): HookBody = + AfterStep(tagExpression, DEFAULT_AFTER_ORDER) + + /** Defines and after step hook. + * + * @param order the order in which this hook should run. Higher numbers are run first + */ + def AfterStep(order: Int): HookBody = AfterStep(EMPTY_TAG_EXPRESSION, order) + + /** Defines and after step hook. + * + * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed + * @param order the order in which this hook should run. Higher numbers are run first + */ + def AfterStep(tagExpression: String, order: Int) = + new HookBody(HookType.AFTER_STEP, tagExpression, order, Utils.frame(self)) + + final class HookBody( + hookType: HookType, + tagExpression: String, + order: Int, + frame: StackTraceElement + ) { + + // When a HookBody is created, we want to ensure that the apply method is called + // To be able to check this, we notice the registry to expect a hook + registry.expectHook(hookType, frame) + + def apply(body: => Unit): Unit = { + apply(_ => body) + } + + def apply(body: Scenario => Unit): Unit = { + val details = ScalaHookDetails(tagExpression, order, body) + registry.registerHook(hookType, details, frame) + } + + } + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/ParameterTypeDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/ParameterTypeDsl.scala new file mode 100644 index 00000000..721e0656 --- /dev/null +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/ParameterTypeDsl.scala @@ -0,0 +1,754 @@ +package io.cucumber.scala + +import scala.reflect.ClassTag + +private[scala] trait ParameterTypeDsl extends BaseScalaDsl { + + /** Register parameter type. + * + * @param name used as the type name in typed expressions + * @param regex expression to match + * @see https://cucumber.io/docs/cucumber/cucumber-expressions + */ + def ParameterType(name: String, regex: String) = + new ParameterTypeBody(name, regex) + + final class ParameterTypeBody(name: String, regex: String) { + + // Important: use the piece of code in the file gen.scala to generate these methods easily + + def apply[R](f: (String) => R)(implicit tag: ClassTag[R]): Unit = { + register { case List(p1) => + f(p1) + } + } + + def apply[R](f: (String, String) => R)(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2) => + f(p1, p2) + } + } + + def apply[R]( + f: (String, String, String) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3) => + f(p1, p2, p3) + } + } + + def apply[R]( + f: (String, String, String, String) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4) => + f(p1, p2, p3, p4) + } + } + + def apply[R]( + f: (String, String, String, String, String) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5) => + f(p1, p2, p3, p4, p5) + } + } + + def apply[R]( + f: (String, String, String, String, String, String) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6) => + f(p1, p2, p3, p4, p5, p6) + } + } + + def apply[R]( + f: (String, String, String, String, String, String, String) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6, p7) => + f(p1, p2, p3, p4, p5, p6, p7) + } + } + + def apply[R]( + f: (String, String, String, String, String, String, String, String) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6, p7, p8) => + f(p1, p2, p3, p4, p5, p6, p7, p8) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14 + ) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15 + ) => + f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16 + ) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17 + ) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18 + ) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19 + ) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20 + ) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21 + ) + } + } + + def apply[R]( + f: ( + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String, + String + ) => R + )(implicit tag: ClassTag[R]): Unit = { + register { + case List( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22 + ) => + f( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22 + ) + } + } + + private def register[R]( + pf: PartialFunction[List[String], R] + )(implicit tag: ClassTag[R]): Unit = { + registry.registerParameterType( + ScalaParameterTypeDetails[R](name, regex, pf, tag) + ) + } + + } + +} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala index a3d7f0ca..daf4c27b 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaDsl.scala @@ -1,20 +1,5 @@ package io.cucumber.scala -import Aliases._ - -import scala.reflect.ClassTag - -private[scala] trait BaseScalaDsl { - - val NO_REPLACEMENT = Seq[String]() - val EMPTY_TAG_EXPRESSION = "" - val DEFAULT_BEFORE_ORDER = 1000 - val DEFAULT_AFTER_ORDER = 1000 - - private[scala] val registry: ScalaDslRegistry = new ScalaDslRegistry() - -} - /** Base trait for a scala step definition implementation. */ trait ScalaDsl @@ -25,2634 +10,3 @@ trait ScalaDsl with DocStringTypeDsl with ParameterTypeDsl with DefaultTransformerDsl {} - -sealed trait HookType - -object HookType { - - case object BEFORE extends HookType - - case object BEFORE_STEP extends HookType - - case object AFTER extends HookType - - case object AFTER_STEP extends HookType - -} - -private[scala] trait HookDsl extends BaseScalaDsl { - self => - - /** Defines an before hook. - */ - def Before: HookBody = Before(EMPTY_TAG_EXPRESSION, DEFAULT_BEFORE_ORDER) - - /** Defines an before hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - */ - def Before(tagExpression: String): HookBody = - Before(tagExpression, DEFAULT_BEFORE_ORDER) - - /** Defines an before hook. - * - * @param order the order in which this hook should run. Higher numbers are run first - */ - def Before(order: Int): HookBody = Before(EMPTY_TAG_EXPRESSION, order) - - /** Defines an before hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - * @param order the order in which this hook should run. Higher numbers are run first - */ - def Before(tagExpression: String, order: Int) = - new HookBody(HookType.BEFORE, tagExpression, order, Utils.frame(self)) - - /** Defines an before step hook. - */ - def BeforeStep: HookBody = - BeforeStep(EMPTY_TAG_EXPRESSION, DEFAULT_BEFORE_ORDER) - - /** Defines an before step hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - */ - def BeforeStep(tagExpression: String): HookBody = - BeforeStep(tagExpression, DEFAULT_BEFORE_ORDER) - - /** Defines an before step hook. - * - * @param order the order in which this hook should run. Higher numbers are run first - */ - def BeforeStep(order: Int): HookBody = BeforeStep(EMPTY_TAG_EXPRESSION, order) - - /** Defines an before step hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - * @param order the order in which this hook should run. Higher numbers are run first - */ - def BeforeStep(tagExpression: String, order: Int) = - new HookBody(HookType.BEFORE_STEP, tagExpression, order, Utils.frame(self)) - - /** Defines and after hook. - */ - def After: HookBody = After(EMPTY_TAG_EXPRESSION, DEFAULT_AFTER_ORDER) - - /** Defines and after hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - */ - def After(tagExpression: String): HookBody = - After(tagExpression, DEFAULT_AFTER_ORDER) - - /** Defines and after hook. - * - * @param order the order in which this hook should run. Higher numbers are run first - */ - def After(order: Int): HookBody = After(EMPTY_TAG_EXPRESSION, order) - - /** Defines and after hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - * @param order the order in which this hook should run. Higher numbers are run first - */ - def After(tagExpression: String, order: Int) = - new HookBody(HookType.AFTER, tagExpression, order, Utils.frame(self)) - - /** Defines and after step hook. - */ - def AfterStep: HookBody = AfterStep(EMPTY_TAG_EXPRESSION, DEFAULT_AFTER_ORDER) - - /** Defines and after step hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - */ - def AfterStep(tagExpression: String): HookBody = - AfterStep(tagExpression, DEFAULT_AFTER_ORDER) - - /** Defines and after step hook. - * - * @param order the order in which this hook should run. Higher numbers are run first - */ - def AfterStep(order: Int): HookBody = AfterStep(EMPTY_TAG_EXPRESSION, order) - - /** Defines and after step hook. - * - * @param tagExpression a tag expression, if the expression applies to the current scenario this hook will be executed - * @param order the order in which this hook should run. Higher numbers are run first - */ - def AfterStep(tagExpression: String, order: Int) = - new HookBody(HookType.AFTER_STEP, tagExpression, order, Utils.frame(self)) - - final class HookBody( - hookType: HookType, - tagExpression: String, - order: Int, - frame: StackTraceElement - ) { - - // When a HookBody is created, we want to ensure that the apply method is called - // To be able to check this, we notice the registry to expect a hook - registry.expectHook(hookType, frame) - - def apply(body: => Unit): Unit = { - apply(_ => body) - } - - def apply(body: Scenario => Unit): Unit = { - val details = ScalaHookDetails(tagExpression, order, body) - registry.registerHook(hookType, details, frame) - } - - } - -} - -private[scala] trait DocStringTypeDsl extends BaseScalaDsl { - - /** Register doc string type. - * - * @param contentType Name of the content type. - * @param body a function that creates an instance of T - * from the doc string - * @tparam T type to convert to - */ - def DocStringType[T]( - contentType: String - )(body: DocStringDefinitionBody[T])(implicit ev: ClassTag[T]): Unit = { - registry.registerDocStringType( - ScalaDocStringTypeDetails[T](contentType, body, ev) - ) - } - -} - -private[scala] trait DataTableTypeDsl extends BaseScalaDsl { - - /** Register a data table type. - */ - def DataTableType: DataTableTypeBody = DataTableType(NO_REPLACEMENT) - - /** Register a data table type with a replacement. - *

- * A data table can only represent absent and non-empty strings. By replacing - * a known value (for example [empty]) a data table can also represent - * empty strings. - * - * @param replaceWithEmptyString a string that will be replaced with an empty string. - */ - def DataTableType(replaceWithEmptyString: String): DataTableTypeBody = - DataTableType(Seq(replaceWithEmptyString)) - - private def DataTableType(replaceWithEmptyString: Seq[String]) = - new DataTableTypeBody(replaceWithEmptyString) - - final class DataTableTypeBody(replaceWithEmptyString: Seq[String]) { - - def apply[T]( - body: DataTableEntryDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableEntryTypeDetails[T](replaceWithEmptyString, body, ev) - ) - } - - def apply[T]( - body: DataTableOptionalEntryDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableOptionalEntryTypeDetails[T]( - replaceWithEmptyString, - body, - ev - ) - ) - } - - def apply[T]( - body: DataTableRowDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableRowTypeDetails[T](replaceWithEmptyString, body, ev) - ) - } - - def apply[T]( - body: DataTableOptionalRowDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableOptionalRowTypeDetails[T]( - replaceWithEmptyString, - body, - ev - ) - ) - } - - def apply[T]( - body: DataTableCellDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableCellTypeDetails[T](replaceWithEmptyString, body, ev) - ) - } - - def apply[T]( - body: DataTableOptionalCellDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableOptionalCellTypeDetails[T]( - replaceWithEmptyString, - body, - ev - ) - ) - } - - def apply[T]( - body: DataTableDefinitionBody[T] - )(implicit ev: ClassTag[T]): Unit = { - registry.registerDataTableType( - ScalaDataTableTableTypeDetails[T](replaceWithEmptyString, body, ev) - ) - } - - } - -} - -private[scala] trait ParameterTypeDsl extends BaseScalaDsl { - - /** Register parameter type. - * - * @param name used as the type name in typed expressions - * @param regex expression to match - * @see https://cucumber.io/docs/cucumber/cucumber-expressions - */ - def ParameterType(name: String, regex: String) = - new ParameterTypeBody(name, regex) - - final class ParameterTypeBody(name: String, regex: String) { - - // Important: use the piece of code in the file gen.scala to generate these methods easily - - def apply[R](f: (String) => R)(implicit tag: ClassTag[R]): Unit = { - register { case List(p1) => - f(p1) - } - } - - def apply[R](f: (String, String) => R)(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2) => - f(p1, p2) - } - } - - def apply[R]( - f: (String, String, String) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3) => - f(p1, p2, p3) - } - } - - def apply[R]( - f: (String, String, String, String) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4) => - f(p1, p2, p3, p4) - } - } - - def apply[R]( - f: (String, String, String, String, String) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5) => - f(p1, p2, p3, p4, p5) - } - } - - def apply[R]( - f: (String, String, String, String, String, String) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6) => - f(p1, p2, p3, p4, p5, p6) - } - } - - def apply[R]( - f: (String, String, String, String, String, String, String) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6, p7) => - f(p1, p2, p3, p4, p5, p6, p7) - } - } - - def apply[R]( - f: (String, String, String, String, String, String, String, String) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6, p7, p8) => - f(p1, p2, p3, p4, p5, p6, p7, p8) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14 - ) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15 - ) => - f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16 - ) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17 - ) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18 - ) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19 - ) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20 - ) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20, - p21 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20, - p21 - ) - } - } - - def apply[R]( - f: ( - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String, - String - ) => R - )(implicit tag: ClassTag[R]): Unit = { - register { - case List( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20, - p21, - p22 - ) => - f( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20, - p21, - p22 - ) - } - } - - private def register[R]( - pf: PartialFunction[List[String], R] - )(implicit tag: ClassTag[R]): Unit = { - registry.registerParameterType( - ScalaParameterTypeDetails[R](name, regex, pf, tag) - ) - } - - } - -} - -private[scala] trait DefaultTransformerDsl extends BaseScalaDsl { - - /** Register default parameter type transformer. - * - * @param body converts `String` argument to an instance of the `Type` argument - */ - def DefaultParameterTransformer( - body: DefaultParameterTransformerBody - ): Unit = { - registry.registerDefaultParameterTransformer( - ScalaDefaultParameterTransformerDetails(body) - ) - } - - /** Register default data table cell transformer. - * - * @param body converts `String` argument to an instance of the `Type` argument - */ - def DefaultDataTableCellTransformer( - body: DefaultDataTableCellTransformerBody - ): Unit = { - DefaultDataTableCellTransformer(NO_REPLACEMENT)(body) - } - - /** Register default data table cell transformer with a replacement. - *

- * A data table can only represent absent and non-empty strings. By replacing - * a known value (for example [empty]) a data table can also represent - * empty strings. - * * - * - * @param replaceWithEmptyString a string that will be replaced with an empty string. - * @param body converts `String` argument to an instance of the `Type` argument - */ - def DefaultDataTableCellTransformer( - replaceWithEmptyString: String - )(body: DefaultDataTableCellTransformerBody): Unit = { - DefaultDataTableCellTransformer(Seq(replaceWithEmptyString))(body) - } - - private def DefaultDataTableCellTransformer( - replaceWithEmptyString: Seq[String] - )(body: DefaultDataTableCellTransformerBody): Unit = { - registry.registerDefaultDataTableCellTransformer( - ScalaDefaultDataTableCellTransformerDetails(replaceWithEmptyString, body) - ) - } - - /** Register default data table entry transformer. - * - * @param body converts `Map[String,String]` argument to an instance of the `Type` argument - */ - def DefaultDataTableEntryTransformer( - body: DefaultDataTableEntryTransformerBody - ): Unit = { - DefaultDataTableEntryTransformer(NO_REPLACEMENT)(body) - } - - /** Register default data table cell transformer with a replacement. - *

- * A data table can only represent absent and non-empty strings. By replacing - * a known value (for example [empty]) a data table can also represent - * empty strings. - * - * @param replaceWithEmptyString a string that will be replaced with an empty string. - * @param body converts `Map[String,String]` argument to an instance of the `Type` argument - */ - def DefaultDataTableEntryTransformer( - replaceWithEmptyString: String - )(body: DefaultDataTableEntryTransformerBody): Unit = { - DefaultDataTableEntryTransformer(Seq(replaceWithEmptyString))(body) - } - - private def DefaultDataTableEntryTransformer( - replaceWithEmptyString: Seq[String] - )(body: DefaultDataTableEntryTransformerBody): Unit = { - registry.registerDefaultDataTableEntryTransformer( - ScalaDefaultDataTableEntryTransformerDetails(replaceWithEmptyString, body) - ) - } - -} - -private[scala] trait StepDsl extends BaseScalaDsl { - self => - - final class Step(name: String) { - def apply(regex: String): StepBody = new StepBody(name, regex) - } - - final class Fun0(val f: Function0[Any]) - - object Fun0 { - - implicit def function0AsFun0(f: Function0[Any]): Fun0 = new Fun0(f) - - } - - final class StepBody(name: String, regex: String) { - - /* - * apply0 needs to be able to handle both calls by value and reference. - * - * Call by value: - * - * And("^multipy the things$") { - * z = x * y; - * } - * - * Call by reference: - * - * And("^multipy the things$") { ()=> - * z = x * y; - * } - * - * Call by value has the signature => Unit while call by reference has the signature () => Any - * - * Due to type erasure both would end up with the signature () => Unit. - * - * Fun0 and the implicit conversion lets us work around this. - * - **/ - def apply(f: => Unit): Unit = { - val fun0 = () => f - apply(fun0) - } - - def apply(fun: Fun0): Unit = { - register() { - case Nil => fun.f() - case _ => - throw new IncorrectStepDefinitionException() - } - } - - /* - * Generated apply1 to apply22 below - */ - def apply[T1](f: (T1) => Any)(implicit m1: Manifest[T1]): Unit = { - register(m1) { - case List(a1: AnyRef) => - f(a1.asInstanceOf[T1]) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2]( - f: (T1, T2) => Any - )(implicit m1: Manifest[T1], m2: Manifest[T2]): Unit = { - register(m1, m2) { - case List(a1: AnyRef, a2: AnyRef) => - f(a1.asInstanceOf[T1], a2.asInstanceOf[T2]) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3]( - f: (T1, T2, T3) => Any - )(implicit m1: Manifest[T1], m2: Manifest[T2], m3: Manifest[T3]): Unit = { - register(m1, m2, m3) { - case List(a1: AnyRef, a2: AnyRef, a3: AnyRef) => - f(a1.asInstanceOf[T1], a2.asInstanceOf[T2], a3.asInstanceOf[T3]) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4](f: (T1, T2, T3, T4) => Any)(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4] - ): Unit = { - register(m1, m2, m3, m4) { - case List(a1: AnyRef, a2: AnyRef, a3: AnyRef, a4: AnyRef) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5](f: (T1, T2, T3, T4, T5) => Any)(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5] - ): Unit = { - register(m1, m2, m3, m4, m5) { - case List(a1: AnyRef, a2: AnyRef, a3: AnyRef, a4: AnyRef, a5: AnyRef) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6]( - f: (T1, T2, T3, T4, T5, T6) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6] - ): Unit = { - register(m1, m2, m3, m4, m5, m6) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7]( - f: (T1, T2, T3, T4, T5, T6, T7) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8]( - f: (T1, T2, T3, T4, T5, T6, T7, T8) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9]( - f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8, m9) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( - f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( - f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( - f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( - f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( - f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14] - ): Unit = { - register(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16], - m17: Manifest[T17] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16, - m17 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef, - a17: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16], - a17.asInstanceOf[T17] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16], - m17: Manifest[T17], - m18: Manifest[T18] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16, - m17, - m18 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef, - a17: AnyRef, - a18: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16], - a17.asInstanceOf[T17], - a18.asInstanceOf[T18] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16], - m17: Manifest[T17], - m18: Manifest[T18], - m19: Manifest[T19] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16, - m17, - m18, - m19 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef, - a17: AnyRef, - a18: AnyRef, - a19: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16], - a17.asInstanceOf[T17], - a18.asInstanceOf[T18], - a19.asInstanceOf[T19] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16], - m17: Manifest[T17], - m18: Manifest[T18], - m19: Manifest[T19], - m20: Manifest[T20] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16, - m17, - m18, - m19, - m20 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef, - a17: AnyRef, - a18: AnyRef, - a19: AnyRef, - a20: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16], - a17.asInstanceOf[T17], - a18.asInstanceOf[T18], - a19.asInstanceOf[T19], - a20.asInstanceOf[T20] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16], - m17: Manifest[T17], - m18: Manifest[T18], - m19: Manifest[T19], - m20: Manifest[T20], - m21: Manifest[T21] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16, - m17, - m18, - m19, - m20, - m21 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef, - a17: AnyRef, - a18: AnyRef, - a19: AnyRef, - a20: AnyRef, - a21: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16], - a17.asInstanceOf[T17], - a18.asInstanceOf[T18], - a19.asInstanceOf[T19], - a20.asInstanceOf[T20], - a21.asInstanceOf[T21] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - def apply[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22 - ]( - f: ( - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22 - ) => Any - )(implicit - m1: Manifest[T1], - m2: Manifest[T2], - m3: Manifest[T3], - m4: Manifest[T4], - m5: Manifest[T5], - m6: Manifest[T6], - m7: Manifest[T7], - m8: Manifest[T8], - m9: Manifest[T9], - m10: Manifest[T10], - m11: Manifest[T11], - m12: Manifest[T12], - m13: Manifest[T13], - m14: Manifest[T14], - m15: Manifest[T15], - m16: Manifest[T16], - m17: Manifest[T17], - m18: Manifest[T18], - m19: Manifest[T19], - m20: Manifest[T20], - m21: Manifest[T21], - m22: Manifest[T22] - ): Unit = { - register( - m1, - m2, - m3, - m4, - m5, - m6, - m7, - m8, - m9, - m10, - m11, - m12, - m13, - m14, - m15, - m16, - m17, - m18, - m19, - m20, - m21, - m22 - ) { - case List( - a1: AnyRef, - a2: AnyRef, - a3: AnyRef, - a4: AnyRef, - a5: AnyRef, - a6: AnyRef, - a7: AnyRef, - a8: AnyRef, - a9: AnyRef, - a10: AnyRef, - a11: AnyRef, - a12: AnyRef, - a13: AnyRef, - a14: AnyRef, - a15: AnyRef, - a16: AnyRef, - a17: AnyRef, - a18: AnyRef, - a19: AnyRef, - a20: AnyRef, - a21: AnyRef, - a22: AnyRef - ) => - f( - a1.asInstanceOf[T1], - a2.asInstanceOf[T2], - a3.asInstanceOf[T3], - a4.asInstanceOf[T4], - a5.asInstanceOf[T5], - a6.asInstanceOf[T6], - a7.asInstanceOf[T7], - a8.asInstanceOf[T8], - a9.asInstanceOf[T9], - a10.asInstanceOf[T10], - a11.asInstanceOf[T11], - a12.asInstanceOf[T12], - a13.asInstanceOf[T13], - a14.asInstanceOf[T14], - a15.asInstanceOf[T15], - a16.asInstanceOf[T16], - a17.asInstanceOf[T17], - a18.asInstanceOf[T18], - a19.asInstanceOf[T19], - a20.asInstanceOf[T20], - a21.asInstanceOf[T21], - a22.asInstanceOf[T22] - ) - case _ => - throw new IncorrectStepDefinitionException() - } - } - - private def register( - manifests: Manifest[_ <: Any]* - )(pf: PartialFunction[List[Any], Any]): Unit = { - registry.registerStep( - ScalaStepDetails(Utils.frame(self), name, regex, manifests, pf) - ) - } - - } - -} diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDefinition.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDefinition.scala index 0f1e7cb3..189478ed 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDefinition.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDefinition.scala @@ -1,5 +1,6 @@ package io.cucumber.scala +import java.lang.reflect.{Type => JType} import java.util.{List => JList} import io.cucumber.core.backend.{ParameterInfo, ScenarioScoped, StepDefinition} @@ -16,9 +17,8 @@ trait ScalaStepDefinition extends StepDefinition with AbstractGlueDefinition { stepDetails.types ) - private def fromTypes(types: Seq[Manifest[_]]): JList[ParameterInfo] = { + private def fromTypes(types: Seq[JType]): JList[ParameterInfo] = { types - .map(ScalaTypeHelper.asJavaType) .map(new ScalaTypeResolver(_)) .map(new ScalaParameterInfo(_)) .toList diff --git a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDetails.scala b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDetails.scala index f05069ce..b279e37e 100644 --- a/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDetails.scala +++ b/cucumber-scala/src/main/scala/io/cucumber/scala/ScalaStepDetails.scala @@ -1,5 +1,7 @@ package io.cucumber.scala +import java.lang.reflect.{Type => JType} + /** Implementation of step definition for scala. * * @param frame Representation of a stack frame containing information about the context in which a @@ -13,6 +15,6 @@ case class ScalaStepDetails( frame: StackTraceElement, name: String, pattern: String, - types: Seq[Manifest[_]], + types: Seq[JType], body: List[Any] => Any ) From 42c4b0b57a61bebd2a001d1f2d1fc35180e85bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Tue, 22 Dec 2020 18:48:49 +0100 Subject: [PATCH 07/11] wip ko --- cucumber-scala/src/main/codegen/gen.scala | 63 ++- .../scala-3.0/io/cucumber/scala/Macros.scala | 194 ++++++- .../scala-3.0/io/cucumber/scala/StepDsl.scala | 494 +++++++++++++++++- 3 files changed, 744 insertions(+), 7 deletions(-) diff --git a/cucumber-scala/src/main/codegen/gen.scala b/cucumber-scala/src/main/codegen/gen.scala index 8e95536d..345ec847 100644 --- a/cucumber-scala/src/main/codegen/gen.scala +++ b/cucumber-scala/src/main/codegen/gen.scala @@ -15,6 +15,29 @@ for (i <- 1 to 22) { println(p1 + p2 + ": Unit = { " + register + pf + otherwise + closeRegister + "\n") } +/* + * Generates the evil looking apply methods in ScalaDsl#StepBody for Function1 to Function22 + * For Scala 3 + */ +for (i <- 1 to 22) { + val ts = (1 to i).map(n => s"T$n").mkString(", ") + val pf = " case List(" + (1 to i).map("a" + _ + ":AnyRef").mkString(", ") + ") => \n f(" + (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ") + ")\n" + + val template = + s""" + |inline def apply[$ts](f: ($ts) => Any): Unit = { + | val types = parameterTypes(f) + | register(types) { + | $pf + | case _ => + | throw new IncorrectStepDefinitionException() + | } + |} + |""".stripMargin + + println(template) +} + /* * Generates the apply methods in ParameterTypeDsl for Function1 to Function22 */ @@ -35,4 +58,42 @@ for (i <- 1 to 22) { |""".stripMargin println(template) -} \ No newline at end of file +} + +/* + * Generates the macros parameterTypes. + * For Scala 3 + */ +for (i <- 1 to 22) { + + val ts = (1 to i).map("T".+).mkString(", ") + + val template = + s""" + |inline def parameterTypes[$ts](fn: ($ts) => Any): Seq[String] = { + | $${ getTypes[$ts]() } + |} + |""".stripMargin + + println(template) +} + +/* + * Generates the macros method getTypes. + * For Scala 3 + */ +for (i <- 1 to 22) { + val ts = (1 to i).map(n => s"T$n").mkString(", ") + val usings = (1 to i).map(n => s"Type[T$n]").mkString(", ") + val reprs = (1 to i).map(n => s"TypeRepr.of[T$n]").mkString(", ") + + val template = + s""" + |private def getTypes[$ts]()(using $usings, Quotes): Expr[Seq[String]] = { + | import quotes.reflect._ + | getTypesFromRepr(Seq($reprs)) + |} + |""".stripMargin + + println(template) +} diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala index 765b8f26..c478b81e 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala @@ -7,15 +7,207 @@ case class MyType(me: Class[_], args: Seq[MyType] = Seq()) object Macros { - inline def parameterTypes[T1](fn: T1 => Any): Seq[String] = { + inline def parameterTypes[T1](fn: (T1) => Any): Seq[String] = { ${ getTypes[T1]() } } + inline def parameterTypes[T1, T2](fn: (T1, T2) => Any): Seq[String] = { + ${ getTypes[T1, T2]() } + } + + inline def parameterTypes[T1, T2, T3](fn: (T1, T2, T3) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3]() } + } + + inline def parameterTypes[T1, T2, T3, T4](fn: (T1, T2, T3, T4) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5](fn: (T1, T2, T3, T4, T5) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6](fn: (T1, T2, T3, T4, T5, T6) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7](fn: (T1, T2, T3, T4, T5, T6, T7) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8](fn: (T1, T2, T3, T4, T5, T6, T7, T8) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]() } + } + + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]() } + } + + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]() } + } + + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]() } + } + + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Any): Seq[String] = { + ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]() } + } + private def getTypes[T1]()(using Type[T1], Quotes): Expr[Seq[String]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1])) } + private def getTypes[T1, T2]()(using Type[T1], Type[T2], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2])) + } + + private def getTypes[T1, T2, T3]()(using Type[T1], Type[T2], Type[T3], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3])) + } + + private def getTypes[T1, T2, T3, T4]()(using Type[T1], Type[T2], Type[T3], Type[T4], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4])) + } + + private def getTypes[T1, T2, T3, T4, T5]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19], TypeRepr.of[T20])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19], TypeRepr.of[T20], TypeRepr.of[T21])) + } + + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Type[T22], Quotes): Expr[Seq[String]] = { + import quotes.reflect._ + getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19], TypeRepr.of[T20], TypeRepr.of[T21], TypeRepr.of[T22])) + } + private def getTypesFromRepr(using q: Quotes)(reprs: Seq[q.reflect.TypeRepr]): Expr[Seq[String]] = { import q.reflect._ diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala index b56d5ae5..f4727e0d 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala @@ -1,5 +1,7 @@ package io.cucumber.scala +import io.cucumber.scala.Macros.parameterTypes + private[scala] trait StepDsl extends BaseScalaDsl { self => @@ -39,12 +41,12 @@ private[scala] trait StepDsl extends BaseScalaDsl { * Fun0 and the implicit conversion lets us work around this. * **/ - def apply(f: => Unit): Unit = { + inline def apply(f: => Unit): Unit = { val fun0 = () => f apply(fun0) } - def apply(fun: Fun0): Unit = { + inline def apply(fun: Fun0): Unit = { register(Seq()) { case Nil => fun.f() case _ => @@ -56,16 +58,498 @@ private[scala] trait StepDsl extends BaseScalaDsl { * Generated apply1 to apply22 below */ inline def apply[T1](f: (T1) => Any): Unit = { - val types = Macros.parameterTypes(f) + val types = parameterTypes(f) register(types) { - case List(a1: AnyRef) => + case List(a1:AnyRef) => f(a1.asInstanceOf[T1]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2](f: (T1, T2) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3](f: (T1, T2, T3) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3]) + case _ => throw new IncorrectStepDefinitionException() } } - // TODO other methods + + inline def apply[T1, T2, T3, T4](f: (T1, T2, T3, T4) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5](f: (T1, T2, T3, T4, T5) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6](f: (T1, T2, T3, T4, T5, T6) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7](f: (T1, T2, T3, T4, T5, T6, T7) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8](f: (T1, T2, T3, T4, T5, T6, T7, T8) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19], + a20.asInstanceOf[T20]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19], + a20.asInstanceOf[T20], + a21.asInstanceOf[T21]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } + + + inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Any): Unit = { + val types = parameterTypes(f) + register(types) { + case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef, a22:AnyRef) => + f(a1.asInstanceOf[T1], + a2.asInstanceOf[T2], + a3.asInstanceOf[T3], + a4.asInstanceOf[T4], + a5.asInstanceOf[T5], + a6.asInstanceOf[T6], + a7.asInstanceOf[T7], + a8.asInstanceOf[T8], + a9.asInstanceOf[T9], + a10.asInstanceOf[T10], + a11.asInstanceOf[T11], + a12.asInstanceOf[T12], + a13.asInstanceOf[T13], + a14.asInstanceOf[T14], + a15.asInstanceOf[T15], + a16.asInstanceOf[T16], + a17.asInstanceOf[T17], + a18.asInstanceOf[T18], + a19.asInstanceOf[T19], + a20.asInstanceOf[T20], + a21.asInstanceOf[T21], + a22.asInstanceOf[T22]) + + case _ => + throw new IncorrectStepDefinitionException() + } + } private def register( types: Seq[String] From ca6f0690a3ac050242f8de4ee9555dee2ccac985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Thu, 24 Dec 2020 11:45:20 +0100 Subject: [PATCH 08/11] fix parenthesis in tests --- .../scala/ScalaDslDataTableTypeTest.scala | 16 ++++++++-------- .../io/cucumber/scala/ScalaDslHooksTest.scala | 16 ++++++++-------- .../tests/cukes/TypeRegistryConfiguration.scala | 2 +- .../tests/datatables/DataTableTypeSteps.scala | 10 +++++----- .../tests/datatables/DatatableAsScalaSteps.scala | 4 ++-- .../scala/tests/docstring/DocStringSteps.scala | 8 ++++---- .../parametertypes/ParameterTypesSteps.scala | 16 ++++++++-------- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslDataTableTypeTest.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslDataTableTypeTest.scala index 5d02b472..099bf274 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslDataTableTypeTest.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslDataTableTypeTest.scala @@ -35,7 +35,7 @@ class ScalaDslDataTableTypeTest { def testDataTableEntryType(): Unit = { class Glue extends ScalaDsl with EN { - DataTableType { entry: Map[String, String] => + DataTableType { (entry: Map[String, String]) => Author(entry("name"), entry("surname"), entry("famousBook")) } } @@ -81,7 +81,7 @@ class ScalaDslDataTableTypeTest { def testDataTableRowType(): Unit = { class Glue extends ScalaDsl with EN { - DataTableType { row: Seq[String] => + DataTableType { (row: Seq[String]) => Author(row(0), row(1), row(2)) } } @@ -127,7 +127,7 @@ class ScalaDslDataTableTypeTest { def testDataTableCellType(): Unit = { class Glue extends ScalaDsl with EN { - DataTableType { cell: String => + DataTableType { (cell: String) => Cell(cell) } } @@ -173,7 +173,7 @@ class ScalaDslDataTableTypeTest { def testClassDataTableTableType(): Unit = { class Glue extends ScalaDsl with EN { - DataTableType { table: DataTable => + DataTableType { (table: DataTable) => val authors = table .asMaps() .asScala @@ -242,7 +242,7 @@ class ScalaDslDataTableTypeTest { def testObjectDataTableEntryType(): Unit = { object Glue extends ScalaDsl with EN { - DataTableType { entry: Map[String, String] => + DataTableType { (entry: Map[String, String]) => Author(entry("name"), entry("surname"), entry("famousBook")) } } @@ -284,7 +284,7 @@ class ScalaDslDataTableTypeTest { def testObjectDataTableRowType(): Unit = { object Glue extends ScalaDsl with EN { - DataTableType { row: Seq[String] => + DataTableType { (row: Seq[String]) => Author(row(0), row(1), row(2)) } } @@ -326,7 +326,7 @@ class ScalaDslDataTableTypeTest { def testObjectDataTableCellType(): Unit = { object Glue extends ScalaDsl with EN { - DataTableType { cell: String => + DataTableType { (cell: String) => Cell(cell) } } @@ -368,7 +368,7 @@ class ScalaDslDataTableTypeTest { def testObjectDataTableTableType(): Unit = { object Glue extends ScalaDsl with EN { - DataTableType { table: DataTable => + DataTableType { (table: DataTable) => val authors = table .asMaps() .asScala diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslHooksTest.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslHooksTest.scala index dd2d956d..5e82d790 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslHooksTest.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/ScalaDslHooksTest.scala @@ -30,7 +30,7 @@ class ScalaDslHooksTest { def testBeforeHook(): Unit = { class Glue extends ScalaDsl { - Before { _: Scenario => + Before { (_: Scenario) => invoke() } } @@ -142,7 +142,7 @@ class ScalaDslHooksTest { def testBeforeStepHook(): Unit = { class Glue extends ScalaDsl { - BeforeStep { _: Scenario => + BeforeStep { (_: Scenario) => invoke() } } @@ -254,7 +254,7 @@ class ScalaDslHooksTest { def testAfterHook(): Unit = { class Glue extends ScalaDsl { - After { _: Scenario => + After { (_: Scenario) => invoke() } } @@ -366,7 +366,7 @@ class ScalaDslHooksTest { def testAfterStepHook(): Unit = { class Glue extends ScalaDsl { - AfterStep { _: Scenario => + AfterStep { (_: Scenario) => invoke() } } @@ -481,7 +481,7 @@ class ScalaDslHooksTest { def testObjectBeforeHook(): Unit = { object Glue extends ScalaDsl { - Before { _: Scenario => + Before { (_: Scenario) => invoke() } } @@ -577,7 +577,7 @@ class ScalaDslHooksTest { def testObjectBeforeStepHook(): Unit = { object Glue extends ScalaDsl { - BeforeStep { _: Scenario => + BeforeStep { (_: Scenario) => invoke() } } @@ -673,7 +673,7 @@ class ScalaDslHooksTest { def testObjectAfterHook(): Unit = { object Glue extends ScalaDsl { - After { _: Scenario => + After { (_: Scenario) => invoke() } } @@ -769,7 +769,7 @@ class ScalaDslHooksTest { def testObjectAfterStepHook(): Unit = { object Glue extends ScalaDsl { - AfterStep { _: Scenario => + AfterStep { (_: Scenario) => invoke() } } diff --git a/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala b/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala index f5043593..e8b30a03 100644 --- a/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala +++ b/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala @@ -33,7 +33,7 @@ class TypeRegistryConfiguration extends ScalaDsl { s.charAt(0) } - DataTableType { map: Map[String, String] => + DataTableType { (map: Map[String, String]) => Cukes(map("Number").toInt, map("Color")) } diff --git a/cucumber-scala/src/test/scala/tests/datatables/DataTableTypeSteps.scala b/cucumber-scala/src/test/scala/tests/datatables/DataTableTypeSteps.scala index ad1b5a6f..9f9f8452 100644 --- a/cucumber-scala/src/test/scala/tests/datatables/DataTableTypeSteps.scala +++ b/cucumber-scala/src/test/scala/tests/datatables/DataTableTypeSteps.scala @@ -61,7 +61,7 @@ class DataTableTypeSteps extends ScalaDsl with EN { var _authors: Seq[Author] = _ var _names: String = _ - DataTableType { entry: Map[String, String] => + DataTableType { (entry: Map[String, String]) => Author(entry("name"), entry("surname"), entry("famousBook")) } @@ -77,7 +77,7 @@ class DataTableTypeSteps extends ScalaDsl with EN { ) } - DataTableType { row: Seq[String] => + DataTableType { (row: Seq[String]) => AuthorRow(row(0), row(1), row(2)) } @@ -93,7 +93,7 @@ class DataTableTypeSteps extends ScalaDsl with EN { ) } - DataTableType { cell: String => + DataTableType { (cell: String) => AuthorCell(cell) } @@ -105,7 +105,7 @@ class DataTableTypeSteps extends ScalaDsl with EN { AuthorCellWithNone(cell) } - DataTableType { table: DataTable => + DataTableType { (table: DataTable) => val authors = table .asMaps() .asScala @@ -268,7 +268,7 @@ class DataTableTypeSteps extends ScalaDsl with EN { _names = _authors.map(_.name).mkString(",") } - Then("""I get {string}""") { expected: String => + Then("""I get {string}""") { (expected: String) => assert(_names == expected, s"${_names} was not equal to $expected") } diff --git a/cucumber-scala/src/test/scala/tests/datatables/DatatableAsScalaSteps.scala b/cucumber-scala/src/test/scala/tests/datatables/DatatableAsScalaSteps.scala index df7ee495..5fd1dfdd 100644 --- a/cucumber-scala/src/test/scala/tests/datatables/DatatableAsScalaSteps.scala +++ b/cucumber-scala/src/test/scala/tests/datatables/DatatableAsScalaSteps.scala @@ -197,7 +197,7 @@ class DatatableAsScalaSteps extends ScalaDsl with EN { case class CustomType(key1: String, key2: Option[String], key3: String) - DataTableType { map: Map[String, String] => + DataTableType { (map: Map[String, String]) => CustomType(map("key1"), Option(map("key2")), map("key3")) } @@ -214,7 +214,7 @@ class DatatableAsScalaSteps extends ScalaDsl with EN { case class RichCell(content: Option[String]) - DataTableType { cell: String => + DataTableType { (cell: String) => RichCell(Option(cell)) } diff --git a/cucumber-scala/src/test/scala/tests/docstring/DocStringSteps.scala b/cucumber-scala/src/test/scala/tests/docstring/DocStringSteps.scala index 42fd5241..a45efdc7 100644 --- a/cucumber-scala/src/test/scala/tests/docstring/DocStringSteps.scala +++ b/cucumber-scala/src/test/scala/tests/docstring/DocStringSteps.scala @@ -10,19 +10,19 @@ class DocStringSteps extends ScalaDsl with EN { var _text: Any = _ - DocStringType("json") { text => + DocStringType("json") { (text) => JsonText(text) } - DocStringType("xml") { text => + DocStringType("xml") { (text) => XmlText(text) } - Given("the following json text") { json: JsonText => + Given("the following json text") { (json: JsonText) => _text = json } - Given("the following xml text") { xml: XmlText => + Given("the following xml text") { (xml: XmlText) => _text = xml } diff --git a/cucumber-scala/src/test/scala/tests/parametertypes/ParameterTypesSteps.scala b/cucumber-scala/src/test/scala/tests/parametertypes/ParameterTypesSteps.scala index e251a38f..e51eaa9e 100644 --- a/cucumber-scala/src/test/scala/tests/parametertypes/ParameterTypesSteps.scala +++ b/cucumber-scala/src/test/scala/tests/parametertypes/ParameterTypesSteps.scala @@ -11,7 +11,7 @@ case class Point(x: Int, y: Int) class ParameterTypesSteps extends ScalaDsl with EN { - ParameterType("string-builder", "\"(.*)\"") { str => + ParameterType("string-builder", "\"(.*)\"") { (str) => new StringBuilder(str) } @@ -23,11 +23,11 @@ class ParameterTypesSteps extends ScalaDsl with EN { s"-$x-$y-$z-" } - ParameterType("optionalint", """\s?(\d*)\s?""") { str => + ParameterType("optionalint", """\s?(\d*)\s?""") { (str) => Option(str).filter(_.nonEmpty).map(_.toInt) } - ParameterType("optionalstring", "(.*)") { str => + ParameterType("optionalstring", "(.*)") { (str) => Option(str).filter(_.nonEmpty) } @@ -46,7 +46,7 @@ class ParameterTypesSteps extends ScalaDsl with EN { } Given("{string-builder} parameter, defined by lambda") { - builder: StringBuilder => + (builder: StringBuilder) => assert(builder.toString() == "string builder") } @@ -121,22 +121,22 @@ class ParameterTypesSteps extends ScalaDsl with EN { } Given("""an optional string parameter value "{optionalstring}" undefined""") { - value: Option[String] => + (value: Option[String]) => assert(value.isEmpty) } Given("""an optional string parameter value "{optionalstring}" defined""") { - value: Option[String] => + (value: Option[String]) => assert(value.contains("toto")) } Given("""an optional int parameter value{optionalint}undefined""") { - value: Option[Int] => + (value: Option[Int]) => assert(value.isEmpty) } Given("""an optional int parameter value{optionalint}defined""") { - value: Option[Int] => + (value: Option[Int]) => assert(value.contains(5)) } From ed47ae9a91cce98890b4e7bfa51c04282c89d770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sat, 26 Dec 2020 17:56:05 +0100 Subject: [PATCH 09/11] WIP --- .../src/main/scala-3.0/io/cucumber/scala/Macros.scala | 9 ++++----- .../scala/steps/classes/MultipleInSameFile.scala | 8 ++++++-- .../io/cucumber/scala/steps/objects/StepsInObject.scala | 6 +++++- .../io/cucumber/scala/steps/traits/StepsInTrait.scala | 6 +++++- .../scala/tests/cukes/TypeRegistryConfiguration.scala | 1 + .../scalacalculator/RpnCalculatorStepDefinitions.scala | 4 ++-- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala index c478b81e..4be4122b 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala @@ -3,7 +3,7 @@ package io.cucumber.scala import scala.quoted._ // TODO rename -case class MyType(me: Class[_], args: Seq[MyType] = Seq()) +case class MyType(me: String, args: Seq[MyType] = Seq()) object Macros { @@ -213,18 +213,17 @@ object Macros { import q.reflect._ def getMyType(tpr: TypeRepr): MyType = { - val output: MyType = tpr.classSymbol match { - case Some(clazz) => + tpr.classSymbol match { + case Some(classSymbol) => val typeParameters: Seq[MyType] = tpr match { case a: AppliedType => a.args.map(at => getMyType(at)) case _ => Seq() } - MyType(Class.forName(clazz.fullName), typeParameters) + MyType(classSymbol.fullName, typeParameters) case None => report.error(s"Unable to handle the type ${tpr.show}, please open an issue at https://github.com/cucumber/cucumber-jvm-scala") throw new Exception(s"Error when applying macro") } - output } Expr(reprs.map(i => getMyType(i).toString)) diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala index f6169f6d..1aa28c90 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/classes/MultipleInSameFile.scala @@ -6,21 +6,25 @@ class StepsA extends ScalaDsl with EN { Before { // Nothing + () } BeforeStep { // Nothing + () } After { // Nothing + () } AfterStep { // Nothing + () } - Given("""stepA""") ((() => { + Given("""stepA""")((() => { // Nothing })) @@ -28,7 +32,7 @@ class StepsA extends ScalaDsl with EN { class StepsB extends ScalaDsl with EN { - When("""stepsB""") ((() => { + When("""stepsB""")((() => { // Nothing })) diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala index 3e870b71..52ce82d1 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/objects/StepsInObject.scala @@ -6,21 +6,25 @@ object StepsInObject extends ScalaDsl with EN { Before { // Nothing + () } BeforeStep { // Nothing + () } After { // Nothing + () } AfterStep { // Nothing + () } - Given("""Given step""") ((() => { + Given("""Given step""")((() => { // Nothing })) diff --git a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala index 8e9e628f..0fb940ce 100644 --- a/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala +++ b/cucumber-scala/src/test/scala/io/cucumber/scala/steps/traits/StepsInTrait.scala @@ -6,21 +6,25 @@ trait TraitWithSteps extends ScalaDsl with EN { Before { // Nothing + () } BeforeStep { // Nothing + () } After { // Nothing + () } AfterStep { // Nothing + () } - Given("""Given step""") ((() => { + Given("""Given step""")((() => { // Nothing })) diff --git a/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala b/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala index e8b30a03..b5638229 100644 --- a/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala +++ b/cucumber-scala/src/test/scala/tests/cukes/TypeRegistryConfiguration.scala @@ -17,6 +17,7 @@ class TypeRegistryConfiguration extends ScalaDsl { val direction = s.toList match { case '<' :: _ => Symbol("west") case l if l.last == '>' => Symbol("east") + case _ => Symbol("unknown") } Snake(size, direction) } diff --git a/examples/src/test/scala/cucumber/examples/scalacalculator/RpnCalculatorStepDefinitions.scala b/examples/src/test/scala/cucumber/examples/scalacalculator/RpnCalculatorStepDefinitions.scala index 97f96254..3812b0fe 100644 --- a/examples/src/test/scala/cucumber/examples/scalacalculator/RpnCalculatorStepDefinitions.scala +++ b/examples/src/test/scala/cucumber/examples/scalacalculator/RpnCalculatorStepDefinitions.scala @@ -13,11 +13,11 @@ class RpnCalculatorStepDefinitions extends ScalaDsl with EN { calc push "+" } - Then("the result is {double}") { expected: Double => + Then("the result is {double}") { (expected: Double) => assertEquals(expected, calc.value, 0.001) } - Before("not @foo") { scenario: Scenario => + Before("not @foo") { (scenario: Scenario) => println(s"Runs before scenarios *not* tagged with @foo (${scenario.getId})") } } From 9bcedd288311ecfcf14739547fe9e89e717fe11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Mon, 4 Jan 2021 08:38:41 +0100 Subject: [PATCH 10/11] wip scala3 --- CHANGELOG.md | 1 + cucumber-scala/src/main/codegen/gen.scala | 6 +- .../io/cucumber/scala/ScalaTypeHelper.scala | 7 +- .../scala-3.0/io/cucumber/scala/Macros.scala | 122 ++++++++++-------- .../io/cucumber/scala/ScalaTypeHelper.scala | 28 ++++ .../scala-3.0/io/cucumber/scala/StepDsl.scala | 53 ++++---- project/ScalacOptions.scala | 3 +- project/build.properties | 2 +- 8 files changed, 135 insertions(+), 87 deletions(-) create mode 100644 cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala diff --git a/CHANGELOG.md b/CHANGELOG.md index 6702ec67..4a17ad27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH ### Added - [Build] Cross compilation with Scala 3.0.0-M3 + - TODO DOCUMENT BREAKING CHANGES ### Changed diff --git a/cucumber-scala/src/main/codegen/gen.scala b/cucumber-scala/src/main/codegen/gen.scala index 345ec847..7d174336 100644 --- a/cucumber-scala/src/main/codegen/gen.scala +++ b/cucumber-scala/src/main/codegen/gen.scala @@ -26,7 +26,7 @@ for (i <- 1 to 22) { val template = s""" |inline def apply[$ts](f: ($ts) => Any): Unit = { - | val types = parameterTypes(f) + | val types = parameterTypes[$ts]() | register(types) { | $pf | case _ => @@ -70,7 +70,7 @@ for (i <- 1 to 22) { val template = s""" - |inline def parameterTypes[$ts](fn: ($ts) => Any): Seq[String] = { + |inline def parameterTypes[$ts](): Seq[MyType] = { | $${ getTypes[$ts]() } |} |""".stripMargin @@ -89,7 +89,7 @@ for (i <- 1 to 22) { val template = s""" - |private def getTypes[$ts]()(using $usings, Quotes): Expr[Seq[String]] = { + |private def getTypes[$ts]()(using $usings, Quotes): Expr[Seq[MyType]] = { | import quotes.reflect._ | getTypesFromRepr(Seq($reprs)) |} diff --git a/cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala b/cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala index a5d7fdfc..bba4104e 100644 --- a/cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala +++ b/cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala @@ -16,10 +16,13 @@ object ScalaTypeHelper { class ScalaParameterizedType(manifest: Manifest[_]) extends ParameterizedType { - override def getActualTypeArguments: Array[Type] = + private val typeArgs = manifest.typeArguments.map(ScalaTypeHelper.asJavaType).toArray + private val rawType = manifest.runtimeClass - override def getRawType: Type = manifest.runtimeClass + override def getActualTypeArguments: Array[Type] = typeArgs + + override def getRawType: Type = rawType override def getOwnerType: Type = null diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala index 4be4122b..e7cdb7d3 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/Macros.scala @@ -3,230 +3,246 @@ package io.cucumber.scala import scala.quoted._ // TODO rename -case class MyType(me: String, args: Seq[MyType] = Seq()) +case class MyType(me: String, args: List[MyType] = List()) + +object MyType { + + given ToExpr[MyType] with { + def apply(myType: MyType)(using Quotes): Expr[MyType] = { + '{ + MyType ( + ${Expr (myType.me)}, + ${Expr.ofList (myType.args.map (a => apply (a) ) )} + ) + } + } + } + +} object Macros { - inline def parameterTypes[T1](fn: (T1) => Any): Seq[String] = { + inline def parameterTypes[T1](): Seq[MyType] = { ${ getTypes[T1]() } } - inline def parameterTypes[T1, T2](fn: (T1, T2) => Any): Seq[String] = { + inline def parameterTypes[T1, T2](): Seq[MyType] = { ${ getTypes[T1, T2]() } } - inline def parameterTypes[T1, T2, T3](fn: (T1, T2, T3) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3](): Seq[MyType] = { ${ getTypes[T1, T2, T3]() } } - inline def parameterTypes[T1, T2, T3, T4](fn: (T1, T2, T3, T4) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4]() } } - inline def parameterTypes[T1, T2, T3, T4, T5](fn: (T1, T2, T3, T4, T5) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6](fn: (T1, T2, T3, T4, T5, T6) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7](fn: (T1, T2, T3, T4, T5, T6, T7) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8](fn: (T1, T2, T3, T4, T5, T6, T7, T8) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]() } } - - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]() } } - - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]() } } - inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](fn: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Any): Seq[String] = { + inline def parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](): Seq[MyType] = { ${ getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]() } } - private def getTypes[T1]()(using Type[T1], Quotes): Expr[Seq[String]] = { + private def getTypes[T1]()(using Type[T1], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1])) } - private def getTypes[T1, T2]()(using Type[T1], Type[T2], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2]()(using Type[T1], Type[T2], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2])) } - private def getTypes[T1, T2, T3]()(using Type[T1], Type[T2], Type[T3], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3]()(using Type[T1], Type[T2], Type[T3], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3])) } - private def getTypes[T1, T2, T3, T4]()(using Type[T1], Type[T2], Type[T3], Type[T4], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4]()(using Type[T1], Type[T2], Type[T3], Type[T4], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4])) } - private def getTypes[T1, T2, T3, T4, T5]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5])) } - private def getTypes[T1, T2, T3, T4, T5, T6]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19], TypeRepr.of[T20])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19], TypeRepr.of[T20], TypeRepr.of[T21])) } - private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Type[T22], Quotes): Expr[Seq[String]] = { + private def getTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]()(using Type[T1], Type[T2], Type[T3], Type[T4], Type[T5], Type[T6], Type[T7], Type[T8], Type[T9], Type[T10], Type[T11], Type[T12], Type[T13], Type[T14], Type[T15], Type[T16], Type[T17], Type[T18], Type[T19], Type[T20], Type[T21], Type[T22], Quotes): Expr[Seq[MyType]] = { import quotes.reflect._ getTypesFromRepr(Seq(TypeRepr.of[T1], TypeRepr.of[T2], TypeRepr.of[T3], TypeRepr.of[T4], TypeRepr.of[T5], TypeRepr.of[T6], TypeRepr.of[T7], TypeRepr.of[T8], TypeRepr.of[T9], TypeRepr.of[T10], TypeRepr.of[T11], TypeRepr.of[T12], TypeRepr.of[T13], TypeRepr.of[T14], TypeRepr.of[T15], TypeRepr.of[T16], TypeRepr.of[T17], TypeRepr.of[T18], TypeRepr.of[T19], TypeRepr.of[T20], TypeRepr.of[T21], TypeRepr.of[T22])) } - private def getTypesFromRepr(using q: Quotes)(reprs: Seq[q.reflect.TypeRepr]): Expr[Seq[String]] = { + private def getTypesFromRepr(using q: Quotes)(reprs: Seq[q.reflect.TypeRepr]): Expr[Seq[MyType]] = { import q.reflect._ def getMyType(tpr: TypeRepr): MyType = { tpr.classSymbol match { case Some(classSymbol) => - val typeParameters: Seq[MyType] = tpr match { - case a: AppliedType => a.args.map(at => getMyType(at)) - case _ => Seq() + val typeParameters: List[MyType] = tpr match { + case a: AppliedType => + a.args.map(at => getMyType(at)) + case _ => List() } - MyType(classSymbol.fullName, typeParameters) + // Temporary ugly hack for inner class in objects (not ok for class in class) + val className = classSymbol.fullName.replace("$.", "$") + MyType(className, typeParameters) case None => report.error(s"Unable to handle the type ${tpr.show}, please open an issue at https://github.com/cucumber/cucumber-jvm-scala") throw new Exception(s"Error when applying macro") } } - Expr(reprs.map(i => getMyType(i).toString)) + Expr(reprs.map(i => getMyType(i))) } } diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala new file mode 100644 index 00000000..cea6b678 --- /dev/null +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala @@ -0,0 +1,28 @@ +package io.cucumber.scala + +import java.lang.reflect.{ParameterizedType, Type} + +object ScalaTypeHelper { + + def asJavaType(m: MyType): Type = { + if (m.args.isEmpty) { + Class.forName(m.me) + } else { + new ScalaParameterizedType(m) + } + } + +} + +class ScalaParameterizedType(myType: MyType) extends ParameterizedType { + + private val typeArgs = myType.args.map(ScalaTypeHelper.asJavaType).toArray + private val rawType = Class.forName(myType.me) + + override def getActualTypeArguments: Array[Type] = typeArgs + + override def getRawType: Type = rawType + + override def getOwnerType: Type = null + +} diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala index f4727e0d..fbe999d1 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala @@ -58,7 +58,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { * Generated apply1 to apply22 below */ inline def apply[T1](f: (T1) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1]() register(types) { case List(a1:AnyRef) => f(a1.asInstanceOf[T1]) @@ -70,7 +70,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2](f: (T1, T2) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2]() register(types) { case List(a1:AnyRef, a2:AnyRef) => f(a1.asInstanceOf[T1], @@ -83,7 +83,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3](f: (T1, T2, T3) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef) => f(a1.asInstanceOf[T1], @@ -97,7 +97,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4](f: (T1, T2, T3, T4) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef) => f(a1.asInstanceOf[T1], @@ -112,7 +112,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5](f: (T1, T2, T3, T4, T5) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef) => f(a1.asInstanceOf[T1], @@ -128,7 +128,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6](f: (T1, T2, T3, T4, T5, T6) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef) => f(a1.asInstanceOf[T1], @@ -145,7 +145,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7](f: (T1, T2, T3, T4, T5, T6, T7) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef) => f(a1.asInstanceOf[T1], @@ -163,7 +163,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8](f: (T1, T2, T3, T4, T5, T6, T7, T8) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef) => f(a1.asInstanceOf[T1], @@ -182,7 +182,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef) => f(a1.asInstanceOf[T1], @@ -202,7 +202,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef) => f(a1.asInstanceOf[T1], @@ -223,7 +223,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef) => f(a1.asInstanceOf[T1], @@ -245,7 +245,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef) => f(a1.asInstanceOf[T1], @@ -268,7 +268,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef) => f(a1.asInstanceOf[T1], @@ -292,7 +292,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef) => f(a1.asInstanceOf[T1], @@ -317,7 +317,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef) => f(a1.asInstanceOf[T1], @@ -343,7 +343,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef) => f(a1.asInstanceOf[T1], @@ -370,7 +370,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef) => f(a1.asInstanceOf[T1], @@ -398,7 +398,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef) => f(a1.asInstanceOf[T1], @@ -427,7 +427,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef) => f(a1.asInstanceOf[T1], @@ -457,7 +457,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef) => f(a1.asInstanceOf[T1], @@ -488,7 +488,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef) => f(a1.asInstanceOf[T1], @@ -520,7 +520,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Any): Unit = { - val types = parameterTypes(f) + val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]() register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef, a22:AnyRef) => f(a1.asInstanceOf[T1], @@ -552,12 +552,13 @@ private[scala] trait StepDsl extends BaseScalaDsl { } private def register( - types: Seq[String] + types: Seq[MyType] )(pf: PartialFunction[List[Any], Any]): Unit = { - // TODO map types - println(types) + + val actualTypes = types.map(mt => ScalaTypeHelper.asJavaType(mt)) + registry.registerStep( - ScalaStepDetails(Utils.frame(self), name, regex, Seq(), pf) + ScalaStepDetails(Utils.frame(self), name, regex, actualTypes, pf) ) } diff --git a/project/ScalacOptions.scala b/project/ScalacOptions.scala index a148a2e7..872830da 100644 --- a/project/ScalacOptions.scala +++ b/project/ScalacOptions.scala @@ -1,8 +1,7 @@ object ScalacOptions { val scalacOptions3 = Seq( - "-rewrite", - "-source:3.0-migration", + "-source:3.0", "-deprecation", // Emit warning and location for usages of deprecated APIs. "-explain", // Explain type errors in more detail. // "-explaintypes", // Explain type errors in more detail. diff --git a/project/build.properties b/project/build.properties index c06db1bb..d91c272d 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.4.5 +sbt.version=1.4.6 From 1c755f9927ce2e831c12c5effff8be57c90d4f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Sun, 17 Jan 2021 17:18:52 +0100 Subject: [PATCH 11/11] WIP with izumi-reflect --- build.sbt | 2 + cucumber-scala/src/main/codegen/gen.scala | 3 +- .../io/cucumber/scala/ScalaTypeHelper.scala | 58 ++++++++++++++++--- .../scala-3.0/io/cucumber/scala/StepDsl.scala | 50 ++++++++-------- 4 files changed, 81 insertions(+), 32 deletions(-) diff --git a/build.sbt b/build.sbt index 177bc742..d305a048 100644 --- a/build.sbt +++ b/build.sbt @@ -88,6 +88,8 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala")) CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, n)) if n <= 12 => List("org.scala-lang.modules" %% "scala-collection-compat" % "2.3.1") + case Some((3, 0)) => + List("dev.zio" %% "izumi-reflect" % "1.0.0-M12") case _ => Nil } }, diff --git a/cucumber-scala/src/main/codegen/gen.scala b/cucumber-scala/src/main/codegen/gen.scala index 7d174336..1fcf0be6 100644 --- a/cucumber-scala/src/main/codegen/gen.scala +++ b/cucumber-scala/src/main/codegen/gen.scala @@ -21,12 +21,13 @@ for (i <- 1 to 22) { */ for (i <- 1 to 22) { val ts = (1 to i).map(n => s"T$n").mkString(", ") + val ltt = (1 to i).map(n => s"LTT[T$n]").mkString(", ") val pf = " case List(" + (1 to i).map("a" + _ + ":AnyRef").mkString(", ") + ") => \n f(" + (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ") + ")\n" val template = s""" |inline def apply[$ts](f: ($ts) => Any): Unit = { - | val types = parameterTypes[$ts]() + | val types = Seq($ltt) | register(types) { | $pf | case _ => diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala index cea6b678..ddaf85f5 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/ScalaTypeHelper.scala @@ -2,22 +2,66 @@ package io.cucumber.scala import java.lang.reflect.{ParameterizedType, Type} +import izumi.reflect.macrortti._ + object ScalaTypeHelper { - def asJavaType(m: MyType): Type = { - if (m.args.isEmpty) { - Class.forName(m.me) + def asJavaType(t: LightTypeTag): Type = { + if (t.typeArgs.isEmpty) { + classFromLTT(t) + } else { + new ScalaParameterizedType(t) + } + } + + def classFromLTT(t: LightTypeTag): Class[_] = { + Class.forName(classNameFromLTT(t)) + } + + // TOOD add tests on this one! + def classNameFromLTT(t: LightTypeTag): String = { + // my.company.OuterClass::my.company.OuterClass.InnerClass[=TypeParam] + // my.company.OuterObject$::my.company.OuterObject$.InnerClass[=TypeParam] + val repr = t.repr.split("\\[").head.split("::") + if (repr.length == 1) { + val k = repr.head + // FIXME + if (k == "scala.Int") { + "java.lang.Integer" + } else if (k == "scala.Byte") { + "java.lang.Byte" + } else if (k == "scala.Short") { + "java.lang.Short" + } else if (k == "scala.Long") { + "java.lang.Long" + } else if (k == "scala.Float") { + "java.lang.Float" + } else if (k == "scala.Double") { + "java.lang.Double" + } else if (k == "scala.Boolean") { + "java.lang.Boolean" + } else { + k + } + } else if (repr.length == 2) { + if (repr.head.endsWith("$")) { + repr.head + repr(1).substring(repr.head.length + 1) + } else { + repr.head + "$" + repr(1).substring(repr.head.length + 1) + } } else { - new ScalaParameterizedType(m) + throw new IllegalArgumentException( + s"Unable to understand the type ${t.repr}, please open an issue at https://github.com/cucumber/cucumber-jvm-scala" + ) } } } -class ScalaParameterizedType(myType: MyType) extends ParameterizedType { +class ScalaParameterizedType(t: LightTypeTag) extends ParameterizedType { - private val typeArgs = myType.args.map(ScalaTypeHelper.asJavaType).toArray - private val rawType = Class.forName(myType.me) + private val typeArgs = t.typeArgs.map(ScalaTypeHelper.asJavaType).toArray + private val rawType = ScalaTypeHelper.classFromLTT(t) override def getActualTypeArguments: Array[Type] = typeArgs diff --git a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala index fbe999d1..c361ef0d 100644 --- a/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala +++ b/cucumber-scala/src/main/scala-3.0/io/cucumber/scala/StepDsl.scala @@ -1,6 +1,8 @@ package io.cucumber.scala -import io.cucumber.scala.Macros.parameterTypes +// import io.cucumber.scala.Macros.parameterTypes + +import izumi.reflect.macrortti._ private[scala] trait StepDsl extends BaseScalaDsl { self => @@ -58,7 +60,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { * Generated apply1 to apply22 below */ inline def apply[T1](f: (T1) => Any): Unit = { - val types = parameterTypes[T1]() + val types = Seq(LTT[T1]) register(types) { case List(a1:AnyRef) => f(a1.asInstanceOf[T1]) @@ -70,7 +72,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2](f: (T1, T2) => Any): Unit = { - val types = parameterTypes[T1, T2]() + val types = Seq(LTT[T1], LTT[T2]) register(types) { case List(a1:AnyRef, a2:AnyRef) => f(a1.asInstanceOf[T1], @@ -83,7 +85,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3](f: (T1, T2, T3) => Any): Unit = { - val types = parameterTypes[T1, T2, T3]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef) => f(a1.asInstanceOf[T1], @@ -97,7 +99,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4](f: (T1, T2, T3, T4) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef) => f(a1.asInstanceOf[T1], @@ -112,7 +114,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5](f: (T1, T2, T3, T4, T5) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef) => f(a1.asInstanceOf[T1], @@ -128,7 +130,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6](f: (T1, T2, T3, T4, T5, T6) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef) => f(a1.asInstanceOf[T1], @@ -145,7 +147,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7](f: (T1, T2, T3, T4, T5, T6, T7) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef) => f(a1.asInstanceOf[T1], @@ -163,7 +165,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8](f: (T1, T2, T3, T4, T5, T6, T7, T8) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef) => f(a1.asInstanceOf[T1], @@ -182,7 +184,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef) => f(a1.asInstanceOf[T1], @@ -202,7 +204,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef) => f(a1.asInstanceOf[T1], @@ -223,7 +225,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef) => f(a1.asInstanceOf[T1], @@ -245,7 +247,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef) => f(a1.asInstanceOf[T1], @@ -268,7 +270,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef) => f(a1.asInstanceOf[T1], @@ -292,7 +294,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef) => f(a1.asInstanceOf[T1], @@ -317,7 +319,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef) => f(a1.asInstanceOf[T1], @@ -343,7 +345,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef) => f(a1.asInstanceOf[T1], @@ -370,7 +372,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16], LTT[T17]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef) => f(a1.asInstanceOf[T1], @@ -398,7 +400,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16], LTT[T17], LTT[T18]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef) => f(a1.asInstanceOf[T1], @@ -427,7 +429,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16], LTT[T17], LTT[T18], LTT[T19]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef) => f(a1.asInstanceOf[T1], @@ -457,7 +459,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16], LTT[T17], LTT[T18], LTT[T19], LTT[T20]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef) => f(a1.asInstanceOf[T1], @@ -488,7 +490,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16], LTT[T17], LTT[T18], LTT[T19], LTT[T20], LTT[T21]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef) => f(a1.asInstanceOf[T1], @@ -520,7 +522,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { inline def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Any): Unit = { - val types = parameterTypes[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]() + val types = Seq(LTT[T1], LTT[T2], LTT[T3], LTT[T4], LTT[T5], LTT[T6], LTT[T7], LTT[T8], LTT[T9], LTT[T10], LTT[T11], LTT[T12], LTT[T13], LTT[T14], LTT[T15], LTT[T16], LTT[T17], LTT[T18], LTT[T19], LTT[T20], LTT[T21], LTT[T22]) register(types) { case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef, a22:AnyRef) => f(a1.asInstanceOf[T1], @@ -552,7 +554,7 @@ private[scala] trait StepDsl extends BaseScalaDsl { } private def register( - types: Seq[MyType] + types: Seq[LightTypeTag] )(pf: PartialFunction[List[Any], Any]): Unit = { val actualTypes = types.map(mt => ScalaTypeHelper.asJavaType(mt))