From 7fe4a2394b4717cf64f8330f7916db00e90357a1 Mon Sep 17 00:00:00 2001 From: Achilleas Naoumidis Date: Sun, 29 Sep 2024 15:30:42 +0300 Subject: [PATCH] Update Scala to 3.5 (#2857) --- build.gradle | 10 +++++++--- generator/Generator.sc | 19 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index e0c1ac72c..f1476e572 100644 --- a/build.gradle +++ b/build.gradle @@ -40,8 +40,9 @@ plugins { id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' } -ext.ammoniteScalaVersion = '2.13' -ext.ammoniteVersion = '2.5.11' +ext.ammoniteScalaVersion = '3.5' +ext.ammoniteVersion = '3.0.0' +ext.ammoniteVersionQualifier = '2-6342755f' ext.assertjVersion = '3.26.3' ext.junitVersion = '5.11.1' @@ -87,7 +88,10 @@ tasks.register('generateSources') { } def ammoniteJar = new File(ammoniteDir, "amm-${ammoniteScalaVersion}-${ammoniteVersion}.jar") if (!ammoniteJar.exists()) { - def ammoniteReleaseUrl = "https://github.com/lihaoyi/Ammonite/releases/download/${ammoniteVersion}/${ammoniteScalaVersion}-${ammoniteVersion}" + def ammoniteAssetName = [ammoniteScalaVersion, ammoniteVersion, ammoniteVersionQualifier] + .findAll { it != null && !it.isEmpty() } + .join('-') + def ammoniteReleaseUrl = "https://github.com/lihaoyi/Ammonite/releases/download/${ammoniteVersion}/${ammoniteAssetName}" ant.get(src: ammoniteReleaseUrl, dest: ammoniteJar) } javaexec { diff --git a/generator/Generator.sc b/generator/Generator.sc index af43f2487..970f2f236 100644 --- a/generator/Generator.sc +++ b/generator/Generator.sc @@ -29,7 +29,6 @@ import JavaGenerator._ import collection.immutable.ListMap import scala.language.implicitConversions -import scala.reflect.macros.whitebox val N = 8 val VARARGS = 10 @@ -776,7 +775,7 @@ def generateMainClasses(): Unit = { val forClassName = if (mtype.endsWith("Iterable")) { s"For$i" } else { s"For$i$mtype" } val generics = (1 to i).gen(j => s"T$j")(", ") val params = (1 to i).gen(j => s"${if(mtype == "Either") mtype + s"" else mtype + s""} ts$j")(", ") - xs""" + xs""" /$javadoc * Creates a {@code For}-comprehension of ${i.numerus(mtype)}. ${(0 to i).gen(j => if (j == 0) "*" else s"* @param ts$j the ${j.ordinal} $mtype")("\n")} @@ -2131,7 +2130,7 @@ def generateMainClasses(): Unit = { } """)} - ${(i > 1) gen (1 to i).gen(j => xs""" + ${(i > 1) `gen` (1 to i).gen(j => xs""" /$javadoc * Maps the ${j.ordinal} component of this tuple to a new value. * @@ -2201,7 +2200,7 @@ def generateMainClasses(): Unit = { } """)} - ${(i < N) gen (1 to N-i).gen(j => xs""" + ${(i < N) `gen` (1 to N-i).gen(j => xs""" /$javadoc * Concat a tuple's values to this tuple. * @@ -3644,7 +3643,7 @@ def generateTestClasses(): Unit = { } """)} - ${(i > 1) gen (1 to i).gen(j => { + ${(i > 1) `gen` (1 to i).gen(j => { val substitutedResultTypes = if (i == 0) "" else s"<${(1 to i).gen(k => s"${if (k == j) "String" else "Integer"}")(", ")}>" val ones = (1 to i).gen(_ => "1")(", ") val result = (1 to i).gen(k => s"${if (k == j) "\"X\"" else "1"}")(", ") @@ -3683,7 +3682,7 @@ def generateTestClasses(): Unit = { } """)} - ${(i < N) gen (1 to N-i).gen(j => xs""" + ${(i < N) `gen` (1 to N-i).gen(j => xs""" @$test public void shouldConcatTuple$j() { final Tuple${i+j}<${(1 to i+j).gen(j => s"Integer")(", ")}> actual = ${ if (i == 0) "Tuple0.instance()" else s"Tuple.of(${(1 to i).gen(j => xs"$j")(", ")})"}.concat(Tuple.of(${(i+1 to i+j).gen(k => s"$k")(", ")})); @@ -3943,10 +3942,10 @@ object Generator { def first: String = s.substring(0, 1) // converts first char of s to upper case. throws if string is empty - def firstUpper: String = s(0).toUpper + s.substring(1) + def firstUpper: String = s"${s(0).toUpper}${s.substring(1)}" // converts first char of s to lower case. throws if string is empty - def firstLower: String = s(0).toLower + s.substring(1) + def firstLower: String = s"${s(0).toLower}${s.substring(1)}" } implicit class BooleanExtensions(condition: Boolean) { @@ -4121,7 +4120,7 @@ object Generator { * @param args StringContext parts * @return An aligned String */ - def xs(args: Any*): String = align(sc.s(indentedArgs(args:_*):_*)) + def xs(args: Any*): String = align(sc.s(indentedArgs(args*)*)) /** * Formats raw/unescaped strings. @@ -4129,7 +4128,7 @@ object Generator { * @param args StringContext parts * @return An aligned String */ - def xraw(args: Any*): String = align(sc.raw(indentedArgs(args:_*):_*)) + def xraw(args: Any*): String = align(sc.raw(indentedArgs(args*)*)) // indent embedded strings, invariant: parts.length = args.length + 1 private def indentedArgs(args: Any*): Seq[String] =