Skip to content

Commit 72e8efc

Browse files
authored
Merge pull request #215 from SethTisue/scala3
2 parents 05ca073 + 5160b41 commit 72e8efc

File tree

9 files changed

+149
-127
lines changed

9 files changed

+149
-127
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import: scala/scala-dev:travis/default.yml
55
language: scala
66

77
scala:
8+
- 3.0.0-RC1
89
- 2.11.12
910
- 2.12.13
1011
- 2.13.5

Diff for: build.sbt

+38-32
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,21 @@ ThisBuild / versionScheme := Some("early-semver")
2222
ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible
2323

2424
lazy val commonSettings = Seq(
25-
scalacOptions ++= Seq("-feature", "-deprecation", "-unchecked"),
26-
27-
unmanagedSourceDirectories in Compile ++= {
28-
(unmanagedSourceDirectories in Compile).value.flatMap { dir =>
25+
Compile / unmanagedSourceDirectories ++= {
26+
(Compile / unmanagedSourceDirectories).value.flatMap { dir =>
2927
CrossVersion.partialVersion(scalaVersion.value) match {
30-
case Some((2, 13)) => Seq(file(dir.getPath ++ "-2.13+"))
3128
case Some((2, 11)) => Seq(file(dir.getPath ++ "-2.13-"), file(dir.getPath ++ "-2.11"))
32-
case _ => Seq(file(dir.getPath ++ "-2.13-"))
29+
case Some((2, 12)) => Seq(file(dir.getPath ++ "-2.13-"))
30+
case _ => Seq(file(dir.getPath ++ "-2.13+"))
3331
}
3432
}
3533
},
36-
37-
unmanagedSourceDirectories in Test ++= {
38-
(unmanagedSourceDirectories in Test).value.flatMap { dir =>
34+
Test / unmanagedSourceDirectories ++= {
35+
(Test / unmanagedSourceDirectories).value.flatMap { dir =>
3936
CrossVersion.partialVersion(scalaVersion.value) match {
40-
case Some((2, 13)) => Seq(file(dir.getPath ++ "-2.13+"))
4137
case Some((2, 11)) => Seq(file(dir.getPath ++ "-2.13-"), file(dir.getPath ++ "-2.11"))
42-
case _ => Seq(file(dir.getPath ++ "-2.13-"))
38+
case Some((2, 12)) => Seq(file(dir.getPath ++ "-2.13-"))
39+
case _ => Seq(file(dir.getPath ++ "-2.13+"))
4340
}
4441
}
4542
},
@@ -48,7 +45,9 @@ lazy val commonSettings = Seq(
4845
lazy val fnGen = (project in file("fnGen"))
4946
.settings(commonSettings)
5047
.settings(
51-
fork in run := true, // Needed if you run this project directly
48+
crossScalaVersions := Seq("2.12.13"),
49+
scalaVersion := crossScalaVersions.value.head,
50+
run / fork := true, // Needed if you run this project directly
5251
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
5352
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
5453
)
@@ -73,10 +72,11 @@ lazy val scalaJava8Compat = (project in file("."))
7372

7473
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
7574

76-
// we're still in 0.x land so we could choose to break bincompat,
77-
// but let's at least be aware when we're doing it. also we should
78-
// think about going 1.0, it's been a while
79-
scalaModuleMimaPreviousVersion := Some("0.9.1"),
75+
scalaModuleMimaPreviousVersion := {
76+
// pending resolution of https://github.com/scalacenter/sbt-version-policy/issues/62
77+
if (isDotty.value) None
78+
else Some("0.9.1")
79+
},
8080

8181
mimaBinaryIssueFilters ++= {
8282
import com.typesafe.tools.mima.core._, ProblemFilters._
@@ -93,19 +93,19 @@ lazy val scalaJava8Compat = (project in file("."))
9393

9494
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a"),
9595

96-
(sourceGenerators in Compile) += Def.task {
97-
val out = (sourceManaged in Compile).value
96+
(Compile / sourceGenerators) += Def.task {
97+
val out = (Compile / sourceManaged).value
9898
if (!out.exists) IO.createDirectory(out)
9999
val canon = out.getCanonicalPath
100100
val args = (new File(canon, "FunctionConverters.scala")).toString :: Nil
101-
val runTarget = (mainClass in Compile in fnGen).value getOrElse "No main class defined for function conversion generator"
102-
val classPath = (fullClasspath in Compile in fnGen).value
101+
val runTarget = (fnGen / Compile / mainClass).value getOrElse "No main class defined for function conversion generator"
102+
val classPath = (fnGen / Compile / fullClasspath).value
103103
runner.value.run(runTarget, classPath.files, args, streams.value.log)
104104
(out ** "*.scala").get
105105
}.taskValue,
106106

107-
sourceGenerators in Compile += Def.task {
108-
val dir = (sourceManaged in Compile).value
107+
Compile / sourceGenerators += Def.task {
108+
val dir = (Compile / sourceManaged).value
109109
val write = jwrite(dir) _
110110
if(scalaVersion.value.startsWith("2.11.")) {
111111
Seq(write("JFunction", CodeGen.factory)) ++
@@ -118,8 +118,8 @@ lazy val scalaJava8Compat = (project in file("."))
118118
} else CodeGen.create212.map(write.tupled)
119119
}.taskValue,
120120

121-
sourceGenerators in Test += Def.task {
122-
Seq(jwrite((sourceManaged in Test).value)("TestApi", CodeGen.testApi))
121+
Test / sourceGenerators += Def.task {
122+
Seq(jwrite((Test / sourceManaged).value)("TestApi", CodeGen.testApi))
123123
}.taskValue,
124124

125125
initialize := {
@@ -131,23 +131,29 @@ lazy val scalaJava8Compat = (project in file("."))
131131
sys.error("Java 8 or higher is required for this project.")
132132
},
133133

134-
publishArtifact in packageDoc := !disableDocs
134+
packageDoc / publishArtifact := !disableDocs
135135
)
136136
.settings(
137137
inConfig(JavaDoc)(Defaults.configSettings) ++ {
138138
if (disableDocs) Nil
139139
else Seq(
140-
packageDoc in Compile := (packageDoc in JavaDoc).value,
141-
sources in JavaDoc := {
140+
Compile / packageDoc := (JavaDoc / packageDoc).value,
141+
JavaDoc / sources := {
142142
val allJavaSources =
143143
(target.value / "java" ** "*.java").get ++
144-
(sources in Compile).value.filter(_.getName.endsWith(".java"))
144+
(Compile / sources).value.filter(_.getName.endsWith(".java"))
145145
allJavaSources.filterNot(_.getName.contains("FuturesConvertersImpl.java")) // this file triggers bugs in genjavadoc
146146
},
147-
javacOptions in JavaDoc := Seq("-Xdoclint:none"),
148-
artifactName in packageDoc in JavaDoc := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar"),
149-
libraryDependencies += compilerPlugin("com.typesafe.genjavadoc" % "genjavadoc-plugin" % "0.16" cross CrossVersion.full),
150-
scalacOptions in Compile += "-P:genjavadoc:out=" + (target.value / "java")
147+
JavaDoc / javacOptions := Seq("-Xdoclint:none"),
148+
JavaDoc / packageDoc / artifactName := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar"),
149+
libraryDependencies ++= (
150+
if (isDotty.value) Seq()
151+
else Seq(compilerPlugin("com.typesafe.genjavadoc" % "genjavadoc-plugin" % "0.16" cross CrossVersion.full))
152+
),
153+
Compile / scalacOptions ++= (
154+
if (isDotty.value) Seq()
155+
else Seq(s"""-P:genjavadoc:out=${target.value / "java"}""")
156+
),
151157
)
152158
}
153159
)

Diff for: fnGen/WrapFnGen.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ object WrapFnGen {
143143

144144
private def buildWrappersViaReflection: Seq[SamConversionCode] = {
145145

146-
val pack: Symbol = rootMirror.getPackageIfDefined(TermName("java.util.function"))
146+
val pack: Symbol = rootMirror.getPackageIfDefined("java.util.function")
147147

148148
case class Jfn(iface: Symbol, sam: Symbol) {
149149
lazy val genericCount = iface.typeParams.length

Diff for: project/plugins.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.2.4")
22
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "1.0.0-RC5")
3+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")

Diff for: src/main/scala-2.13+/scala/compat/java8/StreamConverters.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import scala.collection.{IterableOnce, Stepper, StepperShape}
2121
import scala.compat.java8.converterImpl._
2222
import scala.jdk.CollectionConverters._
2323
import scala.jdk._
24-
import scala.language.{higherKinds, implicitConversions}
24+
import scala.language.implicitConversions
2525

2626
/** Defines extension methods to create Java Streams for Scala collections, available through
2727
* [[scala.compat.java8.StreamConverters]].
@@ -86,7 +86,7 @@ trait StreamExtensions {
8686

8787
implicit class MapHasParKeyValueStream[K, V, CC[X, Y] <: collection.MapOps[X, Y, collection.Map, _]](cc: CC[K, V]) {
8888
private type MapOpsWithEfficientKeyStepper = collection.MapOps[K, V, collection.Map, _] { def keyStepper[S <: Stepper[_]](implicit shape : StepperShape[K, S]) : S with EfficientSplit }
89-
private type MapOpsWithEfficientValueStepper = collection.MapOps[K, V, collection.Map, _] { def valueStepper[V1 >: V, S <: Stepper[_]](implicit shape : StepperShape[V1, S]) : S with EfficientSplit }
89+
private type MapOpsWithEfficientValueStepper = collection.MapOps[K, V, collection.Map, _] { def valueStepper[S <: Stepper[_]](implicit shape : StepperShape[V, S]) : S with EfficientSplit }
9090
private type MapOpsWithEfficientStepper = collection.MapOps[K, V, collection.Map, _] { def stepper[S <: Stepper[_]](implicit shape : StepperShape[(K, V), S]) : S with EfficientSplit }
9191

9292
/** Create a parallel [[java.util.stream.Stream Java Stream]] for the keys of this map. If

Diff for: src/main/scala-2.13+/scala/compat/java8/converterImpl/AccumulatorConverters.scala

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ package scala.compat.java8.converterImpl
1515
import scala.language.implicitConversions
1616

1717
trait Priority3AccumulatorConverters {
18-
implicit def collectionCanAccumulate[A](underlying: IterableOnce[A]) = new CollectionCanAccumulate[A](underlying)
18+
implicit def collectionCanAccumulate[A](underlying: IterableOnce[A]): CollectionCanAccumulate[A] =
19+
new CollectionCanAccumulate[A](underlying)
1920
}
2021

2122
trait Priority2AccumulatorConverters extends Priority3AccumulatorConverters {
22-
implicit def accumulateDoubleCollection(underlying: IterableOnce[Double]) = new AccumulateDoubleCollection(underlying)
23-
implicit def accumulateIntCollection(underlying: IterableOnce[Int]) = new AccumulateIntCollection(underlying)
24-
implicit def accumulateLongCollection(underlying: IterableOnce[Long]) = new AccumulateLongCollection(underlying)
25-
implicit def accumulateAnyArray[A](underlying: Array[A]) = new AccumulateAnyArray(underlying)
23+
implicit def accumulateDoubleCollection(underlying: IterableOnce[Double]): AccumulateDoubleCollection =
24+
new AccumulateDoubleCollection(underlying)
25+
implicit def accumulateIntCollection(underlying: IterableOnce[Int]): AccumulateIntCollection =
26+
new AccumulateIntCollection(underlying)
27+
implicit def accumulateLongCollection(underlying: IterableOnce[Long]): AccumulateLongCollection =
28+
new AccumulateLongCollection(underlying)
29+
implicit def accumulateAnyArray[A](underlying: Array[A]): AccumulateAnyArray[A] =
30+
new AccumulateAnyArray(underlying)
2631
}
2732

2833
trait Priority1AccumulatorConverters extends Priority2AccumulatorConverters {
29-
implicit def accumulateDoubleArray(underlying: Array[Double]) = new AccumulateDoubleArray(underlying)
30-
implicit def accumulateIntArray(underlying: Array[Int]) = new AccumulateIntArray(underlying)
31-
implicit def accumulateLongArray(underlying: Array[Long]) = new AccumulateLongArray(underlying)
34+
implicit def accumulateDoubleArray(underlying: Array[Double]): AccumulateDoubleArray =
35+
new AccumulateDoubleArray(underlying)
36+
implicit def accumulateIntArray(underlying: Array[Int]): AccumulateIntArray =
37+
new AccumulateIntArray(underlying)
38+
implicit def accumulateLongArray(underlying: Array[Long]): AccumulateLongArray =
39+
new AccumulateLongArray(underlying)
3240
}

Diff for: src/main/scala/scala/compat/java8/FutureConverters.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object FutureConverters {
6666
*/
6767
def toJava[T](f: Future[T]): CompletionStage[T] = {
6868
f match {
69-
case p: P[T] => p.wrapped
69+
case p: P[T @unchecked] => p.wrapped
7070
case _ =>
7171
val cf = new CF[T](f)
7272
implicit val ec = InternalCallbackExecutor

Diff for: src/main/scala/scala/compat/java8/OptionConverters.scala

+30-27
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,33 @@ object OptionConverters {
5858
/** Converts from `Option` to a manually specialized variant `That` */
5959
def fromScala(o: Option[A]): That
6060
}
61-
61+
6262
/** Implementation of creation of `OptionalDouble` from `Option[Double]` or `Optional[Double]`*/
63-
implicit val specializer_OptionalDouble = new SpecializerOfOptions[Double, OptionalDouble] {
64-
/** Creates an `OptionalDouble` from `Optional[Double]` */
65-
def fromJava(o: Optional[Double]): OptionalDouble = if (o.isPresent) OptionalDouble.of(o.get) else OptionalDouble.empty
66-
/** Creates an `OptionalDouble` from `Option[Double]` */
67-
def fromScala(o: Option[Double]): OptionalDouble = o match { case Some(d) => OptionalDouble.of(d); case _ => OptionalDouble.empty }
68-
}
69-
63+
implicit val specializer_OptionalDouble: SpecializerOfOptions[Double, OptionalDouble] =
64+
new SpecializerOfOptions[Double, OptionalDouble] {
65+
/** Creates an `OptionalDouble` from `Optional[Double]` */
66+
def fromJava(o: Optional[Double]): OptionalDouble = if (o.isPresent) OptionalDouble.of(o.get) else OptionalDouble.empty
67+
/** Creates an `OptionalDouble` from `Option[Double]` */
68+
def fromScala(o: Option[Double]): OptionalDouble = o match { case Some(d) => OptionalDouble.of(d); case _ => OptionalDouble.empty }
69+
}
70+
7071
/** Implementation of creation of `OptionalInt` from `Option[Int]` or `Optional[Int]`*/
71-
implicit val specializer_OptionalInt = new SpecializerOfOptions[Int, OptionalInt] {
72-
/** Creates an `OptionalInt` from `Optional[Int]` */
73-
def fromJava(o: Optional[Int]): OptionalInt = if (o.isPresent) OptionalInt.of(o.get) else OptionalInt.empty
74-
/** Creates an `OptionalInt` from `Option[Int]` */
75-
def fromScala(o: Option[Int]): OptionalInt = o match { case Some(d) => OptionalInt.of(d); case _ => OptionalInt.empty }
76-
}
77-
72+
implicit val specializer_OptionalInt: SpecializerOfOptions[Int, OptionalInt] =
73+
new SpecializerOfOptions[Int, OptionalInt] {
74+
/** Creates an `OptionalInt` from `Optional[Int]` */
75+
def fromJava(o: Optional[Int]): OptionalInt = if (o.isPresent) OptionalInt.of(o.get) else OptionalInt.empty
76+
/** Creates an `OptionalInt` from `Option[Int]` */
77+
def fromScala(o: Option[Int]): OptionalInt = o match { case Some(d) => OptionalInt.of(d); case _ => OptionalInt.empty }
78+
}
79+
7880
/** Implementation of creation of `OptionalLong` from `Option[Long]` or `Optional[Long]`*/
79-
implicit val specializer_OptionalLong = new SpecializerOfOptions[Long, OptionalLong] {
80-
/** Creates an `OptionalLong` from `Optional[Long]` */
81-
def fromJava(o: Optional[Long]): OptionalLong = if (o.isPresent) OptionalLong.of(o.get) else OptionalLong.empty
82-
/** Creates an `OptionalLong` from `Option[Long]` */
83-
def fromScala(o: Option[Long]): OptionalLong = o match { case Some(d) => OptionalLong.of(d); case _ => OptionalLong.empty }
84-
}
81+
implicit val specializer_OptionalLong: SpecializerOfOptions[Long, OptionalLong] =
82+
new SpecializerOfOptions[Long, OptionalLong] {
83+
/** Creates an `OptionalLong` from `Optional[Long]` */
84+
def fromJava(o: Optional[Long]): OptionalLong = if (o.isPresent) OptionalLong.of(o.get) else OptionalLong.empty
85+
/** Creates an `OptionalLong` from `Option[Long]` */
86+
def fromScala(o: Option[Long]): OptionalLong = o match { case Some(d) => OptionalLong.of(d); case _ => OptionalLong.empty }
87+
}
8588

8689
/** Provides conversions from `java.util.Optional` to Scala `Option` or primitive `java.util.Optional` types */
8790
implicit class RichOptionalGeneric[A](val underlying: java.util.Optional[A]) extends AnyVal {
@@ -90,42 +93,42 @@ object OptionConverters {
9093
/** Create a specialized primitive variant of this generic `Optional`, if an appropriate one exists */
9194
def asPrimitive[That](implicit specOp: SpecializerOfOptions[A, That]): That = specOp.fromJava(underlying)
9295
}
93-
96+
9497
/** Provides conversions from `scala.Option` to Java `Optional` types, either generic or primitive */
9598
implicit class RichOptionForJava8[A](val underlying: Option[A]) extends AnyVal {
9699
/** Create a `java.util.Optional` version of this `Option` (not specialized) */
97100
def asJava: Optional[A] = underlying match { case Some(a) => Optional.ofNullable(a); case _ => Optional.empty[A] }
98101
/** Create a specialized primitive `java.util.Optional` type, if an appropriate one exists */
99102
def asPrimitive[That](implicit specOp: SpecializerOfOptions[A, That]): That = specOp.fromScala(underlying)
100103
}
101-
104+
102105
/** Provides conversions from `java.util.OptionalDouble` to the generic `Optional` and Scala `Option` */
103106
implicit class RichOptionalDouble(val underlying: OptionalDouble) extends AnyVal {
104107
/** Create a `scala.Option` version of this `OptionalDouble` */
105108
def asScala: Option[Double] = if (underlying.isPresent) Some(underlying.getAsDouble) else None
106109
/** Create a generic `java.util.Optional` version of this `OptionalDouble` */
107110
def asGeneric: Optional[Double] = if (underlying.isPresent) Optional.of(underlying.getAsDouble) else Optional.empty[Double]
108111
}
109-
112+
110113
/** Provides conversions from `java.util.OptionalInt` to the generic `Optional` and Scala `Option` */
111114
implicit class RichOptionalInt(val underlying: OptionalInt) extends AnyVal {
112115
/** Create a `scala.Option` version of this `OptionalInt` */
113116
def asScala: Option[Int] = if (underlying.isPresent) Some(underlying.getAsInt) else None
114117
/** Create a generic `java.util.Optional` version of this `OptionalInt` */
115118
def asGeneric: Optional[Int] = if (underlying.isPresent) Optional.of(underlying.getAsInt) else Optional.empty[Int]
116119
}
117-
120+
118121
/** Provides conversions from `java.util.OptionalLong` to the generic `Optional` and Scala `Option` */
119122
implicit class RichOptionalLong(val underlying: OptionalLong) extends AnyVal {
120123
/** Create a `scala.Option` version of this `OptionalLong` */
121124
def asScala: Option[Long] = if (underlying.isPresent) Some(underlying.getAsLong) else None
122125
/** Create a generic `java.util.Optional` version of this `OptionalLong` */
123126
def asGeneric: Optional[Long] = if (underlying.isPresent) Optional.of(underlying.getAsLong) else Optional.empty[Long]
124127
}
125-
128+
126129
/** Conversion from Scala `Option` to Java `Optional` without using implicits, for convenient use from Java. */
127130
final def toJava[A](o: Option[A]): Optional[A] = o match { case Some(a) => Optional.ofNullable(a); case _ => Optional.empty[A] }
128-
131+
129132
/** Conversion from Java `Optional` to Scala `Option` without using implicits, for convenient use from Java */
130133
final def toScala[A](o: Optional[A]): Option[A] = if (o.isPresent) Some(o.get) else None
131134

0 commit comments

Comments
 (0)