Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace scala-collection-compat with ScalaCollectionCompat #230

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ lazy val `play-json` = crossProject(JVMPlatform, JSPlatform).crossType(CrossType
"org.typelevel" %% "macro-compat" % "1.1.1",
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
),
libraryDependencies ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("org.scala-lang.modules" %%% "scala-collection-compat" % "0.2.0")
case _ => Seq("org.scala-lang.modules" %%% "scala-collection-compat" % "0.1.1")
}),
libraryDependencies ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq()
case _ => Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full))
}),
unmanagedSourceDirectories in Compile += {
//val sourceDir = (sourceDirectory in Compile).value
// ^ gives jvm/src/main, for some reason
val sourceDir = baseDirectory.value / "../shared/src/main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 13 => sourceDir / "scala-2.13+"
case _ => sourceDir / "scala-2.13-"
}
},
sourceGenerators in Compile += Def.task{
val dir = (sourceManaged in Compile).value

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/

package play.api.libs.json

/** Copied from scala-collection-compat, because its binary API isn't stable. */
private[json] object ScalaCollectionCompat {
type Factory[-A, +C] = scala.collection.Factory[A, C]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/

package play.api.libs.json

import scala.language.implicitConversions
import scala.language.higherKinds

import scala.collection.generic.CanBuildFrom
import scala.collection.mutable

/** Copied from scala-collection-compat, because its binary API isn't stable. */
private[json] object ScalaCollectionCompat {

/**
* A factory that builds a collection of type `C` with elements of type `A`.
*
* Type param `A` is the type of elements (e.g. `Int`, `Boolean`, etc.).
* Type param `C` is the type of collection (e.g. `List[Int]`, `TreeMap[Int, String]`, etc.).
*/
type Factory[-A, +C] = CanBuildFrom[Nothing, A, C]

final implicit class FactoryOps[-A, +C](private val factory: Factory[A, C]) {
def newBuilder: mutable.Builder[A, C] = factory()
}

}
12 changes: 5 additions & 7 deletions play-json/shared/src/main/scala/play/api/libs/json/Reads.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

package play.api.libs.json

import scala.annotation.implicitNotFound

import scala.util.control
import scala.language.higherKinds

import scala.annotation.implicitNotFound
import scala.collection.Seq
import scala.collection.compat._
import scala.collection.immutable.Map
import scala.collection.mutable.Builder
import scala.reflect.ClassTag
import scala.util.control

import scala.language.higherKinds

import reflect.ClassTag
import ScalaCollectionCompat._

/**
* A `Reads` object describes how to decode JSON into a value.
Expand Down