Skip to content

Commit 650e660

Browse files
committed
chore: 🤖 Scala 3 - Get rid of Manifest
1 parent a455a0e commit 650e660

File tree

11 files changed

+1163
-3
lines changed

11 files changed

+1163
-3
lines changed

‎build.sbt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,33 @@ 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.2")
91+
case Some((3, 0)) =>
92+
List("io.github.gaeljw" %% "typetrees" % "0.2.0")
9193
case _ => Nil
9294
}
9395
},
9496
unmanagedSourceDirectories in Compile ++= {
9597
val sourceDir = (sourceDirectory in Compile).value
9698
CrossVersion.partialVersion(scalaVersion.value) match {
97-
case Some((2, n)) if n <= 11 => Seq(sourceDir / "scala-2.11")
98-
case _ => Seq()
99+
case Some((2, n)) if n <= 11 =>
100+
Seq(sourceDir / "scala-2", sourceDir / "scala-2.11")
101+
case Some((2, n)) if n > 11 =>
102+
Seq(sourceDir / "scala-2")
103+
case Some((3, 0)) =>
104+
Seq(sourceDir / "scala-3")
105+
case _ =>
106+
Seq()
107+
}
108+
},
109+
unmanagedSourceDirectories in Test ++= {
110+
val testSourceDir = (sourceDirectory in Test).value
111+
CrossVersion.partialVersion(scalaVersion.value) match {
112+
case Some((2, _)) =>
113+
Seq(testSourceDir / "scala-2")
114+
case Some((3, 0)) =>
115+
Seq(testSourceDir / "scala-3")
116+
case _ =>
117+
Seq()
99118
}
100119
},
101120
// Generate I18n traits

‎cucumber-scala/src/main/codegen/gen.scala

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/*
3-
* Generates the evil looking apply methods in ScalaDsl#StepBody for Function1 to Function22
3+
* Generates the evil looking apply methods in StepDsl#StepBody for Function1 to Function22
44
*/
55
for (i <- 1 to 22) {
66
val ts = (1 to i).map("T".+).mkString(", ")
@@ -15,6 +15,29 @@ for (i <- 1 to 22) {
1515
println(p1 + p2 + ": Unit = { " + register + pf + otherwise + closeRegister + "\n")
1616
}
1717

18+
/*
19+
* Generates the evil looking apply methods in StepDsl#StepBody for Function1 to Function22
20+
* Scala 3
21+
*/
22+
for (i <- 1 to 22) {
23+
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(", ")
26+
val listParams = (1 to i).map("a" + _ + ":AnyRef").mkString(", ")
27+
val pf = (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ")
28+
29+
println(s"""
30+
|inline def apply[$ts](f: ($ts) => Any): Unit = {
31+
| $tagsDef
32+
| register($tagsParam) {
33+
| case List($listParams) =>
34+
| f($pf)
35+
| case _ =>
36+
| throw new IncorrectStepDefinitionException()
37+
| }
38+
|}""".stripMargin)
39+
}
40+
1841
/*
1942
* Generates the apply methods in ParameterTypeDsl for Function1 to Function22
2043
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.cucumber.scala
2+
3+
import io.github.gaeljw.typetrees.TypeTreeTag
4+
import java.lang.reflect.{ParameterizedType, Type}
5+
6+
object ScalaTypeHelper {
7+
8+
def asJavaType(tag: TypeTreeTag): Type = {
9+
if (tag.args.isEmpty) {
10+
tag.self.runtimeClass
11+
} else {
12+
new ScalaParameterizedType(tag)
13+
}
14+
}
15+
16+
}
17+
18+
class ScalaParameterizedType(tag: TypeTreeTag) extends ParameterizedType {
19+
20+
override def getActualTypeArguments: Array[Type] =
21+
tag.args.map(ScalaTypeHelper.asJavaType).toArray
22+
23+
override def getRawType: Type = tag.self.runtimeClass
24+
25+
override def getOwnerType: Type = null
26+
27+
}

0 commit comments

Comments
 (0)