summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/GenTraversableLike.scala9
-rw-r--r--src/library/scala/collection/generic/FromRepr.scala56
-rw-r--r--src/library/scala/collection/generic/package.scala6
-rw-r--r--src/library/scala/concurrent/SyncVar.scala50
-rw-r--r--src/library/scala/reflect/api/ToolBoxes.scala4
-rw-r--r--src/library/scala/reflect/makro/Typers.scala4
-rw-r--r--src/library/scala/util/parsing/combinator/JavaTokenParsers.scala9
7 files changed, 124 insertions, 14 deletions
diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala
index 0d51230623..eaec7a2a76 100644
--- a/src/library/scala/collection/GenTraversableLike.scala
+++ b/src/library/scala/collection/GenTraversableLike.scala
@@ -411,3 +411,12 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with
def stringPrefix: String
}
+
+object GenTraversableLike {
+ /** Manufacture a conversion from collection representation type `Repr` to
+ * its corresponding `GenTraversableLike` given an implicitly available
+ * instance of `FromRepr[Repr]`.
+ * @see [[scala.collection.generic.FromRepr]]
+ */
+ implicit def fromRepr[Repr](implicit fr : FromRepr[Repr]) = fr.hasElem
+}
diff --git a/src/library/scala/collection/generic/FromRepr.scala b/src/library/scala/collection/generic/FromRepr.scala
new file mode 100644
index 0000000000..c08761332c
--- /dev/null
+++ b/src/library/scala/collection/generic/FromRepr.scala
@@ -0,0 +1,56 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.collection
+package generic
+
+/** Type class witnessing that a collection representation type `Repr` has
+ * elements of type `A` and has a conversion to `GenTraversableLike[A, Repr]`.
+ *
+ * This type enables simple enrichment of `GenTraversable`s with extension
+ * methods which can make full use of the mechanics of the Scala collections
+ * framework in their implementation.
+ *
+ * Example usage,
+ * {{{
+ * import scala.collection.generic.{ CanBuildFrom, FromRepr, HasElem }
+ *
+ * class FilterMapImpl[A, Repr](val r : Repr)(implicit hasElem : HasElem[Repr, A]) {
+ * def filterMap[B, That](f : A => Option[B])
+ * (implicit cbf : CanBuildFrom[Repr, B, That]) : That = r.flatMap(f(_).toSeq)
+ * }
+ *
+ * implicit def filterMap[Repr : FromRepr](r : Repr) = new FilterMapImpl(r)
+ *
+ * val l = List(1, 2, 3, 4, 5)
+ * List(1, 2, 3, 4, 5) filterMap (i => if(i % 2 == 0) Some(i) else None)
+ * // == List(2, 4)
+ * }}}
+ *
+ * @author Miles Sabin
+ * @since 2.10
+ */
+trait FromRepr[Repr] {
+ type A
+ val hasElem: HasElem[Repr, A]
+}
+
+object FromRepr {
+ import language.higherKinds
+
+ implicit val stringFromRepr : FromRepr[String] { type A = Char } = new FromRepr[String] {
+ type A = Char
+ val hasElem = implicitly[HasElem[String, Char]]
+ }
+
+ implicit def genTraversableLikeFromRepr[C[_], A0]
+ (implicit hasElem0: HasElem[C[A0], A0]) : FromRepr[C[A0]] { type A = A0 } = new FromRepr[C[A0]] {
+ type A = A0
+ val hasElem = hasElem0
+ }
+}
diff --git a/src/library/scala/collection/generic/package.scala b/src/library/scala/collection/generic/package.scala
index 32006b4bf0..e0351ebae6 100644
--- a/src/library/scala/collection/generic/package.scala
+++ b/src/library/scala/collection/generic/package.scala
@@ -4,6 +4,12 @@ import generic.CanBuildFrom
package object generic {
type CanBuild[-Elem, +To] = CanBuildFrom[Nothing, Elem, To]
+ /** The type of conversions from a collection representation type
+ * `Repr` to its corresponding GenTraversableLike.
+ * @see [[scala.collection.generic.FromRepr]]
+ */
+ type HasElem[Repr, A] = Repr => GenTraversableLike[A, Repr]
+
@deprecated("use ArrayTagTraversableFactory instead", "2.10.0")
type ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] = ArrayTagTraversableFactory[CC]
diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala
index 43f2ec57c0..5a6d95c2ed 100644
--- a/src/library/scala/concurrent/SyncVar.scala
+++ b/src/library/scala/concurrent/SyncVar.scala
@@ -55,19 +55,32 @@ class SyncVar[A] {
def take(): A = synchronized {
try get
- finally unset()
+ finally unsetVal()
}
- // TODO: this method should be private
- def set(x: A): Unit = synchronized {
- isDefined = true
- value = Some(x)
- notifyAll()
+ /** Waits for this SyncVar to become defined at least for
+ * `timeout` milliseconds (possibly more), and takes its
+ * value by first reading and then removing the value from
+ * the SyncVar.
+ *
+ * @param timeout the amount of milliseconds to wait, 0 means forever
+ * @return `None` if variable is undefined after `timeout`, `Some(value)` otherwise
+ */
+ def take(timeout: Long): A = synchronized {
+ try get(timeout).get
+ finally unsetVal()
}
+ // TODO: this method should be private
+ // [Heather] the reason why: it doesn't take into consideration
+ // whether or not the SyncVar is already defined. So, set has been
+ // deprecated in order to eventually be able to make "setting" private
+ @deprecated("Use `put` instead, as `set` is potentionally error-prone", "2.10.0")
+ def set(x: A): Unit = setVal(x)
+
def put(x: A): Unit = synchronized {
while (isDefined) wait()
- set(x)
+ setVal(x)
}
def isSet: Boolean = synchronized {
@@ -75,10 +88,33 @@ class SyncVar[A] {
}
// TODO: this method should be private
+ // [Heather] the reason why: it doesn't take into consideration
+ // whether or not the SyncVar is already defined. So, unset has been
+ // deprecated in order to eventually be able to make "unsetting" private
+ @deprecated("Use `take` instead, as `unset` is potentionally error-prone", "2.10.0")
def unset(): Unit = synchronized {
isDefined = false
value = None
notifyAll()
}
+
+ // `setVal` exists so as to retroactively deprecate `set` without
+ // deprecation warnings where we use `set` internally. The
+ // implementation of `set` was moved to `setVal` to achieve this
+ private def setVal(x: A): Unit = synchronized {
+ isDefined = true
+ value = Some(x)
+ notifyAll()
+ }
+
+ // `unsetVal` exists so as to retroactively deprecate `unset` without
+ // deprecation warnings where we use `unset` internally. The
+ // implementation of `unset` was moved to `unsetVal` to achieve this
+ private def unsetVal(): Unit = synchronized {
+ isDefined = false
+ value = None
+ notifyAll()
+ }
+
}
diff --git a/src/library/scala/reflect/api/ToolBoxes.scala b/src/library/scala/reflect/api/ToolBoxes.scala
index aefd6b511c..15c9fcc403 100644
--- a/src/library/scala/reflect/api/ToolBoxes.scala
+++ b/src/library/scala/reflect/api/ToolBoxes.scala
@@ -59,14 +59,14 @@ trait ToolBoxes { self: Universe =>
* Note that this does not revert the tree to its pre-typer shape.
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
*/
- def resetAllAttrs[T <: Tree](tree: T): T
+ def resetAllAttrs(tree: Tree): Tree
/** Recursively resets locally defined symbols and types in a given tree.
*
* Note that this does not revert the tree to its pre-typer shape.
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
*/
- def resetLocalAttrs[T <: Tree](tree: T): T
+ def resetLocalAttrs(tree: Tree): Tree
/** Compiles and runs a tree using this ToolBox.
*
diff --git a/src/library/scala/reflect/makro/Typers.scala b/src/library/scala/reflect/makro/Typers.scala
index c62c5f254c..90024a4f7a 100644
--- a/src/library/scala/reflect/makro/Typers.scala
+++ b/src/library/scala/reflect/makro/Typers.scala
@@ -66,14 +66,14 @@ trait Typers {
* Note that this does not revert the tree to its pre-typer shape.
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
*/
- def resetAllAttrs[T <: Tree](tree: T): T
+ def resetAllAttrs(tree: Tree): Tree
/** Recursively resets locally defined symbols and types in a given tree.
*
* Note that this does not revert the tree to its pre-typer shape.
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
*/
- def resetLocalAttrs[T <: Tree](tree: T): T
+ def resetLocalAttrs(tree: Tree): Tree
/** Represents an error during typechecking
*/
diff --git a/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala b/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala
index bc71391bdb..06567ea348 100644
--- a/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala
+++ b/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala
@@ -9,6 +9,8 @@
package scala.util.parsing.combinator
+import annotation.migration
+
/** `JavaTokenParsers` differs from [[scala.util.parsing.combinator.RegexParsers]]
* by adding the following definitions:
*
@@ -39,12 +41,13 @@ trait JavaTokenParsers extends RegexParsers {
/** Double quotes (`"`) enclosing a sequence of:
*
* - Any character except double quotes, control characters or backslash (`\`)
- * - A backslash followed by a slash, another backslash, or one of the letters
- * `b`, `f`, `n`, `r` or `t`.
+ * - A backslash followed by another backslash, a single or double quote, or one
+ * of the letters `b`, `f`, `n`, `r` or `t`
* - `\` followed by `u` followed by four hexadecimal digits
*/
+ @migration("`stringLiteral` allows escaping single and double quotes, but not forward slashes any longer.", "2.10.0")
def stringLiteral: Parser[String] =
- ("\""+"""([^"\p{Cntrl}\\]|\\[\\/bfnrt]|\\u[a-fA-F0-9]{4})*"""+"\"").r
+ ("\""+"""([^"\p{Cntrl}\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*"""+"\"").r
/** A number following the rules of `decimalNumber`, with the following
* optional additions:
*