Skip to content

Commit

Permalink
Replace scala-collection-compat with ScalaCollectionCompat (#230)
Browse files Browse the repository at this point in the history
* Cleanup imports in Reads.scala

* Replace scala-collection-compat with ScalaCollectionCompat
  • Loading branch information
dwijnand authored and marcospereira committed Jan 28, 2019
1 parent b89d0ce commit 5b04b89
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
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

0 comments on commit 5b04b89

Please sign in to comment.