From 3375e8e8bfdb139f762ec4b6a2207a9c54f22a11 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Tue, 23 Mar 2021 07:28:23 -0700 Subject: [PATCH 1/7] sbt build cleanup: use slash syntax --- build.sbt | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/build.sbt b/build.sbt index a7151a9..3d1ab7a 100644 --- a/build.sbt +++ b/build.sbt @@ -24,8 +24,8 @@ ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible lazy val commonSettings = Seq( scalacOptions ++= Seq("-feature", "-deprecation", "-unchecked"), - unmanagedSourceDirectories in Compile ++= { - (unmanagedSourceDirectories in Compile).value.flatMap { dir => + Compile / unmanagedSourceDirectories ++= { + (Compile / unmanagedSourceDirectories).value.flatMap { dir => CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 13)) => Seq(file(dir.getPath ++ "-2.13+")) case Some((2, 11)) => Seq(file(dir.getPath ++ "-2.13-"), file(dir.getPath ++ "-2.11")) @@ -34,8 +34,8 @@ lazy val commonSettings = Seq( } }, - unmanagedSourceDirectories in Test ++= { - (unmanagedSourceDirectories in Test).value.flatMap { dir => + Test / unmanagedSourceDirectories ++= { + (Test / unmanagedSourceDirectories).value.flatMap { dir => CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 13)) => Seq(file(dir.getPath ++ "-2.13+")) case Some((2, 11)) => Seq(file(dir.getPath ++ "-2.13-"), file(dir.getPath ++ "-2.11")) @@ -48,7 +48,7 @@ lazy val commonSettings = Seq( lazy val fnGen = (project in file("fnGen")) .settings(commonSettings) .settings( - fork in run := true, // Needed if you run this project directly + run / fork := true, // Needed if you run this project directly libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value, libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value ) @@ -93,19 +93,19 @@ lazy val scalaJava8Compat = (project in file(".")) testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a"), - (sourceGenerators in Compile) += Def.task { - val out = (sourceManaged in Compile).value + (Compile / sourceGenerators) += Def.task { + val out = (Compile / sourceManaged).value if (!out.exists) IO.createDirectory(out) val canon = out.getCanonicalPath val args = (new File(canon, "FunctionConverters.scala")).toString :: Nil - val runTarget = (mainClass in Compile in fnGen).value getOrElse "No main class defined for function conversion generator" - val classPath = (fullClasspath in Compile in fnGen).value + val runTarget = (fnGen / Compile / mainClass).value getOrElse "No main class defined for function conversion generator" + val classPath = (fnGen / Compile / fullClasspath).value runner.value.run(runTarget, classPath.files, args, streams.value.log) (out ** "*.scala").get }.taskValue, - sourceGenerators in Compile += Def.task { - val dir = (sourceManaged in Compile).value + Compile / sourceGenerators += Def.task { + val dir = (Compile / sourceManaged).value val write = jwrite(dir) _ if(scalaVersion.value.startsWith("2.11.")) { Seq(write("JFunction", CodeGen.factory)) ++ @@ -118,8 +118,8 @@ lazy val scalaJava8Compat = (project in file(".")) } else CodeGen.create212.map(write.tupled) }.taskValue, - sourceGenerators in Test += Def.task { - Seq(jwrite((sourceManaged in Test).value)("TestApi", CodeGen.testApi)) + Test / sourceGenerators += Def.task { + Seq(jwrite((Test / sourceManaged).value)("TestApi", CodeGen.testApi)) }.taskValue, initialize := { @@ -131,23 +131,23 @@ lazy val scalaJava8Compat = (project in file(".")) sys.error("Java 8 or higher is required for this project.") }, - publishArtifact in packageDoc := !disableDocs + packageDoc / publishArtifact := !disableDocs ) .settings( inConfig(JavaDoc)(Defaults.configSettings) ++ { if (disableDocs) Nil else Seq( - packageDoc in Compile := (packageDoc in JavaDoc).value, - sources in JavaDoc := { + Compile / packageDoc := (JavaDoc / packageDoc).value, + JavaDoc / sources := { val allJavaSources = (target.value / "java" ** "*.java").get ++ - (sources in Compile).value.filter(_.getName.endsWith(".java")) + (Compile / sources).value.filter(_.getName.endsWith(".java")) allJavaSources.filterNot(_.getName.contains("FuturesConvertersImpl.java")) // this file triggers bugs in genjavadoc }, - javacOptions in JavaDoc := Seq("-Xdoclint:none"), - artifactName in packageDoc in JavaDoc := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar"), + JavaDoc / javacOptions := Seq("-Xdoclint:none"), + JavaDoc / packageDoc / artifactName := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar"), libraryDependencies += compilerPlugin("com.typesafe.genjavadoc" % "genjavadoc-plugin" % "0.16" cross CrossVersion.full), - scalacOptions in Compile += "-P:genjavadoc:out=" + (target.value / "java") + Compile / scalacOptions += "-P:genjavadoc:out=" + (target.value / "java") ) } ) From 7e706e3e862dcac283b6a9473bad904f3646f820 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 25 Mar 2021 16:48:01 -0700 Subject: [PATCH 2/7] avoid deprecation warning --- fnGen/WrapFnGen.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fnGen/WrapFnGen.scala b/fnGen/WrapFnGen.scala index c3e2e86..794c104 100644 --- a/fnGen/WrapFnGen.scala +++ b/fnGen/WrapFnGen.scala @@ -143,7 +143,7 @@ object WrapFnGen { private def buildWrappersViaReflection: Seq[SamConversionCode] = { - val pack: Symbol = rootMirror.getPackageIfDefined(TermName("java.util.function")) + val pack: Symbol = rootMirror.getPackageIfDefined("java.util.function") case class Jfn(iface: Symbol, sam: Symbol) { lazy val genericCount = iface.typeParams.length From 4732e78098be6cce7cfd8dc60a54ba9dfc3d2c3e Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 25 Mar 2021 16:48:20 -0700 Subject: [PATCH 3/7] code improvement (for Scala 3, but good on 2 also) --- .../scala/compat/java8/StreamConverters.scala | 2 +- .../converterImpl/AccumulatorConverters.scala | 24 ++-- .../scala/compat/java8/OptionConverters.scala | 57 +++++---- .../java8/PrimitiveIteratorConversions.scala | 115 +++++++++--------- 4 files changed, 106 insertions(+), 92 deletions(-) diff --git a/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala b/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala index 8adea5f..47bfa05 100644 --- a/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala +++ b/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala @@ -21,7 +21,7 @@ import scala.collection.{IterableOnce, Stepper, StepperShape} import scala.compat.java8.converterImpl._ import scala.jdk.CollectionConverters._ import scala.jdk._ -import scala.language.{higherKinds, implicitConversions} +import scala.language.implicitConversions /** Defines extension methods to create Java Streams for Scala collections, available through * [[scala.compat.java8.StreamConverters]]. diff --git a/src/main/scala-2.13+/scala/compat/java8/converterImpl/AccumulatorConverters.scala b/src/main/scala-2.13+/scala/compat/java8/converterImpl/AccumulatorConverters.scala index 4ff943a..b2e7e2b 100644 --- a/src/main/scala-2.13+/scala/compat/java8/converterImpl/AccumulatorConverters.scala +++ b/src/main/scala-2.13+/scala/compat/java8/converterImpl/AccumulatorConverters.scala @@ -15,18 +15,26 @@ package scala.compat.java8.converterImpl import scala.language.implicitConversions trait Priority3AccumulatorConverters { - implicit def collectionCanAccumulate[A](underlying: IterableOnce[A]) = new CollectionCanAccumulate[A](underlying) + implicit def collectionCanAccumulate[A](underlying: IterableOnce[A]): CollectionCanAccumulate[A] = + new CollectionCanAccumulate[A](underlying) } trait Priority2AccumulatorConverters extends Priority3AccumulatorConverters { - implicit def accumulateDoubleCollection(underlying: IterableOnce[Double]) = new AccumulateDoubleCollection(underlying) - implicit def accumulateIntCollection(underlying: IterableOnce[Int]) = new AccumulateIntCollection(underlying) - implicit def accumulateLongCollection(underlying: IterableOnce[Long]) = new AccumulateLongCollection(underlying) - implicit def accumulateAnyArray[A](underlying: Array[A]) = new AccumulateAnyArray(underlying) + implicit def accumulateDoubleCollection(underlying: IterableOnce[Double]): AccumulateDoubleCollection = + new AccumulateDoubleCollection(underlying) + implicit def accumulateIntCollection(underlying: IterableOnce[Int]): AccumulateIntCollection = + new AccumulateIntCollection(underlying) + implicit def accumulateLongCollection(underlying: IterableOnce[Long]): AccumulateLongCollection = + new AccumulateLongCollection(underlying) + implicit def accumulateAnyArray[A](underlying: Array[A]): AccumulateAnyArray[A] = + new AccumulateAnyArray(underlying) } trait Priority1AccumulatorConverters extends Priority2AccumulatorConverters { - implicit def accumulateDoubleArray(underlying: Array[Double]) = new AccumulateDoubleArray(underlying) - implicit def accumulateIntArray(underlying: Array[Int]) = new AccumulateIntArray(underlying) - implicit def accumulateLongArray(underlying: Array[Long]) = new AccumulateLongArray(underlying) + implicit def accumulateDoubleArray(underlying: Array[Double]): AccumulateDoubleArray = + new AccumulateDoubleArray(underlying) + implicit def accumulateIntArray(underlying: Array[Int]): AccumulateIntArray = + new AccumulateIntArray(underlying) + implicit def accumulateLongArray(underlying: Array[Long]): AccumulateLongArray = + new AccumulateLongArray(underlying) } diff --git a/src/main/scala/scala/compat/java8/OptionConverters.scala b/src/main/scala/scala/compat/java8/OptionConverters.scala index 49e06c2..64572dc 100644 --- a/src/main/scala/scala/compat/java8/OptionConverters.scala +++ b/src/main/scala/scala/compat/java8/OptionConverters.scala @@ -58,30 +58,33 @@ object OptionConverters { /** Converts from `Option` to a manually specialized variant `That` */ def fromScala(o: Option[A]): That } - + /** Implementation of creation of `OptionalDouble` from `Option[Double]` or `Optional[Double]`*/ - implicit val specializer_OptionalDouble = new SpecializerOfOptions[Double, OptionalDouble] { - /** Creates an `OptionalDouble` from `Optional[Double]` */ - def fromJava(o: Optional[Double]): OptionalDouble = if (o.isPresent) OptionalDouble.of(o.get) else OptionalDouble.empty - /** Creates an `OptionalDouble` from `Option[Double]` */ - def fromScala(o: Option[Double]): OptionalDouble = o match { case Some(d) => OptionalDouble.of(d); case _ => OptionalDouble.empty } - } - + implicit val specializer_OptionalDouble: SpecializerOfOptions[Double, OptionalDouble] = + new SpecializerOfOptions[Double, OptionalDouble] { + /** Creates an `OptionalDouble` from `Optional[Double]` */ + def fromJava(o: Optional[Double]): OptionalDouble = if (o.isPresent) OptionalDouble.of(o.get) else OptionalDouble.empty + /** Creates an `OptionalDouble` from `Option[Double]` */ + def fromScala(o: Option[Double]): OptionalDouble = o match { case Some(d) => OptionalDouble.of(d); case _ => OptionalDouble.empty } + } + /** Implementation of creation of `OptionalInt` from `Option[Int]` or `Optional[Int]`*/ - implicit val specializer_OptionalInt = new SpecializerOfOptions[Int, OptionalInt] { - /** Creates an `OptionalInt` from `Optional[Int]` */ - def fromJava(o: Optional[Int]): OptionalInt = if (o.isPresent) OptionalInt.of(o.get) else OptionalInt.empty - /** Creates an `OptionalInt` from `Option[Int]` */ - def fromScala(o: Option[Int]): OptionalInt = o match { case Some(d) => OptionalInt.of(d); case _ => OptionalInt.empty } - } - + implicit val specializer_OptionalInt: SpecializerOfOptions[Int, OptionalInt] = + new SpecializerOfOptions[Int, OptionalInt] { + /** Creates an `OptionalInt` from `Optional[Int]` */ + def fromJava(o: Optional[Int]): OptionalInt = if (o.isPresent) OptionalInt.of(o.get) else OptionalInt.empty + /** Creates an `OptionalInt` from `Option[Int]` */ + def fromScala(o: Option[Int]): OptionalInt = o match { case Some(d) => OptionalInt.of(d); case _ => OptionalInt.empty } + } + /** Implementation of creation of `OptionalLong` from `Option[Long]` or `Optional[Long]`*/ - implicit val specializer_OptionalLong = new SpecializerOfOptions[Long, OptionalLong] { - /** Creates an `OptionalLong` from `Optional[Long]` */ - def fromJava(o: Optional[Long]): OptionalLong = if (o.isPresent) OptionalLong.of(o.get) else OptionalLong.empty - /** Creates an `OptionalLong` from `Option[Long]` */ - def fromScala(o: Option[Long]): OptionalLong = o match { case Some(d) => OptionalLong.of(d); case _ => OptionalLong.empty } - } + implicit val specializer_OptionalLong: SpecializerOfOptions[Long, OptionalLong] = + new SpecializerOfOptions[Long, OptionalLong] { + /** Creates an `OptionalLong` from `Optional[Long]` */ + def fromJava(o: Optional[Long]): OptionalLong = if (o.isPresent) OptionalLong.of(o.get) else OptionalLong.empty + /** Creates an `OptionalLong` from `Option[Long]` */ + def fromScala(o: Option[Long]): OptionalLong = o match { case Some(d) => OptionalLong.of(d); case _ => OptionalLong.empty } + } /** Provides conversions from `java.util.Optional` to Scala `Option` or primitive `java.util.Optional` types */ implicit class RichOptionalGeneric[A](val underlying: java.util.Optional[A]) extends AnyVal { @@ -90,7 +93,7 @@ object OptionConverters { /** Create a specialized primitive variant of this generic `Optional`, if an appropriate one exists */ def asPrimitive[That](implicit specOp: SpecializerOfOptions[A, That]): That = specOp.fromJava(underlying) } - + /** Provides conversions from `scala.Option` to Java `Optional` types, either generic or primitive */ implicit class RichOptionForJava8[A](val underlying: Option[A]) extends AnyVal { /** Create a `java.util.Optional` version of this `Option` (not specialized) */ @@ -98,7 +101,7 @@ object OptionConverters { /** Create a specialized primitive `java.util.Optional` type, if an appropriate one exists */ def asPrimitive[That](implicit specOp: SpecializerOfOptions[A, That]): That = specOp.fromScala(underlying) } - + /** Provides conversions from `java.util.OptionalDouble` to the generic `Optional` and Scala `Option` */ implicit class RichOptionalDouble(val underlying: OptionalDouble) extends AnyVal { /** Create a `scala.Option` version of this `OptionalDouble` */ @@ -106,7 +109,7 @@ object OptionConverters { /** Create a generic `java.util.Optional` version of this `OptionalDouble` */ def asGeneric: Optional[Double] = if (underlying.isPresent) Optional.of(underlying.getAsDouble) else Optional.empty[Double] } - + /** Provides conversions from `java.util.OptionalInt` to the generic `Optional` and Scala `Option` */ implicit class RichOptionalInt(val underlying: OptionalInt) extends AnyVal { /** Create a `scala.Option` version of this `OptionalInt` */ @@ -114,7 +117,7 @@ object OptionConverters { /** Create a generic `java.util.Optional` version of this `OptionalInt` */ def asGeneric: Optional[Int] = if (underlying.isPresent) Optional.of(underlying.getAsInt) else Optional.empty[Int] } - + /** Provides conversions from `java.util.OptionalLong` to the generic `Optional` and Scala `Option` */ implicit class RichOptionalLong(val underlying: OptionalLong) extends AnyVal { /** Create a `scala.Option` version of this `OptionalLong` */ @@ -122,10 +125,10 @@ object OptionConverters { /** Create a generic `java.util.Optional` version of this `OptionalLong` */ def asGeneric: Optional[Long] = if (underlying.isPresent) Optional.of(underlying.getAsLong) else Optional.empty[Long] } - + /** Conversion from Scala `Option` to Java `Optional` without using implicits, for convenient use from Java. */ final def toJava[A](o: Option[A]): Optional[A] = o match { case Some(a) => Optional.ofNullable(a); case _ => Optional.empty[A] } - + /** Conversion from Java `Optional` to Scala `Option` without using implicits, for convenient use from Java */ final def toScala[A](o: Optional[A]): Option[A] = if (o.isPresent) Some(o.get) else None diff --git a/src/main/scala/scala/compat/java8/PrimitiveIteratorConversions.scala b/src/main/scala/scala/compat/java8/PrimitiveIteratorConversions.scala index d0abb4d..20400b4 100644 --- a/src/main/scala/scala/compat/java8/PrimitiveIteratorConversions.scala +++ b/src/main/scala/scala/compat/java8/PrimitiveIteratorConversions.scala @@ -39,76 +39,79 @@ object PrimitiveIteratorConverters { /** Packages a Scala `Iterator` to a manually specialized Java variant `That` */ def fromScala(it: Iterator[A]): That } - + /** Implementation of wrapping of `java.util.Iterator[Double]` or `scala.collection.Iterator[Double]` as a `java.util.PrimitiveIterator.OfDouble` */ - implicit val specializer_PrimitiveIteratorDouble = new SpecializerOfIterators[Double, PrimitiveIterator.OfDouble] { - /** Packages a `java.util.Iterator[Double]` as a `java.util.PrimitiveIterator.OfDouble` */ - def fromJava(it: JIterator[Double]): PrimitiveIterator.OfDouble = - new wrappers.IteratorPrimitiveDoubleWrapper(it.asInstanceOf[JIterator[java.lang.Double]]) - - /** Packages a `scala.collection.Iterator[Double]` as a `java.util.PrimitiveIterator.OfDouble` */ - def fromScala(it: Iterator[Double]): PrimitiveIterator.OfDouble = new PrimitiveIterator.OfDouble { - def hasNext = it.hasNext - override def next() = it.next().asInstanceOf[java.lang.Double] - def nextDouble() = it.next() - override def remove(): Unit = { throw new UnsupportedOperationException("remove on scala.collection.Iterator") } - override def forEachRemaining(c: java.util.function.Consumer[_ >: java.lang.Double]): Unit = { - while (it.hasNext) c.accept(it.next()) - } - override def forEachRemaining(c: java.util.function.DoubleConsumer): Unit = { - while (it.hasNext) c.accept(it.next()) + implicit val specializer_PrimitiveIteratorDouble: SpecializerOfIterators[Double, PrimitiveIterator.OfDouble] = + new SpecializerOfIterators[Double, PrimitiveIterator.OfDouble] { + /** Packages a `java.util.Iterator[Double]` as a `java.util.PrimitiveIterator.OfDouble` */ + def fromJava(it: JIterator[Double]): PrimitiveIterator.OfDouble = + new wrappers.IteratorPrimitiveDoubleWrapper(it.asInstanceOf[JIterator[java.lang.Double]]) + + /** Packages a `scala.collection.Iterator[Double]` as a `java.util.PrimitiveIterator.OfDouble` */ + def fromScala(it: Iterator[Double]): PrimitiveIterator.OfDouble = new PrimitiveIterator.OfDouble { + def hasNext = it.hasNext + override def next() = it.next().asInstanceOf[java.lang.Double] + def nextDouble() = it.next() + override def remove(): Unit = { throw new UnsupportedOperationException("remove on scala.collection.Iterator") } + override def forEachRemaining(c: java.util.function.Consumer[_ >: java.lang.Double]): Unit = { + while (it.hasNext) c.accept(it.next()) + } + override def forEachRemaining(c: java.util.function.DoubleConsumer): Unit = { + while (it.hasNext) c.accept(it.next()) + } } } - } - + /** Implementation of wrapping of `java.util.Iterator[Int]` or `scala.collection.Iterator[Int]` as a `java.util.PrimitiveIterator.OfInt` */ - implicit val specializer_PrimitiveIteratorInt = new SpecializerOfIterators[Int, PrimitiveIterator.OfInt] { - /** Packages a `java.util.Iterator[Int]` as a `java.util.PrimitiveIterator.OfInt` */ - def fromJava(it: JIterator[Int]): PrimitiveIterator.OfInt = - new wrappers.IteratorPrimitiveIntWrapper(it.asInstanceOf[JIterator[java.lang.Integer]]) - - /** Packages a `scala.collection.Iterator[Int]` as a `java.util.PrimitiveIterator.OfInt` */ - def fromScala(it: Iterator[Int]): PrimitiveIterator.OfInt = new PrimitiveIterator.OfInt { - def hasNext = it.hasNext - override def next() = it.next().asInstanceOf[java.lang.Integer] - def nextInt() = it.next() - override def remove(): Unit = { throw new UnsupportedOperationException("remove on scala.collection.Iterator") } - override def forEachRemaining(c: java.util.function.Consumer[_ >: java.lang.Integer]): Unit = { - while (it.hasNext) c.accept(it.next()) - } - override def forEachRemaining(c: java.util.function.IntConsumer): Unit = { - while (it.hasNext) c.accept(it.next()) + implicit val specializer_PrimitiveIteratorInt: SpecializerOfIterators[Int, PrimitiveIterator.OfInt] = + new SpecializerOfIterators[Int, PrimitiveIterator.OfInt] { + /** Packages a `java.util.Iterator[Int]` as a `java.util.PrimitiveIterator.OfInt` */ + def fromJava(it: JIterator[Int]): PrimitiveIterator.OfInt = + new wrappers.IteratorPrimitiveIntWrapper(it.asInstanceOf[JIterator[java.lang.Integer]]) + + /** Packages a `scala.collection.Iterator[Int]` as a `java.util.PrimitiveIterator.OfInt` */ + def fromScala(it: Iterator[Int]): PrimitiveIterator.OfInt = new PrimitiveIterator.OfInt { + def hasNext = it.hasNext + override def next() = it.next().asInstanceOf[java.lang.Integer] + def nextInt() = it.next() + override def remove(): Unit = { throw new UnsupportedOperationException("remove on scala.collection.Iterator") } + override def forEachRemaining(c: java.util.function.Consumer[_ >: java.lang.Integer]): Unit = { + while (it.hasNext) c.accept(it.next()) + } + override def forEachRemaining(c: java.util.function.IntConsumer): Unit = { + while (it.hasNext) c.accept(it.next()) + } } } - } - + /** Implementation of wrapping of `java.util.Iterator[Long]` or `scala.collection.Iterator[Long]` as a `java.util.PrimitiveIterator.OfLong` */ - implicit val specializer_PrimitiveIteratorLong = new SpecializerOfIterators[Long, PrimitiveIterator.OfLong] { - /** Packages a `java.util.Iterator[Long]` as a `java.util.PrimitiveIterator.OfLong` */ - def fromJava(it: JIterator[Long]): PrimitiveIterator.OfLong = - new wrappers.IteratorPrimitiveLongWrapper(it.asInstanceOf[JIterator[java.lang.Long]]) - - /** Packages a `scala.collection.Iterator[Long]` as a `java.util.PrimitiveIterator.OfLong` */ - def fromScala(it: Iterator[Long]): PrimitiveIterator.OfLong = new PrimitiveIterator.OfLong { - def hasNext = it.hasNext - override def next() = it.next().asInstanceOf[java.lang.Long] - def nextLong() = it.next() - override def remove(): Unit = { throw new UnsupportedOperationException("remove on scala.collection.Iterator") } - override def forEachRemaining(c: java.util.function.Consumer[_ >: java.lang.Long]): Unit = { - while (it.hasNext) c.accept(it.next()) - } - override def forEachRemaining(c: java.util.function.LongConsumer): Unit = { - while (it.hasNext) c.accept(it.next()) + implicit val specializer_PrimitiveIteratorLong: SpecializerOfIterators[Long, PrimitiveIterator.OfLong] = + new SpecializerOfIterators[Long, PrimitiveIterator.OfLong] { + /** Packages a `java.util.Iterator[Long]` as a `java.util.PrimitiveIterator.OfLong` */ + def fromJava(it: JIterator[Long]): PrimitiveIterator.OfLong = + new wrappers.IteratorPrimitiveLongWrapper(it.asInstanceOf[JIterator[java.lang.Long]]) + + /** Packages a `scala.collection.Iterator[Long]` as a `java.util.PrimitiveIterator.OfLong` */ + def fromScala(it: Iterator[Long]): PrimitiveIterator.OfLong = new PrimitiveIterator.OfLong { + def hasNext = it.hasNext + override def next() = it.next().asInstanceOf[java.lang.Long] + def nextLong() = it.next() + override def remove(): Unit = { throw new UnsupportedOperationException("remove on scala.collection.Iterator") } + override def forEachRemaining(c: java.util.function.Consumer[_ >: java.lang.Long]): Unit = { + while (it.hasNext) c.accept(it.next()) + } + override def forEachRemaining(c: java.util.function.LongConsumer): Unit = { + while (it.hasNext) c.accept(it.next()) + } } } - } - + /** Provides conversions from Java `Iterator` to manually specialized `PrimitiveIterator` variants, when available */ implicit final class RichJavaIteratorToPrimitives[A](private val underlying: JIterator[A]) extends AnyVal { /** Wraps this `java.util.Iterator` as a manually specialized variant, if possible */ def asPrimitive[That](implicit specOp: SpecializerOfIterators[A, That]): That = specOp.fromJava(underlying) } - + /** Provides conversions from Scala `Iterator` to manually specialized `PrimitiveIterator` variants, when available */ implicit final class RichIteratorToPrimitives[A](private val underlying: Iterator[A]) extends AnyVal { /** Wraps this `scala.collection.Iterator` as a manually specialized `java.util.PrimitiveIterator` variant, if possible */ From d26adbe3672fc86b5f62de91fc5d8849abccad5a Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Tue, 23 Mar 2021 07:28:11 -0700 Subject: [PATCH 4/7] add Scala 3 to crossbuild fixes #200 --- .travis.yml | 1 + build.sbt | 29 +++++++++++++++++++---------- project/plugins.sbt | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index d5108f1..0a3363c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ import: scala/scala-dev:travis/default.yml language: scala scala: + - 3.0.0-RC1 - 2.11.12 - 2.12.13 - 2.13.5 diff --git a/build.sbt b/build.sbt index 3d1ab7a..d081181 100644 --- a/build.sbt +++ b/build.sbt @@ -27,9 +27,9 @@ lazy val commonSettings = Seq( Compile / unmanagedSourceDirectories ++= { (Compile / unmanagedSourceDirectories).value.flatMap { dir => CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => Seq(file(dir.getPath ++ "-2.13+")) case Some((2, 11)) => Seq(file(dir.getPath ++ "-2.13-"), file(dir.getPath ++ "-2.11")) - case _ => Seq(file(dir.getPath ++ "-2.13-")) + case Some((2, 12)) => Seq(file(dir.getPath ++ "-2.13-")) + case _ => Seq(file(dir.getPath ++ "-2.13+")) } } }, @@ -37,9 +37,9 @@ lazy val commonSettings = Seq( Test / unmanagedSourceDirectories ++= { (Test / unmanagedSourceDirectories).value.flatMap { dir => CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => Seq(file(dir.getPath ++ "-2.13+")) case Some((2, 11)) => Seq(file(dir.getPath ++ "-2.13-"), file(dir.getPath ++ "-2.11")) - case _ => Seq(file(dir.getPath ++ "-2.13-")) + case Some((2, 12)) => Seq(file(dir.getPath ++ "-2.13-")) + case _ => Seq(file(dir.getPath ++ "-2.13+")) } } }, @@ -48,6 +48,8 @@ lazy val commonSettings = Seq( lazy val fnGen = (project in file("fnGen")) .settings(commonSettings) .settings( + crossScalaVersions := Seq("2.12.13"), + scalaVersion := crossScalaVersions.value.head, run / fork := true, // Needed if you run this project directly libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value, libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value @@ -73,10 +75,11 @@ lazy val scalaJava8Compat = (project in file(".")) libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test", - // we're still in 0.x land so we could choose to break bincompat, - // but let's at least be aware when we're doing it. also we should - // think about going 1.0, it's been a while - scalaModuleMimaPreviousVersion := Some("0.9.1"), + scalaModuleMimaPreviousVersion := { + // pending resolution of https://github.com/scalacenter/sbt-version-policy/issues/62 + if (isDotty.value) None + else Some("0.9.1") + }, mimaBinaryIssueFilters ++= { import com.typesafe.tools.mima.core._, ProblemFilters._ @@ -146,8 +149,14 @@ lazy val scalaJava8Compat = (project in file(".")) }, JavaDoc / javacOptions := Seq("-Xdoclint:none"), JavaDoc / packageDoc / artifactName := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar"), - libraryDependencies += compilerPlugin("com.typesafe.genjavadoc" % "genjavadoc-plugin" % "0.16" cross CrossVersion.full), - Compile / scalacOptions += "-P:genjavadoc:out=" + (target.value / "java") + libraryDependencies ++= ( + if (isDotty.value) Seq() + else Seq(compilerPlugin("com.typesafe.genjavadoc" % "genjavadoc-plugin" % "0.16" cross CrossVersion.full)) + ), + Compile / scalacOptions ++= ( + if (isDotty.value) Seq() + else Seq(s"""-P:genjavadoc:out=${target.value / "java"}""") + ), ) } ) diff --git a/project/plugins.sbt b/project/plugins.sbt index 32698b2..e47c7d1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,3 @@ addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.2.4") addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "1.0.0-RC5") +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3") From a7fc68fb04ab0b247a13a9928bc712ec8aa03130 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 25 Mar 2021 17:00:54 -0700 Subject: [PATCH 5/7] remove redundant code in build.sbt this is already handled by sbt-scala-module --- build.sbt | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.sbt b/build.sbt index d081181..2978b49 100644 --- a/build.sbt +++ b/build.sbt @@ -22,8 +22,6 @@ ThisBuild / versionScheme := Some("early-semver") ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible lazy val commonSettings = Seq( - scalacOptions ++= Seq("-feature", "-deprecation", "-unchecked"), - Compile / unmanagedSourceDirectories ++= { (Compile / unmanagedSourceDirectories).value.flatMap { dir => CrossVersion.partialVersion(scalaVersion.value) match { @@ -33,7 +31,6 @@ lazy val commonSettings = Seq( } } }, - Test / unmanagedSourceDirectories ++= { (Test / unmanagedSourceDirectories).value.flatMap { dir => CrossVersion.partialVersion(scalaVersion.value) match { From 0dbec1f9f57e26072c1ba5349b3c4129ee56363a Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 25 Mar 2021 17:17:22 -0700 Subject: [PATCH 6/7] avoid unchecked warning --- src/main/scala/scala/compat/java8/FutureConverters.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/scala/compat/java8/FutureConverters.scala b/src/main/scala/scala/compat/java8/FutureConverters.scala index 794ae7e..7f75ee0 100644 --- a/src/main/scala/scala/compat/java8/FutureConverters.scala +++ b/src/main/scala/scala/compat/java8/FutureConverters.scala @@ -66,7 +66,7 @@ object FutureConverters { */ def toJava[T](f: Future[T]): CompletionStage[T] = { f match { - case p: P[T] => p.wrapped + case p: P[T @unchecked] => p.wrapped case _ => val cf = new CF[T](f) implicit val ec = InternalCallbackExecutor From 5160b411d4076697478e2f0aa1239ecd9994ce8e Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 25 Mar 2021 17:17:42 -0700 Subject: [PATCH 7/7] for Scala 3, remove a type parameter from StreamConverters I do not fully understand why this was here, but Scala 3 was complaining: "Polymorphic refinement method valueStepper without matching type in parent trait MapOps is no longer allowed" simplifying the code as I have done in this commit compiles on both Scala versions and the tests still pass, and this is an obscure enough corner of the API that I'm not inclined to spend time really digging deeply into it (e.g. attempting to construct a test case that would now compile when it shouldn't, or vice versa) --- src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala b/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala index 47bfa05..309d4c3 100644 --- a/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala +++ b/src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala @@ -86,7 +86,7 @@ trait StreamExtensions { implicit class MapHasParKeyValueStream[K, V, CC[X, Y] <: collection.MapOps[X, Y, collection.Map, _]](cc: CC[K, V]) { private type MapOpsWithEfficientKeyStepper = collection.MapOps[K, V, collection.Map, _] { def keyStepper[S <: Stepper[_]](implicit shape : StepperShape[K, S]) : S with EfficientSplit } - private type MapOpsWithEfficientValueStepper = collection.MapOps[K, V, collection.Map, _] { def valueStepper[V1 >: V, S <: Stepper[_]](implicit shape : StepperShape[V1, S]) : S with EfficientSplit } + private type MapOpsWithEfficientValueStepper = collection.MapOps[K, V, collection.Map, _] { def valueStepper[S <: Stepper[_]](implicit shape : StepperShape[V, S]) : S with EfficientSplit } private type MapOpsWithEfficientStepper = collection.MapOps[K, V, collection.Map, _] { def stepper[S <: Stepper[_]](implicit shape : StepperShape[(K, V), S]) : S with EfficientSplit } /** Create a parallel [[java.util.stream.Stream Java Stream]] for the keys of this map. If