Skip to content

Commit d8512ba

Browse files
committed
Cross compatibility with the new collections of 2.13
Use distinct implementations of PagedSeq according to the scala version. Use JavaConverters rather than JavaConversions. Use Map#map instead of Map#transform. Use ++= instead of copyToBuffer.
1 parent 5c11019 commit d8512ba

File tree

7 files changed

+30
-6
lines changed

7 files changed

+30
-6
lines changed

build.sbt

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ lazy val `scala-parser-combinators` = crossProject.in(file(".")).
3535
"Scala Parser Combinators",
3636
"-doc-version",
3737
version.value
38-
)
38+
),
39+
unmanagedSourceDirectories in Compile ++= {
40+
(unmanagedSourceDirectories in Compile).value.map { dir =>
41+
CrossVersion.partialVersion(scalaVersion.value) match {
42+
case Some((2, 13)) => file(dir.getPath ++ "-2.13")
43+
case _ => file(dir.getPath ++ "-2.11-2.12")
44+
}
45+
}
46+
}
3947
).
4048
jvmSettings(
4149
// Mima uses the name of the jvm project in the artifactId

jvm/src/test/scala/scala/util/parsing/combinator/t4929.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.util.parsing.json._
22
import java.util.concurrent._
3-
import collection.JavaConversions._
3+
import collection.JavaConverters._
44

55
import org.junit.Test
66

@@ -36,6 +36,6 @@ class t4929 {
3636
thread.setDaemon(true)
3737
thread.start()
3838
}
39-
errors foreach { throw(_) }
39+
errors.asScala foreach { throw(_) }
4040
}
4141
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package scala.util.parsing.input
2+
3+
private[input] trait ScalaVersionSpecificPagedSeq[T] {
4+
// Nothing for 2.11 and 2.12!
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package scala.util.parsing.input
2+
3+
private[input] trait ScalaVersionSpecificPagedSeq[T] { self: PagedSeq[T] =>
4+
// Members declared in scala.collection.Seq
5+
def iterableFactory: collection.SeqFactory[collection.IndexedSeq] = collection.IndexedSeq
6+
7+
// Members declared in scala.collection.IterableOps
8+
protected[this] def fromSpecificIterable(coll: collection.Iterable[T]): collection.IndexedSeq[T] = iterableFactory.from(coll)
9+
protected[this] def newSpecificBuilder(): collection.mutable.Builder[T, collection.IndexedSeq[T]] = iterableFactory.newBuilder()
10+
}

shared/src/main/scala/scala/util/parsing/input/PagedSeq.scala

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class PagedSeq[T: ClassTag] protected(
129129
end: Int)
130130
extends scala.collection.AbstractSeq[T]
131131
with scala.collection.IndexedSeq[T]
132+
with ScalaVersionSpecificPagedSeq[T]
132133
{
133134
def this(more: (Array[T], Int, Int) => Int) = this(more, new Page[T](0), 0, UndeterminedEnd)
134135

shared/src/main/scala/scala/util/parsing/json/JSON.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ object JSON extends Parser {
7373
* arrays. See the `parse` method for details.
7474
*/
7575
def resolveType(input: Any): Any = input match {
76-
case JSONObject(data) => data.transform {
77-
case (k,v) => resolveType(v)
76+
case JSONObject(data) => data.map {
77+
case (k,v) => k -> resolveType(v)
7878
}
7979
case JSONArray(data) => data.map(resolveType)
8080
case x => x

shared/src/test/scala/scala/util/parsing/combinator/UnitTestIO.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UnitTestIO {
2626
val s = "Here is a test string"
2727
val f = io.Source.fromBytes(s.getBytes("utf-8"))
2828
val b = new collection.mutable.ArrayBuffer[Char]()
29-
f.copyToBuffer(b)
29+
b ++= f
3030
assertEquals(new String(b.toArray), s)
3131
}
3232
}

0 commit comments

Comments
 (0)