Skip to content

Commit 81b6788

Browse files
authored
Merge pull request #206 from cucumber/remove-typetree-tag
Change the way we infer the types of steps arguments
2 parents 5e0940c + 52edabc commit 81b6788

File tree

11 files changed

+1198
-811
lines changed

11 files changed

+1198
-811
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH
1616

1717
### Changed
1818

19+
- [Internal] Rewrite the way types of step arguments are inferred
20+
1921
### Deprecated
2022

2123
### Removed

build.sbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
8888
CrossVersion.partialVersion(scalaVersion.value) match {
8989
case Some((2, n)) if n <= 12 =>
9090
List("org.scala-lang.modules" %% "scala-collection-compat" % "2.4.4")
91-
case Some((3, 0)) =>
92-
List("io.github.gaeljw" %% "typetrees" % "0.4.0")
9391
case _ => Nil
9492
}
9593
},
Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11

2-
/*
3-
* Generates the evil looking apply methods in StepDsl#StepBody for Function1 to Function22
4-
*/
5-
for (i <- 1 to 22) {
6-
val ts = (1 to i).map("T".+).mkString(", ")
7-
val f = "(" + ts + ") => Any"
8-
val p1 = "def apply[" + ts + "](f: " + f + ")"
9-
val p2 = "(implicit " + (1 to i).map(n => "m" + n + ":Manifest[T" + n + "]").mkString(", ") + ")"
10-
val register = "\n register(" +(1 to i).map(n => "m" + n).mkString(", ") + ") {\n"
11-
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"
12-
val otherwise = " case _ =>\n throw new IncorrectStepDefinitionException()\n"
13-
val closeRegister = " }\n}"
14-
15-
println(p1 + p2 + ": Unit = { " + register + pf + otherwise + closeRegister + "\n")
16-
}
17-
182
/*
193
* Generates the evil looking apply methods in StepDsl#StepBody for Function1 to Function22
204
* Scala 3
215
*/
226
for (i <- 1 to 22) {
237
val ts = (1 to i).map("T".+).mkString(", ")
24-
val tagsDef = (1 to i).map(n => s"val t$n: TypeTreeTag = typeTreeTag[T$n]").mkString("\n")
25-
val tagsParam = (1 to i).map(n => s"t$n").mkString(", ")
8+
val implicits = (1 to i).map(n => s"t$n: Stepable[T$n]").mkString(", ")
9+
val implicitsParams = (1 to i).map(n => s"t$n").mkString(", ")
2610
val listParams = (1 to i).map("a" + _ + ":AnyRef").mkString(", ")
2711
val pf = (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ")
2812

2913
println(s"""
30-
|inline def apply[$ts](f: ($ts) => Any): Unit = {
31-
| $tagsDef
32-
| register($tagsParam) {
14+
|def apply[$ts](f: ($ts) => Any)(using $implicits): Unit = {
15+
| register($implicitsParams) {
3316
| case List($listParams) =>
3417
| f($pf)
3518
| case _ =>
@@ -58,4 +41,30 @@ for (i <- 1 to 22) {
5841
|""".stripMargin
5942

6043
println(template)
61-
}
44+
}
45+
46+
/*
47+
* Generates the Stepable implicit methods
48+
*/
49+
for (i <- (1 to 9).reverse) {
50+
51+
val underscores = (1 to i).map(_ => "_").mkString(", ")
52+
val types = (1 to i).map(j => s"X$j").mkString(", ")
53+
val typesStepable = (1 to i).map(j => s"X$j: Stepable").mkString(", ")
54+
val typeArgs = (1 to i).map(j => s"implicitly[Stepable[X$j]].asJavaType").mkString(", ")
55+
56+
val template =
57+
s"""
58+
|implicit def stepable$i[T[$underscores], $typesStepable](implicit ct: ClassTag[T[$types]]): Stepable[T[$types]] =
59+
| new Stepable[T[$types]] {
60+
| def asJavaType: JavaType =
61+
| new ScalaParameterizedType(
62+
| ct.runtimeClass,
63+
| Array(
64+
| $typeArgs
65+
| )
66+
| )
67+
| }""".stripMargin
68+
69+
println(template)
70+
}

cucumber-scala/src/main/scala-2/io/cucumber/scala/ScalaTypeHelper.scala

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)