Skip to content

Move everything into the scala.collection.compat package #31

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

Merged
merged 2 commits into from
May 17, 2018
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
3 changes: 0 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)
}
)
.jvmSettings(
// NOTE: if this setting is not defined, the published jar doesn't contain any classfiles.
// Related to https://github.com/scala/scala-parser-combinators/issues/119.
// TODO: what should the setting be? This library also adds classes to other (existing) packages.
OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}"),
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.collection
package scala.collection.compat

import scala.collection.generic.CanBuildFrom
import scala.collection.{Iterable, mutable}

/** Builds a collection of type `C` from elements of type `A` when a source collection of type `From` is available.
* Implicit instances of `BuildFrom` are available for all collection types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package scala.collection.compat

import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.Builder
import scala.collection.{immutable, mutable}
import scala.collection.{immutable => i, mutable => m}

private[compat] object CompatImpl {
def simpleCBF[A, C](f: => Builder[A, C]): CanBuildFrom[Any, A, C] = new CanBuildFrom[Any, A, C] {
def apply(from: Any): Builder[A, C] = apply()
def apply(): Builder[A, C] = f
}

type ImmutableBitSetCC[X] = ({ type L[_] = immutable.BitSet })#L[X]
type MutableBitSetCC[X] = ({ type L[_] = mutable.BitSet })#L[X]
type ImmutableBitSetCC[X] = ({ type L[_] = i.BitSet })#L[X]
type MutableBitSetCC[X] = ({ type L[_] = m.BitSet })#L[X]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.collection
package scala.collection.compat

import scala.collection.generic.CanBuildFrom
import scala.collection.{TraversableOnce, mutable}

/**
* A factory that builds a collection of type `C` with elements of type `A`.
Expand Down Expand Up @@ -33,4 +34,4 @@ object Factory {
implicit def fromCanBuildFromConversion[X, A, C](x: X)(implicit toCanBuildFrom: X => CanBuildFrom[Nothing, A, C]): Factory[A, C] =
fromCanBuildFrom(toCanBuildFrom(x))

}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package scala
package collection
package immutable
package scala.collection.compat.immutable

import scala.reflect.ClassTag
import scala.runtime.BoxedUnit
import java.util.Arrays

import scala.annotation.unchecked.uncheckedVariance
import scala.collection.AbstractSeq
import scala.collection.generic._
import scala.collection.mutable.{Builder, ArrayBuilder, ArrayBuffer, WrappedArrayBuilder}
import scala.collection.immutable.IndexedSeq
import scala.collection.mutable.{ArrayBuilder, Builder, WrappedArrayBuilder}
import scala.reflect.ClassTag
import scala.util.hashing.MurmurHash3
import scala.annotation.unchecked.uncheckedVariance

import java.util.Arrays

/**
* An immutable array.
Expand Down Expand Up @@ -42,9 +41,6 @@ abstract class ArraySeq[+T]
/** The underlying array */
def unsafeArray: Array[T @uncheckedVariance]

private def elementClass: Class[_] =
unsafeArray.getClass.getComponentType

override def stringPrefix = "ArraySeq"

/** Clones this object, including the underlying Array. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package scala.collection

import scala.collection.generic._
import scala.collection.mutable.Builder
import scala.reflect.ClassTag
import scala.collection.{immutable => i, mutable => m}

/** The collection compatibility API */
package object compat {
Expand All @@ -26,10 +26,10 @@ package object compat {
implicit def bitSetFactoryToCBF(fact: BitSetFactory[BitSet]): CanBuildFrom[Any, Int, BitSet] =
simpleCBF(fact.newBuilder)

implicit def immutableBitSetFactoryToCBF(fact: BitSetFactory[immutable.BitSet]): CanBuildFrom[Any, Int, ImmutableBitSetCC[Int]] =
implicit def immutableBitSetFactoryToCBF(fact: BitSetFactory[i.BitSet]): CanBuildFrom[Any, Int, ImmutableBitSetCC[Int]] =
simpleCBF(fact.newBuilder)

implicit def mutableBitSetFactoryToCBF(fact: BitSetFactory[mutable.BitSet]): CanBuildFrom[Any, Int, MutableBitSetCC[Int]] =
implicit def mutableBitSetFactoryToCBF(fact: BitSetFactory[m.BitSet]): CanBuildFrom[Any, Int, MutableBitSetCC[Int]] =
simpleCBF(fact.newBuilder)

implicit class IterableFactoryExtensionMethods[CC[X] <: GenTraversable[X]](private val fact: GenericCompanion[CC]) {
Expand All @@ -56,4 +56,5 @@ package object compat {

// This really belongs into scala.collection but there's already a package object in scala-library so we can't add to it
type IterableOnce[+X] = TraversableOnce[X]
val IterableOnce = TraversableOnce
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.collection.compat

package object immutable {
type ArraySeq[+T] = scala.collection.immutable.ArraySeq[T]
val ArraySeq = scala.collection.immutable.ArraySeq
}
9 changes: 8 additions & 1 deletion src/main/scala-2.13/scala/collection/compat/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package scala.collection

// Empty dummy package to allow cross-building with Scala 2.12
package object compat {
type Factory[-A, +C] = scala.collection.Factory[A, C]
val Factory = scala.collection.Factory

type BuildFrom[-From, -A, +C] = scala.collection.BuildFrom[From, A, C]
val BuildFrom = scala.collection.BuildFrom

type IterableOnce[+X] = scala.collection.IterableOnce[X]
val IterableOnce = scala.collection.IterableOnce
}
2 changes: 1 addition & 1 deletion src/test/scala/test/scala/collection/ArraySeqTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package test.scala.collection

import org.junit.{Assert, Test}

import scala.collection.immutable.ArraySeq
import scala.collection.compat.immutable.ArraySeq

// The unmodified ArraySeqTest from collection-strawman
class ArraySeqTest {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/test/scala/collection/BuildFromTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.Test
import scala.collection.compat._
import scala.collection.immutable.{HashMap, TreeMap, TreeSet}
import scala.collection.mutable.{ArrayBuffer, Builder, ListBuffer}
import scala.collection.{BitSet, BuildFrom, SortedMap, SortedSet, immutable, mutable}
import scala.collection.{BitSet, SortedMap, SortedSet, immutable, mutable}

// Tests copied from the 2.13 scala-library
class BuildFromTest {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/test/scala/collection/FactoryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test.scala.collection
import org.junit.{Assert, Test}

import scala.collection.compat._
import scala.collection.{BitSet, Factory, immutable, mutable}
import scala.collection.{BitSet, immutable, mutable}

class FactoryTest {

Expand Down