summaryrefslogtreecommitdiff
path: root/examples/scala-js/scalalib
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scala-js/scalalib')
-rw-r--r--examples/scala-js/scalalib/overrides-2.10/scala/Console.scala468
-rw-r--r--examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/NumericRange.scala285
-rw-r--r--examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/Range.scala424
-rw-r--r--examples/scala-js/scalalib/overrides-2.10/scala/collection/mutable/Buffer.scala50
-rw-r--r--examples/scala-js/scalalib/overrides-2.10/scala/compat/Platform.scala133
-rw-r--r--examples/scala-js/scalalib/overrides-2.10/scala/package.scala138
-rw-r--r--examples/scala-js/scalalib/overrides-2.11/scala/Console.scala222
-rw-r--r--examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/NumericRange.scala346
-rw-r--r--examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/Range.scala516
-rw-r--r--examples/scala-js/scalalib/overrides-2.11/scala/collection/mutable/Buffer.scala51
-rw-r--r--examples/scala-js/scalalib/overrides-2.11/scala/compat/Platform.scala132
-rw-r--r--examples/scala-js/scalalib/overrides-2.11/scala/package.scala133
-rw-r--r--examples/scala-js/scalalib/overrides/scala/App.scala83
-rw-r--r--examples/scala-js/scalalib/overrides/scala/Enumeration.scala284
-rw-r--r--examples/scala-js/scalalib/overrides/scala/Symbol.scala117
-rw-r--r--examples/scala-js/scalalib/overrides/scala/concurrent/impl/AbstractPromise.scala29
-rw-r--r--examples/scala-js/scalalib/overrides/scala/math/ScalaNumber.scala21
-rw-r--r--examples/scala-js/scalalib/overrides/scala/runtime/BoxesRunTime.scala124
-rw-r--r--examples/scala-js/scalalib/overrides/scala/util/control/NoStackTrace.scala33
19 files changed, 3589 insertions, 0 deletions
diff --git a/examples/scala-js/scalalib/overrides-2.10/scala/Console.scala b/examples/scala-js/scalalib/overrides-2.10/scala/Console.scala
new file mode 100644
index 0000000..7fc2d50
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.10/scala/Console.scala
@@ -0,0 +1,468 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+
+package scala
+
+import java.io.{BufferedReader, InputStream, InputStreamReader,
+ IOException, OutputStream, PrintStream, Reader}
+import java.text.MessageFormat
+import scala.util.DynamicVariable
+
+
+/** Implements functionality for
+ * printing Scala values on the terminal as well as reading specific values.
+ * Also defines constants for marking up text on ANSI terminals.
+ *
+ * @author Matthias Zenger
+ * @version 1.0, 03/09/2003
+ */
+object Console {
+
+ /** Foreground color for ANSI black */
+ final val BLACK = "\033[30m"
+ /** Foreground color for ANSI red */
+ final val RED = "\033[31m"
+ /** Foreground color for ANSI green */
+ final val GREEN = "\033[32m"
+ /** Foreground color for ANSI yellow */
+ final val YELLOW = "\033[33m"
+ /** Foreground color for ANSI blue */
+ final val BLUE = "\033[34m"
+ /** Foreground color for ANSI magenta */
+ final val MAGENTA = "\033[35m"
+ /** Foreground color for ANSI cyan */
+ final val CYAN = "\033[36m"
+ /** Foreground color for ANSI white */
+ final val WHITE = "\033[37m"
+
+ /** Background color for ANSI black */
+ final val BLACK_B = "\033[40m"
+ /** Background color for ANSI red */
+ final val RED_B = "\033[41m"
+ /** Background color for ANSI green */
+ final val GREEN_B = "\033[42m"
+ /** Background color for ANSI yellow */
+ final val YELLOW_B = "\033[43m"
+ /** Background color for ANSI blue */
+ final val BLUE_B = "\033[44m"
+ /** Background color for ANSI magenta */
+ final val MAGENTA_B = "\033[45m"
+ /** Background color for ANSI cyan */
+ final val CYAN_B = "\033[46m"
+ /** Background color for ANSI white */
+ final val WHITE_B = "\033[47m"
+
+ /** Reset ANSI styles */
+ final val RESET = "\033[0m"
+ /** ANSI bold */
+ final val BOLD = "\033[1m"
+ /** ANSI underlines */
+ final val UNDERLINED = "\033[4m"
+ /** ANSI blink */
+ final val BLINK = "\033[5m"
+ /** ANSI reversed */
+ final val REVERSED = "\033[7m"
+ /** ANSI invisible */
+ final val INVISIBLE = "\033[8m"
+
+ private val outVar = new DynamicVariable[PrintStream](java.lang.System.out)
+ private val errVar = new DynamicVariable[PrintStream](java.lang.System.err)
+ private val inVar = new DynamicVariable[BufferedReader](null)
+ //new BufferedReader(new InputStreamReader(java.lang.System.in)))
+
+ /** The default output, can be overridden by `setOut` */
+ def out = outVar.value
+ /** The default error, can be overridden by `setErr` */
+ def err = errVar.value
+ /** The default input, can be overridden by `setIn` */
+ def in = inVar.value
+
+ /** Sets the default output stream.
+ *
+ * @param out the new output stream.
+ */
+ def setOut(out: PrintStream) { outVar.value = out }
+
+ /** Sets the default output stream for the duration
+ * of execution of one thunk.
+ *
+ * @example {{{
+ * withOut(Console.err) { println("This goes to default _error_") }
+ * }}}
+ *
+ * @param out the new output stream.
+ * @param thunk the code to execute with
+ * the new output stream active
+ * @return the results of `thunk`
+ * @see `withOut[T](out:OutputStream)(thunk: => T)`
+ */
+ def withOut[T](out: PrintStream)(thunk: =>T): T =
+ outVar.withValue(out)(thunk)
+
+ /** Sets the default output stream.
+ *
+ * @param out the new output stream.
+ */
+ def setOut(out: OutputStream): Unit =
+ setOut(new PrintStream(out))
+
+ /** Sets the default output stream for the duration
+ * of execution of one thunk.
+ *
+ * @param out the new output stream.
+ * @param thunk the code to execute with
+ * the new output stream active
+ * @return the results of `thunk`
+ * @see `withOut[T](out:PrintStream)(thunk: => T)`
+ */
+ def withOut[T](out: OutputStream)(thunk: =>T): T =
+ withOut(new PrintStream(out))(thunk)
+
+
+ /** Sets the default error stream.
+ *
+ * @param err the new error stream.
+ */
+ def setErr(err: PrintStream) { errVar.value = err }
+
+ /** Set the default error stream for the duration
+ * of execution of one thunk.
+ * @example {{{
+ * withErr(Console.out) { println("This goes to default _out_") }
+ * }}}
+ *
+ * @param err the new error stream.
+ * @param thunk the code to execute with
+ * the new error stream active
+ * @return the results of `thunk`
+ * @see `withErr[T](err:OutputStream)(thunk: =>T)`
+ */
+ def withErr[T](err: PrintStream)(thunk: =>T): T =
+ errVar.withValue(err)(thunk)
+
+ /** Sets the default error stream.
+ *
+ * @param err the new error stream.
+ */
+ def setErr(err: OutputStream): Unit =
+ setErr(new PrintStream(err))
+
+ /** Sets the default error stream for the duration
+ * of execution of one thunk.
+ *
+ * @param err the new error stream.
+ * @param thunk the code to execute with
+ * the new error stream active
+ * @return the results of `thunk`
+ * @see `withErr[T](err:PrintStream)(thunk: =>T)`
+ */
+ def withErr[T](err: OutputStream)(thunk: =>T): T =
+ withErr(new PrintStream(err))(thunk)
+
+
+ /** Sets the default input stream.
+ *
+ * @param reader specifies the new input stream.
+ */
+ def setIn(reader: Reader) {
+ inVar.value = new BufferedReader(reader)
+ }
+
+ /** Sets the default input stream for the duration
+ * of execution of one thunk.
+ *
+ * @example {{{
+ * val someFile:Reader = openFile("file.txt")
+ * withIn(someFile) {
+ * // Reads a line from file.txt instead of default input
+ * println(readLine)
+ * }
+ * }}}
+ *
+ * @param thunk the code to execute with
+ * the new input stream active
+ *
+ * @return the results of `thunk`
+ * @see `withIn[T](in:InputStream)(thunk: =>T)`
+ */
+ def withIn[T](reader: Reader)(thunk: =>T): T =
+ inVar.withValue(new BufferedReader(reader))(thunk)
+
+ /** Sets the default input stream.
+ *
+ * @param in the new input stream.
+ */
+ def setIn(in: InputStream) {
+ setIn(new InputStreamReader(in))
+ }
+
+ /** Sets the default input stream for the duration
+ * of execution of one thunk.
+ *
+ * @param in the new input stream.
+ * @param thunk the code to execute with
+ * the new input stream active
+ * @return the results of `thunk`
+ * @see `withIn[T](reader:Reader)(thunk: =>T)`
+ */
+ def withIn[T](in: InputStream)(thunk: =>T): T =
+ withIn(new InputStreamReader(in))(thunk)
+
+ /** Prints an object to `out` using its `toString` method.
+ *
+ * @param obj the object to print; may be null.
+ */
+ def print(obj: Any) {
+ out.print(if (null == obj) "null" else obj.toString())
+ }
+
+ /** Flushes the output stream. This function is required when partial
+ * output (i.e. output not terminated by a newline character) has
+ * to be made visible on the terminal.
+ */
+ def flush() { out.flush() }
+
+ /** Prints a newline character on the default output.
+ */
+ def println() { out.println() }
+
+ /** Prints out an object to the default output, followed by a newline character.
+ *
+ * @param x the object to print.
+ */
+ def println(x: Any) { out.println(x) }
+
+ /** Prints its arguments as a formatted string to the default output,
+ * based on a string pattern (in a fashion similar to printf in C).
+ *
+ * The interpretation of the formatting patterns is described in
+ * <a href="" target="contentFrame" class="java/util/Formatter">
+ * `java.util.Formatter`</a>.
+ *
+ * @param text the pattern for formatting the arguments.
+ * @param args the arguments used to instantiating the pattern.
+ * @throws java.lang.IllegalArgumentException if there was a problem with the format string or arguments
+ */
+ def printf(text: String, args: Any*) { out.print(text format (args : _*)) }
+
+ /** Read a full line from the default input. Returns `null` if the end of the
+ * input stream has been reached.
+ *
+ * @return the string read from the terminal or null if the end of stream was reached.
+ */
+ def readLine(): String = in.readLine()
+
+ /** Print formatted text to the default output and read a full line from the default input.
+ * Returns `null` if the end of the input stream has been reached.
+ *
+ * @param text the format of the text to print out, as in `printf`.
+ * @param args the parameters used to instantiate the format, as in `printf`.
+ * @return the string read from the default input
+ */
+ def readLine(text: String, args: Any*): String = {
+ printf(text, args: _*)
+ readLine()
+ }
+
+ /** Reads a boolean value from an entire line of the default input.
+ * Has a fairly liberal interpretation of the input.
+ *
+ * @return the boolean value read, or false if it couldn't be converted to a boolean
+ * @throws java.io.EOFException if the end of the input stream has been reached.
+ */
+ def readBoolean(): Boolean = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toLowerCase() match {
+ case "true" => true
+ case "t" => true
+ case "yes" => true
+ case "y" => true
+ case _ => false
+ }
+ }
+
+ /** Reads a byte value from an entire line of the default input.
+ *
+ * @return the Byte that was read
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.NumberFormatException if the value couldn't be converted to a Byte
+ */
+ def readByte(): Byte = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toByte
+ }
+
+ /** Reads a short value from an entire line of the default input.
+ *
+ * @return the short that was read
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.NumberFormatException if the value couldn't be converted to a Short
+ */
+ def readShort(): Short = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toShort
+ }
+
+ /** Reads a char value from an entire line of the default input.
+ *
+ * @return the Char that was read
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.StringIndexOutOfBoundsException if the line read from default input was empty
+ */
+ def readChar(): Char = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s charAt 0
+ }
+
+ /** Reads an int value from an entire line of the default input.
+ *
+ * @return the Int that was read
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.NumberFormatException if the value couldn't be converted to an Int
+ */
+ def readInt(): Int = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toInt
+ }
+
+ /** Reads an long value from an entire line of the default input.
+ *
+ * @return the Long that was read
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.NumberFormatException if the value couldn't be converted to a Long
+ */
+ def readLong(): Long = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toLong
+ }
+
+ /** Reads a float value from an entire line of the default input.
+ * @return the Float that was read.
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.NumberFormatException if the value couldn't be converted to a Float
+ *
+ */
+ def readFloat(): Float = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toFloat
+ }
+
+ /** Reads a double value from an entire line of the default input.
+ *
+ * @return the Double that was read.
+ * @throws java.io.EOFException if the end of the
+ * input stream has been reached.
+ * @throws java.lang.NumberFormatException if the value couldn't be converted to a Float
+ */
+ def readDouble(): Double = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ s.toDouble
+ }
+
+ /** Reads in some structured input (from the default input), specified by
+ * a format specifier. See class `java.text.MessageFormat` for details of
+ * the format specification.
+ *
+ * @param format the format of the input.
+ * @return a list of all extracted values.
+ * @throws java.io.EOFException if the end of the input stream has been
+ * reached.
+ */
+ def readf(format: String): List[Any] = {
+ val s = readLine()
+ if (s == null)
+ throw new java.io.EOFException("Console has reached end of input")
+ else
+ textComponents(new MessageFormat(format).parse(s))
+ }
+
+ /** Reads in some structured input (from the default input), specified by
+ * a format specifier, returning only the first value extracted, according
+ * to the format specification.
+ *
+ * @param format format string, as accepted by `readf`.
+ * @return The first value that was extracted from the input
+ */
+ def readf1(format: String): Any = readf(format).head
+
+ /** Reads in some structured input (from the default input), specified
+ * by a format specifier, returning only the first two values extracted,
+ * according to the format specification.
+ *
+ * @param format format string, as accepted by `readf`.
+ * @return A [[scala.Tuple2]] containing the first two values extracted
+ */
+ def readf2(format: String): (Any, Any) = {
+ val res = readf(format)
+ (res.head, res.tail.head)
+ }
+
+ /** Reads in some structured input (from the default input), specified
+ * by a format specifier, returning only the first three values extracted,
+ * according to the format specification.
+ *
+ * @param format format string, as accepted by `readf`.
+ * @return A [[scala.Tuple3]] containing the first three values extracted
+ */
+ def readf3(format: String): (Any, Any, Any) = {
+ val res = readf(format)
+ (res.head, res.tail.head, res.tail.tail.head)
+ }
+
+ private def textComponents(a: Array[AnyRef]): List[Any] = {
+ var i: Int = a.length - 1
+ var res: List[Any] = Nil
+ while (i >= 0) {
+ res = (a(i) match {
+ case x: java.lang.Boolean => x.booleanValue()
+ case x: java.lang.Byte => x.byteValue()
+ case x: java.lang.Short => x.shortValue()
+ case x: java.lang.Character => x.charValue()
+ case x: java.lang.Integer => x.intValue()
+ case x: java.lang.Long => x.longValue()
+ case x: java.lang.Float => x.floatValue()
+ case x: java.lang.Double => x.doubleValue()
+ case x => x
+ }) :: res;
+ i -= 1
+ }
+ res
+ }
+}
diff --git a/examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/NumericRange.scala b/examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/NumericRange.scala
new file mode 100644
index 0000000..d3971ee
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/NumericRange.scala
@@ -0,0 +1,285 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+package scala.collection
+package immutable
+
+import mutable.{ Builder, ListBuffer }
+import generic._
+
+/** `NumericRange` is a more generic version of the
+ * `Range` class which works with arbitrary types.
+ * It must be supplied with an `Integral` implementation of the
+ * range type.
+ *
+ * Factories for likely types include `Range.BigInt`, `Range.Long`,
+ * and `Range.BigDecimal`. `Range.Int` exists for completeness, but
+ * the `Int`-based `scala.Range` should be more performant.
+ *
+ * {{{
+ * val r1 = new Range(0, 100, 1)
+ * val veryBig = Int.MaxValue.toLong + 1
+ * val r2 = Range.Long(veryBig, veryBig + 100, 1)
+ * assert(r1 sameElements r2.map(_ - veryBig))
+ * }}}
+ *
+ * TODO: Now the specialization exists there is no clear reason to have
+ * separate classes for Range/NumericRange. Investigate and consolidate.
+ *
+ * @author Paul Phillips
+ * @version 2.8
+ * @define Coll `NumericRange`
+ * @define coll numeric range
+ * @define mayNotTerminateInf
+ * @define willNotTerminateInf
+ */
+abstract class NumericRange[T]
+ (val start: T, val end: T, val step: T, val isInclusive: Boolean)
+ (implicit num: Integral[T])
+extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
+ /** Note that NumericRange must be invariant so that constructs
+ * such as "1L to 10 by 5" do not infer the range type as AnyVal.
+ */
+ import num._
+
+ // See comment in Range for why this must be lazy.
+ private lazy val numRangeElements: Int =
+ NumericRange.count(start, end, step, isInclusive)
+
+ override def length = numRangeElements
+ override def isEmpty = length == 0
+ override lazy val last: T =
+ if (length == 0) Nil.last
+ else locationAfterN(length - 1)
+
+ /** Create a new range with the start and end values of this range and
+ * a new `step`.
+ */
+ def by(newStep: T): NumericRange[T] = copy(start, end, newStep)
+
+ /** Create a copy of this range.
+ */
+ def copy(start: T, end: T, step: T): NumericRange[T]
+
+ override def foreach[U](f: T => U) {
+ var count = 0
+ var current = start
+ while (count < length) {
+ f(current)
+ current += step
+ count += 1
+ }
+ }
+
+ // TODO: these private methods are straight copies from Range, duplicated
+ // to guard against any (most likely illusory) performance drop. They should
+ // be eliminated one way or another.
+
+ // Counts how many elements from the start meet the given test.
+ private def skipCount(p: T => Boolean): Int = {
+ var current = start
+ var counted = 0
+
+ while (counted < length && p(current)) {
+ counted += 1
+ current += step
+ }
+ counted
+ }
+ // Tests whether a number is within the endpoints, without testing
+ // whether it is a member of the sequence (i.e. when step > 1.)
+ private def isWithinBoundaries(elem: T) = !isEmpty && (
+ (step > zero && start <= elem && elem <= last ) ||
+ (step < zero && last <= elem && elem <= start)
+ )
+ // Methods like apply throw exceptions on invalid n, but methods like take/drop
+ // are forgiving: therefore the checks are with the methods.
+ private def locationAfterN(n: Int): T = start + (step * fromInt(n))
+
+ // When one drops everything. Can't ever have unchecked operations
+ // like "end + 1" or "end - 1" because ranges involving Int.{ MinValue, MaxValue }
+ // will overflow. This creates an exclusive range where start == end
+ // based on the given value.
+ private def newEmptyRange(value: T) = NumericRange(value, value, step)
+
+ final override def take(n: Int): NumericRange[T] = (
+ if (n <= 0 || length == 0) newEmptyRange(start)
+ else if (n >= length) this
+ else new NumericRange.Inclusive(start, locationAfterN(n - 1), step)
+ )
+
+ final override def drop(n: Int): NumericRange[T] = (
+ if (n <= 0 || length == 0) this
+ else if (n >= length) newEmptyRange(end)
+ else copy(locationAfterN(n), end, step)
+ )
+
+ def apply(idx: Int): T = {
+ if (idx < 0 || idx >= length) throw new IndexOutOfBoundsException(idx.toString)
+ else locationAfterN(idx)
+ }
+
+ import NumericRange.defaultOrdering
+
+ override def min[T1 >: T](implicit ord: Ordering[T1]): T =
+ if (ord eq defaultOrdering(num)) {
+ if (num.signum(step) > 0) start
+ else last
+ } else super.min(ord)
+
+ override def max[T1 >: T](implicit ord: Ordering[T1]): T =
+ if (ord eq defaultOrdering(num)) {
+ if (num.signum(step) > 0) last
+ else start
+ } else super.max(ord)
+
+ // Motivated by the desire for Double ranges with BigDecimal precision,
+ // we need some way to map a Range and get another Range. This can't be
+ // done in any fully general way because Ranges are not arbitrary
+ // sequences but step-valued, so we have a custom method only we can call
+ // which we promise to use responsibly.
+ //
+ // The point of it all is that
+ //
+ // 0.0 to 1.0 by 0.1
+ //
+ // should result in
+ //
+ // NumericRange[Double](0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)
+ //
+ // and not
+ //
+ // NumericRange[Double](0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9)
+ //
+ // or perhaps more importantly,
+ //
+ // (0.1 to 0.3 by 0.1 contains 0.3) == true
+ //
+ private[immutable] def mapRange[A](fm: T => A)(implicit unum: Integral[A]): NumericRange[A] = {
+ val self = this
+
+ // XXX This may be incomplete.
+ new NumericRange[A](fm(start), fm(end), fm(step), isInclusive) {
+ def copy(start: A, end: A, step: A): NumericRange[A] =
+ if (isInclusive) NumericRange.inclusive(start, end, step)
+ else NumericRange(start, end, step)
+
+ private lazy val underlyingRange: NumericRange[T] = self
+ override def foreach[U](f: A => U) { underlyingRange foreach (x => f(fm(x))) }
+ override def isEmpty = underlyingRange.isEmpty
+ override def apply(idx: Int): A = fm(underlyingRange(idx))
+ override def containsTyped(el: A) = underlyingRange exists (x => fm(x) == el)
+ }
+ }
+
+ // a well-typed contains method.
+ def containsTyped(x: T): Boolean =
+ isWithinBoundaries(x) && (((x - start) % step) == zero)
+
+ override def contains(x: Any): Boolean =
+ try containsTyped(x.asInstanceOf[T])
+ catch { case _: ClassCastException => false }
+
+ final override def sum[B >: T](implicit num: Numeric[B]): B = {
+ import num.Ops
+ if (isEmpty) this.num fromInt 0
+ else if (numRangeElements == 1) head
+ else ((this.num fromInt numRangeElements) * (head + last) / (this.num fromInt 2))
+ }
+
+ override lazy val hashCode = super.hashCode()
+ override def equals(other: Any) = other match {
+ case x: NumericRange[_] =>
+ (x canEqual this) && (length == x.length) && (
+ (length == 0) || // all empty sequences are equal
+ (start == x.start && last == x.last) // same length and same endpoints implies equality
+ )
+ case _ =>
+ super.equals(other)
+ }
+
+ override def toString() = {
+ val endStr = if (length > Range.MAX_PRINT) ", ... )" else ")"
+ take(Range.MAX_PRINT).mkString("NumericRange(", ", ", endStr)
+ }
+}
+
+/** A companion object for numeric ranges.
+ */
+object NumericRange {
+
+ /** Calculates the number of elements in a range given start, end, step, and
+ * whether or not it is inclusive. Throws an exception if step == 0 or
+ * the number of elements exceeds the maximum Int.
+ */
+ def count[T](start: T, end: T, step: T, isInclusive: Boolean)(implicit num: Integral[T]): Int = {
+ val zero = num.zero
+ val upward = num.lt(start, end)
+ val posStep = num.gt(step, zero)
+
+ if (step == zero) throw new IllegalArgumentException("step cannot be 0.")
+ else if (start == end) if (isInclusive) 1 else 0
+ else if (upward != posStep) 0
+ else {
+ val diff = num.minus(end, start)
+ val jumps = num.toLong(num.quot(diff, step))
+ val remainder = num.rem(diff, step)
+ val longCount = jumps + (
+ if (!isInclusive && zero == remainder) 0 else 1
+ )
+
+ /** The edge cases keep coming. Since e.g.
+ * Long.MaxValue + 1 == Long.MinValue
+ * we do some more improbable seeming checks lest
+ * overflow turn up as an empty range.
+ */
+ // The second condition contradicts an empty result.
+ val isOverflow = longCount == 0 && num.lt(num.plus(start, step), end) == upward
+
+ if (longCount > scala.Int.MaxValue || longCount < 0L || isOverflow) {
+ val word = if (isInclusive) "to" else "until"
+ val descr = List(start, word, end, "by", step) mkString " "
+
+ throw new IllegalArgumentException(descr + ": seqs cannot contain more than Int.MaxValue elements.")
+ }
+ longCount.toInt
+ }
+ }
+
+ class Inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T])
+ extends NumericRange(start, end, step, true) {
+ def copy(start: T, end: T, step: T): Inclusive[T] =
+ NumericRange.inclusive(start, end, step)
+
+ def exclusive: Exclusive[T] = NumericRange(start, end, step)
+ }
+
+ class Exclusive[T](start: T, end: T, step: T)(implicit num: Integral[T])
+ extends NumericRange(start, end, step, false) {
+ def copy(start: T, end: T, step: T): Exclusive[T] =
+ NumericRange(start, end, step)
+
+ def inclusive: Inclusive[T] = NumericRange.inclusive(start, end, step)
+ }
+
+ def apply[T](start: T, end: T, step: T)(implicit num: Integral[T]): Exclusive[T] =
+ new Exclusive(start, end, step)
+ def inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T]): Inclusive[T] =
+ new Inclusive(start, end, step)
+
+ private[collection] val defaultOrdering = Map[Numeric[_], Ordering[_]](
+ Numeric.IntIsIntegral -> Ordering.Int,
+ Numeric.ShortIsIntegral -> Ordering.Short,
+ Numeric.ByteIsIntegral -> Ordering.Byte,
+ Numeric.CharIsIntegral -> Ordering.Char,
+ Numeric.LongIsIntegral -> Ordering.Long
+ )
+
+}
+
diff --git a/examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/Range.scala b/examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/Range.scala
new file mode 100644
index 0000000..5c8758d
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.10/scala/collection/immutable/Range.scala
@@ -0,0 +1,424 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+package scala.collection.immutable
+
+import scala.collection.parallel.immutable.ParRange
+
+/** The `Range` class represents integer values in range
+ * ''[start;end)'' with non-zero step value `step`.
+ * It's a special case of an indexed sequence.
+ * For example:
+ *
+ * {{{
+ * val r1 = 0 until 10
+ * val r2 = r1.start until r1.end by r1.step + 1
+ * println(r2.length) // = 5
+ * }}}
+ *
+ * @param start the start of this range.
+ * @param end the exclusive end of the range.
+ * @param step the step for the range.
+ *
+ * @author Martin Odersky
+ * @author Paul Phillips
+ * @version 2.8
+ * @since 2.5
+ * @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#ranges "Scala's Collection Library overview"]]
+ * section on `Ranges` for more information.
+ *
+ * @define coll range
+ * @define mayNotTerminateInf
+ * @define willNotTerminateInf
+ * @define doesNotUseBuilders
+ * '''Note:''' this method does not use builders to construct a new range,
+ * and its complexity is O(1).
+ */
+@SerialVersionUID(7618862778670199309L)
+@inline
+class Range(val start: Int, val end: Int, val step: Int)
+extends scala.collection.AbstractSeq[Int]
+ with IndexedSeq[Int]
+ with scala.collection.CustomParallelizable[Int, ParRange]
+ with Serializable
+{
+ override def par = new ParRange(this)
+
+ private def gap = end.toLong - start.toLong
+ private def isExact = gap % step == 0
+ private def hasStub = isInclusive || !isExact
+ private def longLength = gap / step + ( if (hasStub) 1 else 0 )
+
+ // Check cannot be evaluated eagerly because we have a pattern where
+ // ranges are constructed like: "x to y by z" The "x to y" piece
+ // should not trigger an exception. So the calculation is delayed,
+ // which means it will not fail fast for those cases where failing was
+ // correct.
+ override final val isEmpty = (
+ (start > end && step > 0)
+ || (start < end && step < 0)
+ || (start == end && !isInclusive)
+ )
+ final val numRangeElements: Int = {
+ if (step == 0) throw new IllegalArgumentException("step cannot be 0.")
+ else if (isEmpty) 0
+ else {
+ val len = longLength
+ if (len > scala.Int.MaxValue) -1
+ else len.toInt
+ }
+ }
+ final val lastElement = start + (numRangeElements - 1) * step
+ final val terminalElement = start + numRangeElements * step
+
+ override def last = if (isEmpty) Nil.last else lastElement
+
+ override def min[A1 >: Int](implicit ord: Ordering[A1]): Int =
+ if (ord eq Ordering.Int) {
+ if (step > 0) start
+ else last
+ } else super.min(ord)
+
+ override def max[A1 >: Int](implicit ord: Ordering[A1]): Int =
+ if (ord eq Ordering.Int) {
+ if (step > 0) last
+ else start
+ } else super.max(ord)
+
+ protected def copy(start: Int, end: Int, step: Int): Range = new Range(start, end, step)
+
+ /** Create a new range with the `start` and `end` values of this range and
+ * a new `step`.
+ *
+ * @return a new range with a different step
+ */
+ def by(step: Int): Range = copy(start, end, step)
+
+ def isInclusive = false
+
+ override def size = length
+ override def length = if (numRangeElements < 0) fail() else numRangeElements
+
+ private def fail() = Range.fail(start, end, step, isInclusive)
+ private def validateMaxLength() {
+ if (numRangeElements < 0)
+ fail()
+ }
+
+ def validateRangeBoundaries(f: Int => Any): Boolean = {
+ validateMaxLength()
+
+ start != Int.MinValue || end != Int.MinValue || {
+ var count = 0
+ var num = start
+ while (count < numRangeElements) {
+ f(num)
+ count += 1
+ num += step
+ }
+ false
+ }
+ }
+
+ final def apply(idx: Int): Int = {
+ validateMaxLength()
+ if (idx < 0 || idx >= numRangeElements) throw new IndexOutOfBoundsException(idx.toString)
+ else start + (step * idx)
+ }
+
+ @inline final override def foreach[@specialized(Unit) U](f: Int => U) {
+ validateMaxLength()
+ val isCommonCase = (start != Int.MinValue || end != Int.MinValue)
+ var i = start
+ var count = 0
+ val terminal = terminalElement
+ val step = this.step
+ while(
+ if(isCommonCase) { i != terminal }
+ else { count < numRangeElements }
+ ) {
+ f(i)
+ count += 1
+ i += step
+ }
+ }
+
+ /** Creates a new range containing the first `n` elements of this range.
+ *
+ * $doesNotUseBuilders
+ *
+ * @param n the number of elements to take.
+ * @return a new range consisting of `n` first elements.
+ */
+ final override def take(n: Int): Range = (
+ if (n <= 0 || isEmpty) newEmptyRange(start)
+ else if (n >= numRangeElements) this
+ else new Range.Inclusive(start, locationAfterN(n - 1), step)
+ )
+
+ /** Creates a new range containing all the elements of this range except the first `n` elements.
+ *
+ * $doesNotUseBuilders
+ *
+ * @param n the number of elements to drop.
+ * @return a new range consisting of all the elements of this range except `n` first elements.
+ */
+ final override def drop(n: Int): Range = (
+ if (n <= 0 || isEmpty) this
+ else if (n >= numRangeElements) newEmptyRange(end)
+ else copy(locationAfterN(n), end, step)
+ )
+
+ /** Creates a new range containing all the elements of this range except the last one.
+ *
+ * $doesNotUseBuilders
+ *
+ * @return a new range consisting of all the elements of this range except the last one.
+ */
+ final override def init: Range = {
+ if (isEmpty)
+ Nil.init
+
+ dropRight(1)
+ }
+
+ /** Creates a new range containing all the elements of this range except the first one.
+ *
+ * $doesNotUseBuilders
+ *
+ * @return a new range consisting of all the elements of this range except the first one.
+ */
+ final override def tail: Range = {
+ if (isEmpty)
+ Nil.tail
+
+ drop(1)
+ }
+
+ // Counts how many elements from the start meet the given test.
+ private def skipCount(p: Int => Boolean): Int = {
+ var current = start
+ var counted = 0
+
+ while (counted < numRangeElements && p(current)) {
+ counted += 1
+ current += step
+ }
+ counted
+ }
+ // Tests whether a number is within the endpoints, without testing
+ // whether it is a member of the sequence (i.e. when step > 1.)
+ private def isWithinBoundaries(elem: Int) = !isEmpty && (
+ (step > 0 && start <= elem && elem <= last ) ||
+ (step < 0 && last <= elem && elem <= start)
+ )
+ // Methods like apply throw exceptions on invalid n, but methods like take/drop
+ // are forgiving: therefore the checks are with the methods.
+ private def locationAfterN(n: Int) = start + (step * n)
+
+ // When one drops everything. Can't ever have unchecked operations
+ // like "end + 1" or "end - 1" because ranges involving Int.{ MinValue, MaxValue }
+ // will overflow. This creates an exclusive range where start == end
+ // based on the given value.
+ private def newEmptyRange(value: Int) = new Range(value, value, step)
+
+ final override def takeWhile(p: Int => Boolean): Range = take(skipCount(p))
+ final override def dropWhile(p: Int => Boolean): Range = drop(skipCount(p))
+ final override def span(p: Int => Boolean): (Range, Range) = splitAt(skipCount(p))
+
+ /** Creates a pair of new ranges, first consisting of elements before `n`, and the second
+ * of elements after `n`.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def splitAt(n: Int) = (take(n), drop(n))
+
+ /** Creates a new range consisting of the `length - n` last elements of the range.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def takeRight(n: Int): Range = drop(numRangeElements - n)
+
+ /** Creates a new range consisting of the initial `length - n` elements of the range.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def dropRight(n: Int): Range = take(numRangeElements - n)
+
+ /** Returns the reverse of this range.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def reverse: Range =
+ if (isEmpty) this
+ else new Range.Inclusive(last, start, -step)
+
+ /** Make range inclusive.
+ */
+ def inclusive =
+ if (isInclusive) this
+ else new Range.Inclusive(start, end, step)
+
+ final def contains(x: Int) = isWithinBoundaries(x) && ((x - start) % step == 0)
+
+ final override def sum[B >: Int](implicit num: Numeric[B]): Int = {
+ if (isEmpty) 0
+ else if (numRangeElements == 1) head
+ else (numRangeElements.toLong * (head + last) / 2).toInt
+ }
+
+ override def toIterable = this
+
+ override def toSeq = this
+
+ override def equals(other: Any) = other match {
+ case x: Range =>
+ (x canEqual this) && (length == x.length) && (
+ isEmpty || // all empty sequences are equal
+ (start == x.start && last == x.last) // same length and same endpoints implies equality
+ )
+ case _ =>
+ super.equals(other)
+ }
+ /** Note: hashCode can't be overridden without breaking Seq's
+ * equals contract.
+ */
+
+ override def toString() = {
+ val endStr = if (numRangeElements > Range.MAX_PRINT) ", ... )" else ")"
+ take(Range.MAX_PRINT).mkString("Range(", ", ", endStr)
+ }
+}
+
+/** A companion object for the `Range` class.
+ */
+object Range {
+ private[immutable] val MAX_PRINT = 512 // some arbitrary value
+
+ private def description(start: Int, end: Int, step: Int, isInclusive: Boolean) =
+ "%d %s %d by %s".format(start, if (isInclusive) "to" else "until", end, step)
+
+ private def fail(start: Int, end: Int, step: Int, isInclusive: Boolean) =
+ throw new IllegalArgumentException(description(start, end, step, isInclusive) +
+ ": seqs cannot contain more than Int.MaxValue elements.")
+
+ /** Counts the number of range elements.
+ * @pre step != 0
+ * If the size of the range exceeds Int.MaxValue, the
+ * result will be negative.
+ */
+ def count(start: Int, end: Int, step: Int, isInclusive: Boolean): Int = {
+ if (step == 0)
+ throw new IllegalArgumentException("step cannot be 0.")
+
+ val isEmpty = (
+ if (start == end) !isInclusive
+ else if (start < end) step < 0
+ else step > 0
+ )
+ if (isEmpty) 0
+ else {
+ // Counts with Longs so we can recognize too-large ranges.
+ val gap: Long = end.toLong - start.toLong
+ val jumps: Long = gap / step
+ // Whether the size of this range is one larger than the
+ // number of full-sized jumps.
+ val hasStub = isInclusive || (gap % step != 0)
+ val result: Long = jumps + ( if (hasStub) 1 else 0 )
+
+ if (result > scala.Int.MaxValue) -1
+ else result.toInt
+ }
+ }
+ def count(start: Int, end: Int, step: Int): Int =
+ count(start, end, step, false)
+
+ @inline
+ class Inclusive(start: Int, end: Int, step: Int) extends Range(start, end, step) {
+// override def par = new ParRange(this)
+ override def isInclusive = true
+ override protected def copy(start: Int, end: Int, step: Int): Range = new Inclusive(start, end, step)
+ }
+
+ /** Make a range from `start` until `end` (exclusive) with given step value.
+ * @note step != 0
+ */
+ def apply(start: Int, end: Int, step: Int): Range = new Range(start, end, step)
+
+ /** Make a range from `start` until `end` (exclusive) with step value 1.
+ */
+ def apply(start: Int, end: Int): Range = new Range(start, end, 1)
+
+ /** Make an inclusive range from `start` to `end` with given step value.
+ * @note step != 0
+ */
+ def inclusive(start: Int, end: Int, step: Int): Range.Inclusive = new Inclusive(start, end, step)
+
+ /** Make an inclusive range from `start` to `end` with step value 1.
+ */
+ def inclusive(start: Int, end: Int): Range.Inclusive = new Inclusive(start, end, 1)
+
+ // BigInt and Long are straightforward generic ranges.
+ object BigInt {
+ def apply(start: BigInt, end: BigInt, step: BigInt) = NumericRange(start, end, step)
+ def inclusive(start: BigInt, end: BigInt, step: BigInt) = NumericRange.inclusive(start, end, step)
+ }
+
+ object Long {
+ def apply(start: Long, end: Long, step: Long) = NumericRange(start, end, step)
+ def inclusive(start: Long, end: Long, step: Long) = NumericRange.inclusive(start, end, step)
+ }
+
+ // BigDecimal uses an alternative implementation of Numeric in which
+ // it pretends to be Integral[T] instead of Fractional[T]. See Numeric for
+ // details. The intention is for it to throw an exception anytime
+ // imprecision or surprises might result from anything, although this may
+ // not yet be fully implemented.
+ object BigDecimal {
+ implicit val bigDecAsIntegral = scala.math.Numeric.BigDecimalAsIfIntegral
+
+ def apply(start: BigDecimal, end: BigDecimal, step: BigDecimal) =
+ NumericRange(start, end, step)
+ def inclusive(start: BigDecimal, end: BigDecimal, step: BigDecimal) =
+ NumericRange.inclusive(start, end, step)
+ }
+
+ // Double works by using a BigDecimal under the hood for precise
+ // stepping, but mapping the sequence values back to doubles with
+ // .doubleValue. This constructs the BigDecimals by way of the
+ // String constructor (valueOf) instead of the Double one, which
+ // is necessary to keep 0.3d at 0.3 as opposed to
+ // 0.299999999999999988897769753748434595763683319091796875 or so.
+ object Double {
+ implicit val bigDecAsIntegral = scala.math.Numeric.BigDecimalAsIfIntegral
+ implicit val doubleAsIntegral = scala.math.Numeric.DoubleAsIfIntegral
+ def toBD(x: Double): BigDecimal = scala.math.BigDecimal valueOf x
+
+ def apply(start: Double, end: Double, step: Double) =
+ BigDecimal(toBD(start), toBD(end), toBD(step)) mapRange (_.doubleValue)
+
+ def inclusive(start: Double, end: Double, step: Double) =
+ BigDecimal.inclusive(toBD(start), toBD(end), toBD(step)) mapRange (_.doubleValue)
+ }
+
+ // As there is no appealing default step size for not-really-integral ranges,
+ // we offer a partially constructed object.
+ class Partial[T, U](f: T => U) {
+ def by(x: T): U = f(x)
+ }
+
+ // Illustrating genericity with Int Range, which should have the same behavior
+ // as the original Range class. However we leave the original Range
+ // indefinitely, for performance and because the compiler seems to bootstrap
+ // off it and won't do so with our parameterized version without modifications.
+ object Int {
+ def apply(start: Int, end: Int, step: Int) = NumericRange(start, end, step)
+ def inclusive(start: Int, end: Int, step: Int) = NumericRange.inclusive(start, end, step)
+ }
+}
diff --git a/examples/scala-js/scalalib/overrides-2.10/scala/collection/mutable/Buffer.scala b/examples/scala-js/scalalib/overrides-2.10/scala/collection/mutable/Buffer.scala
new file mode 100644
index 0000000..ec7763b
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.10/scala/collection/mutable/Buffer.scala
@@ -0,0 +1,50 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+
+package scala.collection
+package mutable
+
+import generic._
+
+import scala.scalajs.js
+
+/** Buffers are used to create sequences of elements incrementally by
+ * appending, prepending, or inserting new elements. It is also
+ * possible to access and modify elements in a random access fashion
+ * via the index of the element in the current sequence.
+ *
+ * @author Matthias Zenger
+ * @author Martin Odersky
+ * @version 2.8
+ * @since 1
+ *
+ * @tparam A type of the elements contained in this buffer.
+ *
+ * @define Coll `Buffer`
+ * @define coll buffer
+ */
+trait Buffer[A] extends Seq[A]
+ with GenericTraversableTemplate[A, Buffer]
+ with BufferLike[A, Buffer[A]]
+ with scala.Cloneable {
+ override def companion: GenericCompanion[Buffer] = Buffer
+}
+
+/** $factoryInfo
+ * @define coll buffer
+ * @define Coll `Buffer`
+ */
+object Buffer extends SeqFactory[Buffer] {
+ implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Buffer[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
+ def newBuilder[A]: Builder[A, Buffer[A]] = new js.WrappedArray
+}
+
+/** Explicit instantiation of the `Buffer` trait to reduce class file size in subclasses. */
+private[scala] abstract class AbstractBuffer[A] extends AbstractSeq[A] with Buffer[A]
diff --git a/examples/scala-js/scalalib/overrides-2.10/scala/compat/Platform.scala b/examples/scala-js/scalalib/overrides-2.10/scala/compat/Platform.scala
new file mode 100644
index 0000000..77bf7de
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.10/scala/compat/Platform.scala
@@ -0,0 +1,133 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+
+package scala.compat
+
+import java.lang.System
+
+object Platform {
+
+ /** Thrown when a stack overflow occurs because a method or function recurses too deeply.
+ *
+ * On the JVM, this is a type alias for `java.lang.StackOverflowError`, which itself extends `java.lang.Error`.
+ * The same rules apply to catching a `java.lang.Error` as for Java, that it indicates a serious problem that a reasonable application should not try and catch.
+ */
+ type StackOverflowError = java.lang.StackOverflowError
+
+ /** This is a type alias for `java.util.ConcurrentModificationException`,
+ * which may be thrown by methods that detect an invalid modification of an object.
+ * For example, many common collection types do not allow modifying a collection
+ * while it is being iterated over.
+ */
+ type ConcurrentModificationException = java.util.ConcurrentModificationException
+
+ /** Copies `length` elements of array `src` starting at position `srcPos` to the
+ * array `dest` starting at position `destPos`. If `src`==`dest`, the copying will
+ * behave as if the elements copied from `src` were first copied to a temporary
+ * array before being copied back into the array at the destination positions.
+ *
+ * @param src A non-null array as source for the copy.
+ * @param srcPos The starting index in the source array.
+ * @param dest A non-null array as destination for the copy.
+ * @param destPos The starting index in the destination array.
+ * @param length The number of elements to be copied.
+ * @throws java.lang.NullPointerException If either `src` or `dest` are `null`.
+ * @throws java.lang.ArrayStoreException If either `src` or `dest` are not of type
+ * [java.lang.Array]; or if the element type of `src` is not
+ * compatible with that of `dest`.
+ * @throws java.lang.IndexOutOfBoundsException If either srcPos` or `destPos` are
+ * outside of the bounds of their respective arrays; or if `length`
+ * is negative; or if there are less than `length` elements available
+ * after `srcPos` or `destPos` in `src` and `dest` respectively.
+ */
+ @inline
+ def arraycopy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int) {
+ System.arraycopy(src, srcPos, dest, destPos, length)
+ }
+
+ /** Creates a new array of the specified type and given length.
+ *
+ * Note that if `elemClass` is a subclass of [[scala.AnyVal]] then the returned value is an Array of the corresponding java primitive type.
+ * For example, the following code `scala.compat.Platform.createArray(classOf[Int], 4)` returns an array of the java primitive type `int`.
+ *
+ * For a [[scala.AnyVal]] array, the values of the array are set to 0 for ''numeric value types'' ([[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]],
+ * [[scala.Short]], and [[scala.Byte]]), and `false` for [[scala.Boolean]]. Creation of an array of type [[scala.Unit]] is not possible.
+ *
+ * For subclasses of [[scala.AnyRef]], the values of the array are set to `null`.
+ *
+ * The caller must cast the returned value to the correct type.
+ *
+ * @example {{{
+ * val a = scala.compat.Platform.createArray(classOf[Int], 4).asInstanceOf[Array[Int]] // returns Array[Int](0, 0, 0, 0)
+ * }}}
+ *
+ * @param elemClass the `Class` object of the component type of the array
+ * @param length the length of the new array.
+ * @return an array of the given component type as an `AnyRef`.
+ * @throws `java.lang.NullPointerException` If `elemClass` is `null`.
+ * @throws `java.lang.IllegalArgumentException` if componentType is [[scala.Unit]] or `java.lang.Void.TYPE`
+ * @throws `java.lang.NegativeArraySizeException` if the specified length is negative
+ */
+ @inline
+ def createArray(elemClass: Class[_], length: Int): AnyRef =
+ java.lang.reflect.Array.newInstance(elemClass, length)
+
+ /** Assigns the value of 0 to each element in the array.
+ * @param arr A non-null Array[Int].
+ * @throws `java.lang.NullPointerException` If `arr` is `null`.
+ */
+ @inline
+ def arrayclear(arr: Array[Int]) { java.util.Arrays.fill(arr, 0) }
+
+ /** Returns the `Class` object associated with the class or interface with the given string name using the current `ClassLoader`.
+ * On the JVM, invoking this method is equivalent to: `java.lang.Class.forName(name)`
+ *
+ * For more information, please see the Java documentation for [[java.lang.Class]].
+ *
+ * @param name the fully qualified name of the desired class.
+ * @return the `Class` object for the class with the specified name.
+ * @throws `java.lang.LinkageError` if the linkage fails
+ * @throws `java.lang.ExceptionInInitializerError` if the initialization provoked by this method fails
+ * @throws `java.lang.ClassNotFoundException` if the class cannot be located
+ * @example {{{
+ * val a = scala.compat.Platform.getClassForName("java.lang.Integer") // returns the Class[_] for java.lang.Integer
+ * }}}
+ */
+ @inline
+ def getClassForName(name: String): Class[_] = java.lang.Class.forName(name)
+
+ /** The default line separator.
+ *
+ * On the JavaScript backend, this is always "\n".
+ */
+ val EOL = "\n"
+
+ /** The current time in milliseconds. The time is counted since 1 January 1970
+ * UTC.
+ *
+ * Note that the operating system timer used to obtain this value may be less
+ * precise than a millisecond.
+ */
+ @inline
+ def currentTime: Long = System.currentTimeMillis()
+
+ /** Runs the garbage collector.
+ *
+ * This is a request that the underlying JVM runs the garbage collector.
+ * The results of this call depends heavily on the JVM used.
+ * The underlying JVM is free to ignore this request.
+ */
+ @inline
+ def collectGarbage(): Unit = System.gc()
+
+ /** The name of the default character set encoding as a string */
+ @inline
+ def defaultCharsetName: String = java.nio.charset.Charset.defaultCharset.name
+}
diff --git a/examples/scala-js/scalalib/overrides-2.10/scala/package.scala b/examples/scala-js/scalalib/overrides-2.10/scala/package.scala
new file mode 100644
index 0000000..5aad9a9
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.10/scala/package.scala
@@ -0,0 +1,138 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+/**
+ * Core Scala types. They are always available without an explicit import.
+ * @contentDiagram hideNodes "scala.Serializable"
+ */
+package object scala {
+ type Throwable = java.lang.Throwable
+ type Exception = java.lang.Exception
+ type Error = java.lang.Error
+
+ type RuntimeException = java.lang.RuntimeException
+ type NullPointerException = java.lang.NullPointerException
+ type ClassCastException = java.lang.ClassCastException
+ type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
+ type ArrayIndexOutOfBoundsException = java.lang.ArrayIndexOutOfBoundsException
+ type StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException
+ type UnsupportedOperationException = java.lang.UnsupportedOperationException
+ type IllegalArgumentException = java.lang.IllegalArgumentException
+ type NoSuchElementException = java.util.NoSuchElementException
+ type NumberFormatException = java.lang.NumberFormatException
+ type AbstractMethodError = java.lang.AbstractMethodError
+ type InterruptedException = java.lang.InterruptedException
+
+ // A dummy used by the specialization annotation.
+ val AnyRef = new Specializable {
+ override def toString = "object AnyRef"
+ }
+
+ @deprecated("instead of `@serializable class C`, use `class C extends Serializable`", "2.9.0")
+ type serializable = annotation.serializable
+
+ @deprecated("instead of `@cloneable class C`, use `class C extends Cloneable`", "2.10.0")
+ type cloneable = annotation.cloneable
+
+ type TraversableOnce[+A] = scala.collection.TraversableOnce[A]
+
+ type Traversable[+A] = scala.collection.Traversable[A]
+ val Traversable = scala.collection.Traversable
+
+ type Iterable[+A] = scala.collection.Iterable[A]
+ val Iterable = scala.collection.Iterable
+
+ type Seq[+A] = scala.collection.Seq[A]
+ val Seq = scala.collection.Seq
+
+ type IndexedSeq[+A] = scala.collection.IndexedSeq[A]
+ val IndexedSeq = scala.collection.IndexedSeq
+
+ type Iterator[+A] = scala.collection.Iterator[A]
+ val Iterator = scala.collection.Iterator
+
+ type BufferedIterator[+A] = scala.collection.BufferedIterator[A]
+
+ type List[+A] = scala.collection.immutable.List[A]
+ val List = scala.collection.immutable.List
+
+ val Nil = scala.collection.immutable.Nil
+
+ type ::[A] = scala.collection.immutable.::[A]
+ val :: = scala.collection.immutable.::
+
+ val +: = scala.collection.+:
+ val :+ = scala.collection.:+
+
+ type Stream[+A] = scala.collection.immutable.Stream[A]
+ val Stream = scala.collection.immutable.Stream
+ val #:: = scala.collection.immutable.Stream.#::
+
+ type Vector[+A] = scala.collection.immutable.Vector[A]
+ val Vector = scala.collection.immutable.Vector
+
+ type StringBuilder = scala.collection.mutable.StringBuilder
+ val StringBuilder = scala.collection.mutable.StringBuilder
+
+ type Range = scala.collection.immutable.Range
+ val Range = scala.collection.immutable.Range
+
+ // Numeric types which were moved into scala.math.*
+
+ type BigDecimal = scala.math.BigDecimal
+ lazy val BigDecimal = scala.math.BigDecimal
+
+ type BigInt = scala.math.BigInt
+ lazy val BigInt = scala.math.BigInt
+
+ type Equiv[T] = scala.math.Equiv[T]
+ val Equiv = scala.math.Equiv
+
+ type Fractional[T] = scala.math.Fractional[T]
+ type Integral[T] = scala.math.Integral[T]
+
+ type Numeric[T] = scala.math.Numeric[T]
+ val Numeric = scala.math.Numeric
+
+ type Ordered[T] = scala.math.Ordered[T]
+ val Ordered = scala.math.Ordered
+
+ type Ordering[T] = scala.math.Ordering[T]
+ val Ordering = scala.math.Ordering
+
+ type PartialOrdering[T] = scala.math.PartialOrdering[T]
+ type PartiallyOrdered[T] = scala.math.PartiallyOrdered[T]
+
+ type Either[+A, +B] = scala.util.Either[A, B]
+ val Either = scala.util.Either
+
+ type Left[+A, +B] = scala.util.Left[A, B]
+ val Left = scala.util.Left
+
+ type Right[+A, +B] = scala.util.Right[A, B]
+ val Right = scala.util.Right
+
+ // Annotations which we might move to annotation.*
+/*
+ type SerialVersionUID = annotation.SerialVersionUID
+ type cloneable = annotation.cloneable
+ type deprecated = annotation.deprecated
+ type deprecatedName = annotation.deprecatedName
+ type inline = annotation.inline
+ type native = annotation.native
+ type noinline = noannotation.inline
+ type remote = annotation.remote
+ type serializable = annotation.serializable
+ type specialized = annotation.specialized
+ type transient = annotation.transient
+ type throws = annotation.throws
+ type unchecked = annotation.unchecked.unchecked
+ type volatile = annotation.volatile
+ */
+}
diff --git a/examples/scala-js/scalalib/overrides-2.11/scala/Console.scala b/examples/scala-js/scalalib/overrides-2.11/scala/Console.scala
new file mode 100644
index 0000000..b85f8dc
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.11/scala/Console.scala
@@ -0,0 +1,222 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+
+import java.io.{ BufferedReader, InputStream, InputStreamReader, OutputStream, PrintStream, Reader }
+import scala.io.{ AnsiColor, StdIn }
+import scala.util.DynamicVariable
+
+/** Implements functionality for
+ * printing Scala values on the terminal as well as reading specific values.
+ * Also defines constants for marking up text on ANSI terminals.
+ *
+ * @author Matthias Zenger
+ * @version 1.0, 03/09/2003
+ */
+object Console extends DeprecatedConsole with AnsiColor {
+ private val outVar = new DynamicVariable[PrintStream](java.lang.System.out)
+ private val errVar = new DynamicVariable[PrintStream](java.lang.System.err)
+ private val inVar = new DynamicVariable[BufferedReader](null)
+ //new BufferedReader(new InputStreamReader(java.lang.System.in)))
+
+ protected def setOutDirect(out: PrintStream): Unit = outVar.value = out
+ protected def setErrDirect(err: PrintStream): Unit = errVar.value = err
+ protected def setInDirect(in: BufferedReader): Unit = inVar.value = in
+
+ /** The default output, can be overridden by `setOut` */
+ def out = outVar.value
+ /** The default error, can be overridden by `setErr` */
+ def err = errVar.value
+ /** The default input, can be overridden by `setIn` */
+ def in = inVar.value
+
+ /** Sets the default output stream for the duration
+ * of execution of one thunk.
+ *
+ * @example {{{
+ * withOut(Console.err) { println("This goes to default _error_") }
+ * }}}
+ *
+ * @param out the new output stream.
+ * @param thunk the code to execute with
+ * the new output stream active
+ * @return the results of `thunk`
+ * @see `withOut[T](out:OutputStream)(thunk: => T)`
+ */
+ def withOut[T](out: PrintStream)(thunk: =>T): T =
+ outVar.withValue(out)(thunk)
+
+ /** Sets the default output stream for the duration
+ * of execution of one thunk.
+ *
+ * @param out the new output stream.
+ * @param thunk the code to execute with
+ * the new output stream active
+ * @return the results of `thunk`
+ * @see `withOut[T](out:PrintStream)(thunk: => T)`
+ */
+ def withOut[T](out: OutputStream)(thunk: =>T): T =
+ withOut(new PrintStream(out))(thunk)
+
+ /** Set the default error stream for the duration
+ * of execution of one thunk.
+ * @example {{{
+ * withErr(Console.out) { println("This goes to default _out_") }
+ * }}}
+ *
+ * @param err the new error stream.
+ * @param thunk the code to execute with
+ * the new error stream active
+ * @return the results of `thunk`
+ * @see `withErr[T](err:OutputStream)(thunk: =>T)`
+ */
+ def withErr[T](err: PrintStream)(thunk: =>T): T =
+ errVar.withValue(err)(thunk)
+
+ /** Sets the default error stream for the duration
+ * of execution of one thunk.
+ *
+ * @param err the new error stream.
+ * @param thunk the code to execute with
+ * the new error stream active
+ * @return the results of `thunk`
+ * @see `withErr[T](err:PrintStream)(thunk: =>T)`
+ */
+ def withErr[T](err: OutputStream)(thunk: =>T): T =
+ withErr(new PrintStream(err))(thunk)
+
+ /** Sets the default input stream for the duration
+ * of execution of one thunk.
+ *
+ * @example {{{
+ * val someFile:Reader = openFile("file.txt")
+ * withIn(someFile) {
+ * // Reads a line from file.txt instead of default input
+ * println(readLine)
+ * }
+ * }}}
+ *
+ * @param thunk the code to execute with
+ * the new input stream active
+ *
+ * @return the results of `thunk`
+ * @see `withIn[T](in:InputStream)(thunk: =>T)`
+ */
+ def withIn[T](reader: Reader)(thunk: =>T): T =
+ inVar.withValue(new BufferedReader(reader))(thunk)
+
+ /** Sets the default input stream for the duration
+ * of execution of one thunk.
+ *
+ * @param in the new input stream.
+ * @param thunk the code to execute with
+ * the new input stream active
+ * @return the results of `thunk`
+ * @see `withIn[T](reader:Reader)(thunk: =>T)`
+ */
+ def withIn[T](in: InputStream)(thunk: =>T): T =
+ withIn(new InputStreamReader(in))(thunk)
+
+ /** Prints an object to `out` using its `toString` method.
+ *
+ * @param obj the object to print; may be null.
+ */
+ def print(obj: Any) {
+ out.print(if (null == obj) "null" else obj.toString())
+ }
+
+ /** Flushes the output stream. This function is required when partial
+ * output (i.e. output not terminated by a newline character) has
+ * to be made visible on the terminal.
+ */
+ def flush() { out.flush() }
+
+ /** Prints a newline character on the default output.
+ */
+ def println() { out.println() }
+
+ /** Prints out an object to the default output, followed by a newline character.
+ *
+ * @param x the object to print.
+ */
+ def println(x: Any) { out.println(x) }
+
+ /** Prints its arguments as a formatted string to the default output,
+ * based on a string pattern (in a fashion similar to printf in C).
+ *
+ * The interpretation of the formatting patterns is described in
+ * <a href="" target="contentFrame" class="java/util/Formatter">
+ * `java.util.Formatter`</a>.
+ *
+ * @param text the pattern for formatting the arguments.
+ * @param args the arguments used to instantiating the pattern.
+ * @throws java.lang.IllegalArgumentException if there was a problem with the format string or arguments
+ */
+ def printf(text: String, args: Any*) { out.print(text format (args : _*)) }
+}
+
+private[scala] abstract class DeprecatedConsole {
+ self: Console.type =>
+
+ /** Internal usage only. */
+ protected def setOutDirect(out: PrintStream): Unit
+ protected def setErrDirect(err: PrintStream): Unit
+ protected def setInDirect(in: BufferedReader): Unit
+
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readBoolean(): Boolean = StdIn.readBoolean()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readByte(): Byte = StdIn.readByte()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readChar(): Char = StdIn.readChar()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readDouble(): Double = StdIn.readDouble()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readFloat(): Float = StdIn.readFloat()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readInt(): Int = StdIn.readInt()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readLine(): String = StdIn.readLine()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readLine(text: String, args: Any*): String = StdIn.readLine(text, args: _*)
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readLong(): Long = StdIn.readLong()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readShort(): Short = StdIn.readShort()
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readf(format: String): List[Any] = StdIn.readf(format)
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readf1(format: String): Any = StdIn.readf1(format)
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readf2(format: String): (Any, Any) = StdIn.readf2(format)
+ @deprecated("Use the method in scala.io.StdIn", "2.11.0") def readf3(format: String): (Any, Any, Any) = StdIn.readf3(format)
+
+ /** Sets the default output stream.
+ *
+ * @param out the new output stream.
+ */
+ @deprecated("Use withOut", "2.11.0") def setOut(out: PrintStream): Unit = setOutDirect(out)
+
+ /** Sets the default output stream.
+ *
+ * @param out the new output stream.
+ */
+ @deprecated("Use withOut", "2.11.0") def setOut(out: OutputStream): Unit = setOutDirect(new PrintStream(out))
+
+ /** Sets the default error stream.
+ *
+ * @param err the new error stream.
+ */
+ @deprecated("Use withErr", "2.11.0") def setErr(err: PrintStream): Unit = setErrDirect(err)
+
+ /** Sets the default error stream.
+ *
+ * @param err the new error stream.
+ */
+ @deprecated("Use withErr", "2.11.0") def setErr(err: OutputStream): Unit = setErrDirect(new PrintStream(err))
+
+ /** Sets the default input stream.
+ *
+ * @param reader specifies the new input stream.
+ */
+ @deprecated("Use withIn", "2.11.0") def setIn(reader: Reader): Unit = setInDirect(new BufferedReader(reader))
+
+ /** Sets the default input stream.
+ *
+ * @param in the new input stream.
+ */
+ @deprecated("Use withIn", "2.11.0") def setIn(in: InputStream): Unit = setInDirect(new BufferedReader(new InputStreamReader(in)))
+}
diff --git a/examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/NumericRange.scala b/examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/NumericRange.scala
new file mode 100644
index 0000000..51f9f68
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/NumericRange.scala
@@ -0,0 +1,346 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+package collection
+package immutable
+
+import mutable.{ Builder, ListBuffer }
+
+/** `NumericRange` is a more generic version of the
+ * `Range` class which works with arbitrary types.
+ * It must be supplied with an `Integral` implementation of the
+ * range type.
+ *
+ * Factories for likely types include `Range.BigInt`, `Range.Long`,
+ * and `Range.BigDecimal`. `Range.Int` exists for completeness, but
+ * the `Int`-based `scala.Range` should be more performant.
+ *
+ * {{{
+ * val r1 = new Range(0, 100, 1)
+ * val veryBig = Int.MaxValue.toLong + 1
+ * val r2 = Range.Long(veryBig, veryBig + 100, 1)
+ * assert(r1 sameElements r2.map(_ - veryBig))
+ * }}}
+ *
+ * TODO: Now the specialization exists there is no clear reason to have
+ * separate classes for Range/NumericRange. Investigate and consolidate.
+ *
+ * @author Paul Phillips
+ * @version 2.8
+ * @define Coll `NumericRange`
+ * @define coll numeric range
+ * @define mayNotTerminateInf
+ * @define willNotTerminateInf
+ */
+abstract class NumericRange[T]
+ (val start: T, val end: T, val step: T, val isInclusive: Boolean)
+ (implicit num: Integral[T])
+extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
+ /** Note that NumericRange must be invariant so that constructs
+ * such as "1L to 10 by 5" do not infer the range type as AnyVal.
+ */
+ import num._
+
+ // See comment in Range for why this must be lazy.
+ private lazy val numRangeElements: Int =
+ NumericRange.count(start, end, step, isInclusive)
+
+ override def length = numRangeElements
+ override def isEmpty = length == 0
+ override lazy val last: T =
+ if (length == 0) Nil.last
+ else locationAfterN(length - 1)
+
+ /** Create a new range with the start and end values of this range and
+ * a new `step`.
+ */
+ def by(newStep: T): NumericRange[T] = copy(start, end, newStep)
+
+ /** Create a copy of this range.
+ */
+ def copy(start: T, end: T, step: T): NumericRange[T]
+
+ override def foreach[U](f: T => U) {
+ var count = 0
+ var current = start
+ while (count < length) {
+ f(current)
+ current += step
+ count += 1
+ }
+ }
+
+ // TODO: these private methods are straight copies from Range, duplicated
+ // to guard against any (most likely illusory) performance drop. They should
+ // be eliminated one way or another.
+
+ // Tests whether a number is within the endpoints, without testing
+ // whether it is a member of the sequence (i.e. when step > 1.)
+ private def isWithinBoundaries(elem: T) = !isEmpty && (
+ (step > zero && start <= elem && elem <= last ) ||
+ (step < zero && last <= elem && elem <= start)
+ )
+ // Methods like apply throw exceptions on invalid n, but methods like take/drop
+ // are forgiving: therefore the checks are with the methods.
+ private def locationAfterN(n: Int): T = start + (step * fromInt(n))
+
+ // When one drops everything. Can't ever have unchecked operations
+ // like "end + 1" or "end - 1" because ranges involving Int.{ MinValue, MaxValue }
+ // will overflow. This creates an exclusive range where start == end
+ // based on the given value.
+ private def newEmptyRange(value: T) = NumericRange(value, value, step)
+
+ final override def take(n: Int): NumericRange[T] = (
+ if (n <= 0 || length == 0) newEmptyRange(start)
+ else if (n >= length) this
+ else new NumericRange.Inclusive(start, locationAfterN(n - 1), step)
+ )
+
+ final override def drop(n: Int): NumericRange[T] = (
+ if (n <= 0 || length == 0) this
+ else if (n >= length) newEmptyRange(end)
+ else copy(locationAfterN(n), end, step)
+ )
+
+ def apply(idx: Int): T = {
+ if (idx < 0 || idx >= length) throw new IndexOutOfBoundsException(idx.toString)
+ else locationAfterN(idx)
+ }
+
+ import NumericRange.defaultOrdering
+
+ override def min[T1 >: T](implicit ord: Ordering[T1]): T =
+ if (ord eq defaultOrdering(num)) {
+ if (num.signum(step) > 0) start
+ else last
+ } else super.min(ord)
+
+ override def max[T1 >: T](implicit ord: Ordering[T1]): T =
+ if (ord eq defaultOrdering(num)) {
+ if (num.signum(step) > 0) last
+ else start
+ } else super.max(ord)
+
+ // Motivated by the desire for Double ranges with BigDecimal precision,
+ // we need some way to map a Range and get another Range. This can't be
+ // done in any fully general way because Ranges are not arbitrary
+ // sequences but step-valued, so we have a custom method only we can call
+ // which we promise to use responsibly.
+ //
+ // The point of it all is that
+ //
+ // 0.0 to 1.0 by 0.1
+ //
+ // should result in
+ //
+ // NumericRange[Double](0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)
+ //
+ // and not
+ //
+ // NumericRange[Double](0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9)
+ //
+ // or perhaps more importantly,
+ //
+ // (0.1 to 0.3 by 0.1 contains 0.3) == true
+ //
+ private[immutable] def mapRange[A](fm: T => A)(implicit unum: Integral[A]): NumericRange[A] = {
+ val self = this
+
+ // XXX This may be incomplete.
+ new NumericRange[A](fm(start), fm(end), fm(step), isInclusive) {
+ def copy(start: A, end: A, step: A): NumericRange[A] =
+ if (isInclusive) NumericRange.inclusive(start, end, step)
+ else NumericRange(start, end, step)
+
+ private lazy val underlyingRange: NumericRange[T] = self
+ override def foreach[U](f: A => U) { underlyingRange foreach (x => f(fm(x))) }
+ override def isEmpty = underlyingRange.isEmpty
+ override def apply(idx: Int): A = fm(underlyingRange(idx))
+ override def containsTyped(el: A) = underlyingRange exists (x => fm(x) == el)
+ }
+ }
+
+ // a well-typed contains method.
+ def containsTyped(x: T): Boolean =
+ isWithinBoundaries(x) && (((x - start) % step) == zero)
+
+ override def contains[A1 >: T](x: A1): Boolean =
+ try containsTyped(x.asInstanceOf[T])
+ catch { case _: ClassCastException => false }
+
+ final override def sum[B >: T](implicit num: Numeric[B]): B = {
+ // arithmetic series formula can be used for regular addition
+ if ((num eq scala.math.Numeric.IntIsIntegral)||
+ (num eq scala.math.Numeric.ShortIsIntegral)||
+ (num eq scala.math.Numeric.ByteIsIntegral)||
+ (num eq scala.math.Numeric.CharIsIntegral)||
+ (num eq scala.math.Numeric.LongIsIntegral)) {
+ val numAsIntegral = num.asInstanceOf[Integral[B]]
+ import numAsIntegral._
+ if (isEmpty) num fromInt 0
+ else if (numRangeElements == 1) head
+ else ((num fromInt numRangeElements) * (head + last) / (num fromInt 2))
+ } else {
+ // user provided custom Numeric, we cannot rely on arithmetic series formula
+ if (isEmpty) num.zero
+ else {
+ var acc = num.zero
+ var i = head
+ var idx = 0
+ while(idx < length) {
+ acc = num.plus(acc, i)
+ i = i + step
+ idx = idx + 1
+ }
+ acc
+ }
+ }
+ }
+
+ override lazy val hashCode = super.hashCode()
+ override def equals(other: Any) = other match {
+ case x: NumericRange[_] =>
+ (x canEqual this) && (length == x.length) && (
+ (length == 0) || // all empty sequences are equal
+ (start == x.start && last == x.last) // same length and same endpoints implies equality
+ )
+ case _ =>
+ super.equals(other)
+ }
+
+ override def toString() = {
+ val endStr = if (length > Range.MAX_PRINT) ", ... )" else ")"
+ take(Range.MAX_PRINT).mkString("NumericRange(", ", ", endStr)
+ }
+}
+
+/** A companion object for numeric ranges.
+ */
+object NumericRange {
+
+ /** Calculates the number of elements in a range given start, end, step, and
+ * whether or not it is inclusive. Throws an exception if step == 0 or
+ * the number of elements exceeds the maximum Int.
+ */
+ def count[T](start: T, end: T, step: T, isInclusive: Boolean)(implicit num: Integral[T]): Int = {
+ val zero = num.zero
+ val upward = num.lt(start, end)
+ val posStep = num.gt(step, zero)
+
+ if (step == zero) throw new IllegalArgumentException("step cannot be 0.")
+ else if (start == end) if (isInclusive) 1 else 0
+ else if (upward != posStep) 0
+ else {
+ /* We have to be frightfully paranoid about running out of range.
+ * We also can't assume that the numbers will fit in a Long.
+ * We will assume that if a > 0, -a can be represented, and if
+ * a < 0, -a+1 can be represented. We also assume that if we
+ * can't fit in Int, we can represent 2*Int.MaxValue+3 (at least).
+ * And we assume that numbers wrap rather than cap when they overflow.
+ */
+ // Check whether we can short-circuit by deferring to Int range.
+ val startint = num.toInt(start)
+ if (start == num.fromInt(startint)) {
+ val endint = num.toInt(end)
+ if (end == num.fromInt(endint)) {
+ val stepint = num.toInt(step)
+ if (step == num.fromInt(stepint)) {
+ return {
+ if (isInclusive) Range.inclusive(startint, endint, stepint).length
+ else Range (startint, endint, stepint).length
+ }
+ }
+ }
+ }
+ // If we reach this point, deferring to Int failed.
+ // Numbers may be big.
+ val one = num.one
+ val limit = num.fromInt(Int.MaxValue)
+ def check(t: T): T =
+ if (num.gt(t, limit)) throw new IllegalArgumentException("More than Int.MaxValue elements.")
+ else t
+ // If the range crosses zero, it might overflow when subtracted
+ val startside = num.signum(start)
+ val endside = num.signum(end)
+ num.toInt{
+ if (startside*endside >= 0) {
+ // We're sure we can subtract these numbers.
+ // Note that we do not use .rem because of different conventions for Long and BigInt
+ val diff = num.minus(end, start)
+ val quotient = check(num.quot(diff, step))
+ val remainder = num.minus(diff, num.times(quotient, step))
+ if (!isInclusive && zero == remainder) quotient else check(num.plus(quotient, one))
+ }
+ else {
+ // We might not even be able to subtract these numbers.
+ // Jump in three pieces:
+ // * start to -1 or 1, whichever is closer (waypointA)
+ // * one step, which will take us at least to 0 (ends at waypointB)
+ // * there to the end
+ val negone = num.fromInt(-1)
+ val startlim = if (posStep) negone else one
+ val startdiff = num.minus(startlim, start)
+ val startq = check(num.quot(startdiff, step))
+ val waypointA = if (startq == zero) start else num.plus(start, num.times(startq, step))
+ val waypointB = num.plus(waypointA, step)
+ check {
+ if (num.lt(waypointB, end) != upward) {
+ // No last piece
+ if (isInclusive && waypointB == end) num.plus(startq, num.fromInt(2))
+ else num.plus(startq, one)
+ }
+ else {
+ // There is a last piece
+ val enddiff = num.minus(end,waypointB)
+ val endq = check(num.quot(enddiff, step))
+ val last = if (endq == zero) waypointB else num.plus(waypointB, num.times(endq, step))
+ // Now we have to tally up all the pieces
+ // 1 for the initial value
+ // startq steps to waypointA
+ // 1 step to waypointB
+ // endq steps to the end (one less if !isInclusive and last==end)
+ num.plus(startq, num.plus(endq, if (!isInclusive && last==end) one else num.fromInt(2)))
+ }
+ }
+ }
+ }
+ }
+ }
+
+ class Inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T])
+ extends NumericRange(start, end, step, true) {
+ def copy(start: T, end: T, step: T): Inclusive[T] =
+ NumericRange.inclusive(start, end, step)
+
+ def exclusive: Exclusive[T] = NumericRange(start, end, step)
+ }
+
+ class Exclusive[T](start: T, end: T, step: T)(implicit num: Integral[T])
+ extends NumericRange(start, end, step, false) {
+ def copy(start: T, end: T, step: T): Exclusive[T] =
+ NumericRange(start, end, step)
+
+ def inclusive: Inclusive[T] = NumericRange.inclusive(start, end, step)
+ }
+
+ def apply[T](start: T, end: T, step: T)(implicit num: Integral[T]): Exclusive[T] =
+ new Exclusive(start, end, step)
+ def inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T]): Inclusive[T] =
+ new Inclusive(start, end, step)
+
+ private[collection] val defaultOrdering = Map[Numeric[_], Ordering[_]](
+ Numeric.IntIsIntegral -> Ordering.Int,
+ Numeric.ShortIsIntegral -> Ordering.Short,
+ Numeric.ByteIsIntegral -> Ordering.Byte,
+ Numeric.CharIsIntegral -> Ordering.Char,
+ Numeric.LongIsIntegral -> Ordering.Long
+ )
+
+}
+
diff --git a/examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/Range.scala b/examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/Range.scala
new file mode 100644
index 0000000..45eed20
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.11/scala/collection/immutable/Range.scala
@@ -0,0 +1,516 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+package scala
+package collection.immutable
+
+import scala.collection.parallel.immutable.ParRange
+
+/** The `Range` class represents integer values in range
+ * ''[start;end)'' with non-zero step value `step`.
+ * It's a special case of an indexed sequence.
+ * For example:
+ *
+ * {{{
+ * val r1 = 0 until 10
+ * val r2 = r1.start until r1.end by r1.step + 1
+ * println(r2.length) // = 5
+ * }}}
+ *
+ * Ranges that contain more than `Int.MaxValue` elements can be created, but
+ * these overfull ranges have only limited capabilities. Any method that
+ * could require a collection of over `Int.MaxValue` length to be created, or
+ * could be asked to index beyond `Int.MaxValue` elements will throw an
+ * exception. Overfull ranges can safely be reduced in size by changing
+ * the step size (e.g. `by 3`) or taking/dropping elements. `contains`,
+ * `equals`, and access to the ends of the range (`head`, `last`, `tail`,
+ * `init`) are also permitted on overfull ranges.
+ *
+ * @param start the start of this range.
+ * @param end the exclusive end of the range.
+ * @param step the step for the range.
+ *
+ * @author Martin Odersky
+ * @author Paul Phillips
+ * @version 2.8
+ * @since 2.5
+ * @see [[http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#ranges "Scala's Collection Library overview"]]
+ * section on `Ranges` for more information.
+ *
+ * @define coll range
+ * @define mayNotTerminateInf
+ * @define willNotTerminateInf
+ * @define doesNotUseBuilders
+ * '''Note:''' this method does not use builders to construct a new range,
+ * and its complexity is O(1).
+ */
+@SerialVersionUID(7618862778670199309L)
+@inline
+@deprecatedInheritance("The implementation details of Range makes inheriting from it unwise.", "2.11.0")
+class Range(val start: Int, val end: Int, val step: Int)
+extends scala.collection.AbstractSeq[Int]
+ with IndexedSeq[Int]
+ with scala.collection.CustomParallelizable[Int, ParRange]
+ with Serializable
+{
+ override def par = new ParRange(this)
+
+ private def gap = end.toLong - start.toLong
+ private def isExact = gap % step == 0
+ private def hasStub = isInclusive || !isExact
+ private def longLength = gap / step + ( if (hasStub) 1 else 0 )
+
+ // Check cannot be evaluated eagerly because we have a pattern where
+ // ranges are constructed like: "x to y by z" The "x to y" piece
+ // should not trigger an exception. So the calculation is delayed,
+ // which means it will not fail fast for those cases where failing was
+ // correct.
+ override final val isEmpty = (
+ (start > end && step > 0)
+ || (start < end && step < 0)
+ || (start == end && !isInclusive)
+ )
+ @deprecated("This method will be made private, use `length` instead.", "2.11")
+ final val numRangeElements: Int = {
+ if (step == 0) throw new IllegalArgumentException("step cannot be 0.")
+ else if (isEmpty) 0
+ else {
+ val len = longLength
+ if (len > scala.Int.MaxValue) -1
+ else len.toInt
+ }
+ }
+ @deprecated("This method will be made private, use `last` instead.", "2.11")
+ final val lastElement =
+ if (isEmpty) start - step
+ else step match {
+ case 1 => if (isInclusive) end else end-1
+ case -1 => if (isInclusive) end else end+1
+ case _ =>
+ val remainder = (gap % step).toInt
+ if (remainder != 0) end - remainder
+ else if (isInclusive) end
+ else end - step
+ }
+
+ @deprecated("This method will be made private.", "2.11")
+ final val terminalElement = lastElement + step
+
+ /** The last element of this range. This method will return the correct value
+ * even if there are too many elements to iterate over.
+ */
+ override def last = if (isEmpty) Nil.last else lastElement
+ override def head = if (isEmpty) Nil.head else start
+
+ override def min[A1 >: Int](implicit ord: Ordering[A1]): Int =
+ if (ord eq Ordering.Int) {
+ if (step > 0) head
+ else last
+ } else super.min(ord)
+
+ override def max[A1 >: Int](implicit ord: Ordering[A1]): Int =
+ if (ord eq Ordering.Int) {
+ if (step > 0) last
+ else head
+ } else super.max(ord)
+
+ protected def copy(start: Int, end: Int, step: Int): Range = new Range(start, end, step)
+
+ /** Create a new range with the `start` and `end` values of this range and
+ * a new `step`.
+ *
+ * @return a new range with a different step
+ */
+ def by(step: Int): Range = copy(start, end, step)
+
+ def isInclusive = false
+
+ override def size = length
+ override def length = if (numRangeElements < 0) fail() else numRangeElements
+
+ private def fail() = Range.fail(start, end, step, isInclusive)
+ private def validateMaxLength() {
+ if (numRangeElements < 0)
+ fail()
+ }
+
+ final def apply(idx: Int): Int = {
+ validateMaxLength()
+ if (idx < 0 || idx >= numRangeElements) throw new IndexOutOfBoundsException(idx.toString)
+ else start + (step * idx)
+ }
+
+ @inline final override def foreach[@specialized(Unit) U](f: Int => U) {
+ validateMaxLength()
+ val isCommonCase = (start != Int.MinValue || end != Int.MinValue)
+ var i = start
+ var count = 0
+ val terminal = terminalElement
+ val step = this.step
+ while(
+ if(isCommonCase) { i != terminal }
+ else { count < numRangeElements }
+ ) {
+ f(i)
+ count += 1
+ i += step
+ }
+ }
+
+ /** Creates a new range containing the first `n` elements of this range.
+ *
+ * $doesNotUseBuilders
+ *
+ * @param n the number of elements to take.
+ * @return a new range consisting of `n` first elements.
+ */
+ final override def take(n: Int): Range = (
+ if (n <= 0 || isEmpty) newEmptyRange(start)
+ else if (n >= numRangeElements && numRangeElements >= 0) this
+ else {
+ // May have more than Int.MaxValue elements in range (numRangeElements < 0)
+ // but the logic is the same either way: take the first n
+ new Range.Inclusive(start, locationAfterN(n - 1), step)
+ }
+ )
+
+ /** Creates a new range containing all the elements of this range except the first `n` elements.
+ *
+ * $doesNotUseBuilders
+ *
+ * @param n the number of elements to drop.
+ * @return a new range consisting of all the elements of this range except `n` first elements.
+ */
+ final override def drop(n: Int): Range = (
+ if (n <= 0 || isEmpty) this
+ else if (n >= numRangeElements && numRangeElements >= 0) newEmptyRange(end)
+ else {
+ // May have more than Int.MaxValue elements (numRangeElements < 0)
+ // but the logic is the same either way: go forwards n steps, keep the rest
+ copy(locationAfterN(n), end, step)
+ }
+ )
+
+ /** Creates a new range containing all the elements of this range except the last one.
+ *
+ * $doesNotUseBuilders
+ *
+ * @return a new range consisting of all the elements of this range except the last one.
+ */
+ final override def init: Range = {
+ if (isEmpty)
+ Nil.init
+
+ dropRight(1)
+ }
+
+ /** Creates a new range containing all the elements of this range except the first one.
+ *
+ * $doesNotUseBuilders
+ *
+ * @return a new range consisting of all the elements of this range except the first one.
+ */
+ final override def tail: Range = {
+ if (isEmpty)
+ Nil.tail
+
+ drop(1)
+ }
+
+ // Advance from the start while we meet the given test
+ private def argTakeWhile(p: Int => Boolean): Long = {
+ if (isEmpty) start
+ else {
+ var current = start
+ val stop = last
+ while (current != stop && p(current)) current += step
+ if (current != stop || !p(current)) current
+ else current.toLong + step
+ }
+ }
+ // Methods like apply throw exceptions on invalid n, but methods like take/drop
+ // are forgiving: therefore the checks are with the methods.
+ private def locationAfterN(n: Int) = start + (step * n)
+
+ // When one drops everything. Can't ever have unchecked operations
+ // like "end + 1" or "end - 1" because ranges involving Int.{ MinValue, MaxValue }
+ // will overflow. This creates an exclusive range where start == end
+ // based on the given value.
+ private def newEmptyRange(value: Int) = new Range(value, value, step)
+
+ final override def takeWhile(p: Int => Boolean): Range = {
+ val stop = argTakeWhile(p)
+ if (stop==start) newEmptyRange(start)
+ else {
+ val x = (stop - step).toInt
+ if (x == last) this
+ else new Range.Inclusive(start, x, step)
+ }
+ }
+ final override def dropWhile(p: Int => Boolean): Range = {
+ val stop = argTakeWhile(p)
+ if (stop == start) this
+ else {
+ val x = (stop - step).toInt
+ if (x == last) newEmptyRange(last)
+ else new Range.Inclusive(x + step, last, step)
+ }
+ }
+ final override def span(p: Int => Boolean): (Range, Range) = {
+ val border = argTakeWhile(p)
+ if (border == start) (newEmptyRange(start), this)
+ else {
+ val x = (border - step).toInt
+ if (x == last) (this, newEmptyRange(last))
+ else (new Range.Inclusive(start, x, step), new Range.Inclusive(x+step, last, step))
+ }
+ }
+
+ /** Creates a pair of new ranges, first consisting of elements before `n`, and the second
+ * of elements after `n`.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def splitAt(n: Int) = (take(n), drop(n))
+
+ /** Creates a new range consisting of the `length - n` last elements of the range.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def takeRight(n: Int): Range = {
+ if (n <= 0) newEmptyRange(start)
+ else if (numRangeElements >= 0) drop(numRangeElements - n)
+ else {
+ // Need to handle over-full range separately
+ val y = last
+ val x = y - step.toLong*(n-1)
+ if ((step > 0 && x < start) || (step < 0 && x > start)) this
+ else new Range.Inclusive(x.toInt, y, step)
+ }
+ }
+
+ /** Creates a new range consisting of the initial `length - n` elements of the range.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def dropRight(n: Int): Range = {
+ if (n <= 0) this
+ else if (numRangeElements >= 0) take(numRangeElements - n)
+ else {
+ // Need to handle over-full range separately
+ val y = last - step.toInt*n
+ if ((step > 0 && y < start) || (step < 0 && y > start)) newEmptyRange(start)
+ else new Range.Inclusive(start, y.toInt, step)
+ }
+ }
+
+ /** Returns the reverse of this range.
+ *
+ * $doesNotUseBuilders
+ */
+ final override def reverse: Range =
+ if (isEmpty) this
+ else new Range.Inclusive(last, start, -step)
+
+ /** Make range inclusive.
+ */
+ def inclusive =
+ if (isInclusive) this
+ else new Range.Inclusive(start, end, step)
+
+ final def contains(x: Int) = {
+ if (x==end && !isInclusive) false
+ else if (step > 0) {
+ if (x < start || x > end) false
+ else (step == 1) || (((x - start) % step) == 0)
+ }
+ else {
+ if (x < end || x > start) false
+ else (step == -1) || (((x - start) % step) == 0)
+ }
+ }
+
+ final override def sum[B >: Int](implicit num: Numeric[B]): Int = {
+ if (num eq scala.math.Numeric.IntIsIntegral) {
+ // this is normal integer range with usual addition. arithmetic series formula can be used
+ if (isEmpty) 0
+ else if (numRangeElements == 1) head
+ else (numRangeElements.toLong * (head + last) / 2).toInt
+ } else {
+ // user provided custom Numeric, we cannot rely on arithmetic series formula
+ if (isEmpty) num.toInt(num.zero)
+ else {
+ var acc = num.zero
+ var i = head
+ while(i != terminalElement) {
+ acc = num.plus(acc, i)
+ i = i + step
+ }
+ num.toInt(acc)
+ }
+ }
+ }
+
+ override def toIterable = this
+
+ override def toSeq = this
+
+ override def equals(other: Any) = other match {
+ case x: Range =>
+ // Note: this must succeed for overfull ranges (length > Int.MaxValue)
+ (x canEqual this) && {
+ if (isEmpty) x.isEmpty // empty sequences are equal
+ else // this is non-empty...
+ x.nonEmpty && start == x.start && { // ...so other must contain something and have same start
+ val l0 = last
+ (l0 == x.last && ( // And same end
+ start == l0 || step == x.step // And either the same step, or not take any steps
+ ))
+ }
+ }
+ case _ =>
+ super.equals(other)
+ }
+ /** Note: hashCode can't be overridden without breaking Seq's
+ * equals contract.
+ */
+
+ override def toString() = {
+ val endStr =
+ if (numRangeElements > Range.MAX_PRINT || (!isEmpty && numRangeElements < 0)) ", ... )" else ")"
+ take(Range.MAX_PRINT).mkString("Range(", ", ", endStr)
+ }
+}
+
+/** A companion object for the `Range` class.
+ */
+object Range {
+ private[immutable] val MAX_PRINT = 512 // some arbitrary value
+
+ private def description(start: Int, end: Int, step: Int, isInclusive: Boolean) =
+ "%d %s %d by %s".format(start, if (isInclusive) "to" else "until", end, step)
+
+ private def fail(start: Int, end: Int, step: Int, isInclusive: Boolean) =
+ throw new IllegalArgumentException(description(start, end, step, isInclusive) +
+ ": seqs cannot contain more than Int.MaxValue elements.")
+
+ /** Counts the number of range elements.
+ * @pre step != 0
+ * If the size of the range exceeds Int.MaxValue, the
+ * result will be negative.
+ */
+ def count(start: Int, end: Int, step: Int, isInclusive: Boolean): Int = {
+ if (step == 0)
+ throw new IllegalArgumentException("step cannot be 0.")
+
+ val isEmpty = (
+ if (start == end) !isInclusive
+ else if (start < end) step < 0
+ else step > 0
+ )
+ if (isEmpty) 0
+ else {
+ // Counts with Longs so we can recognize too-large ranges.
+ val gap: Long = end.toLong - start.toLong
+ val jumps: Long = gap / step
+ // Whether the size of this range is one larger than the
+ // number of full-sized jumps.
+ val hasStub = isInclusive || (gap % step != 0)
+ val result: Long = jumps + ( if (hasStub) 1 else 0 )
+
+ if (result > scala.Int.MaxValue) -1
+ else result.toInt
+ }
+ }
+ def count(start: Int, end: Int, step: Int): Int =
+ count(start, end, step, isInclusive = false)
+
+ @inline
+ class Inclusive(start: Int, end: Int, step: Int) extends Range(start, end, step) {
+// override def par = new ParRange(this)
+ override def isInclusive = true
+ override protected def copy(start: Int, end: Int, step: Int): Range = new Inclusive(start, end, step)
+ }
+
+ /** Make a range from `start` until `end` (exclusive) with given step value.
+ * @note step != 0
+ */
+ def apply(start: Int, end: Int, step: Int): Range = new Range(start, end, step)
+
+ /** Make a range from `start` until `end` (exclusive) with step value 1.
+ */
+ def apply(start: Int, end: Int): Range = new Range(start, end, 1)
+
+ /** Make an inclusive range from `start` to `end` with given step value.
+ * @note step != 0
+ */
+ def inclusive(start: Int, end: Int, step: Int): Range.Inclusive = new Inclusive(start, end, step)
+
+ /** Make an inclusive range from `start` to `end` with step value 1.
+ */
+ def inclusive(start: Int, end: Int): Range.Inclusive = new Inclusive(start, end, 1)
+
+ // BigInt and Long are straightforward generic ranges.
+ object BigInt {
+ def apply(start: BigInt, end: BigInt, step: BigInt) = NumericRange(start, end, step)
+ def inclusive(start: BigInt, end: BigInt, step: BigInt) = NumericRange.inclusive(start, end, step)
+ }
+
+ object Long {
+ def apply(start: Long, end: Long, step: Long) = NumericRange(start, end, step)
+ def inclusive(start: Long, end: Long, step: Long) = NumericRange.inclusive(start, end, step)
+ }
+
+ // BigDecimal uses an alternative implementation of Numeric in which
+ // it pretends to be Integral[T] instead of Fractional[T]. See Numeric for
+ // details. The intention is for it to throw an exception anytime
+ // imprecision or surprises might result from anything, although this may
+ // not yet be fully implemented.
+ object BigDecimal {
+ implicit val bigDecAsIntegral = scala.math.Numeric.BigDecimalAsIfIntegral
+
+ def apply(start: BigDecimal, end: BigDecimal, step: BigDecimal) =
+ NumericRange(start, end, step)
+ def inclusive(start: BigDecimal, end: BigDecimal, step: BigDecimal) =
+ NumericRange.inclusive(start, end, step)
+ }
+
+ // Double works by using a BigDecimal under the hood for precise
+ // stepping, but mapping the sequence values back to doubles with
+ // .doubleValue. This constructs the BigDecimals by way of the
+ // String constructor (valueOf) instead of the Double one, which
+ // is necessary to keep 0.3d at 0.3 as opposed to
+ // 0.299999999999999988897769753748434595763683319091796875 or so.
+ object Double {
+ implicit val bigDecAsIntegral = scala.math.Numeric.BigDecimalAsIfIntegral
+ implicit val doubleAsIntegral = scala.math.Numeric.DoubleAsIfIntegral
+ def toBD(x: Double): BigDecimal = scala.math.BigDecimal valueOf x
+
+ def apply(start: Double, end: Double, step: Double) =
+ BigDecimal(toBD(start), toBD(end), toBD(step)) mapRange (_.doubleValue)
+
+ def inclusive(start: Double, end: Double, step: Double) =
+ BigDecimal.inclusive(toBD(start), toBD(end), toBD(step)) mapRange (_.doubleValue)
+ }
+
+ // As there is no appealing default step size for not-really-integral ranges,
+ // we offer a partially constructed object.
+ class Partial[T, U](f: T => U) {
+ def by(x: T): U = f(x)
+ }
+
+ // Illustrating genericity with Int Range, which should have the same behavior
+ // as the original Range class. However we leave the original Range
+ // indefinitely, for performance and because the compiler seems to bootstrap
+ // off it and won't do so with our parameterized version without modifications.
+ object Int {
+ def apply(start: Int, end: Int, step: Int) = NumericRange(start, end, step)
+ def inclusive(start: Int, end: Int, step: Int) = NumericRange.inclusive(start, end, step)
+ }
+}
diff --git a/examples/scala-js/scalalib/overrides-2.11/scala/collection/mutable/Buffer.scala b/examples/scala-js/scalalib/overrides-2.11/scala/collection/mutable/Buffer.scala
new file mode 100644
index 0000000..2171cb9
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.11/scala/collection/mutable/Buffer.scala
@@ -0,0 +1,51 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+
+package scala
+package collection
+package mutable
+
+import generic._
+
+import scala.scalajs.js
+
+/** Buffers are used to create sequences of elements incrementally by
+ * appending, prepending, or inserting new elements. It is also
+ * possible to access and modify elements in a random access fashion
+ * via the index of the element in the current sequence.
+ *
+ * @author Matthias Zenger
+ * @author Martin Odersky
+ * @version 2.8
+ * @since 1
+ *
+ * @tparam A type of the elements contained in this buffer.
+ *
+ * @define Coll `Buffer`
+ * @define coll buffer
+ */
+trait Buffer[A] extends Seq[A]
+ with GenericTraversableTemplate[A, Buffer]
+ with BufferLike[A, Buffer[A]]
+ with scala.Cloneable {
+ override def companion: GenericCompanion[Buffer] = Buffer
+}
+
+/** $factoryInfo
+ * @define coll buffer
+ * @define Coll `Buffer`
+ */
+object Buffer extends SeqFactory[Buffer] {
+ implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Buffer[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
+ def newBuilder[A]: Builder[A, Buffer[A]] = new js.WrappedArray
+}
+
+/** Explicit instantiation of the `Buffer` trait to reduce class file size in subclasses. */
+abstract class AbstractBuffer[A] extends AbstractSeq[A] with Buffer[A]
diff --git a/examples/scala-js/scalalib/overrides-2.11/scala/compat/Platform.scala b/examples/scala-js/scalalib/overrides-2.11/scala/compat/Platform.scala
new file mode 100644
index 0000000..cdb6916
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.11/scala/compat/Platform.scala
@@ -0,0 +1,132 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+package compat
+
+import java.lang.System
+
+object Platform {
+
+ /** Thrown when a stack overflow occurs because a method or function recurses too deeply.
+ *
+ * On the JVM, this is a type alias for `java.lang.StackOverflowError`, which itself extends `java.lang.Error`.
+ * The same rules apply to catching a `java.lang.Error` as for Java, that it indicates a serious problem that a reasonable application should not try and catch.
+ */
+ type StackOverflowError = java.lang.StackOverflowError
+
+ /** This is a type alias for `java.util.ConcurrentModificationException`,
+ * which may be thrown by methods that detect an invalid modification of an object.
+ * For example, many common collection types do not allow modifying a collection
+ * while it is being iterated over.
+ */
+ type ConcurrentModificationException = java.util.ConcurrentModificationException
+
+ /** Copies `length` elements of array `src` starting at position `srcPos` to the
+ * array `dest` starting at position `destPos`. If `src`==`dest`, the copying will
+ * behave as if the elements copied from `src` were first copied to a temporary
+ * array before being copied back into the array at the destination positions.
+ *
+ * @param src A non-null array as source for the copy.
+ * @param srcPos The starting index in the source array.
+ * @param dest A non-null array as destination for the copy.
+ * @param destPos The starting index in the destination array.
+ * @param length The number of elements to be copied.
+ * @throws java.lang.NullPointerException If either `src` or `dest` are `null`.
+ * @throws java.lang.ArrayStoreException If either `src` or `dest` are not of type
+ * [java.lang.Array]; or if the element type of `src` is not
+ * compatible with that of `dest`.
+ * @throws java.lang.IndexOutOfBoundsException If either srcPos` or `destPos` are
+ * outside of the bounds of their respective arrays; or if `length`
+ * is negative; or if there are less than `length` elements available
+ * after `srcPos` or `destPos` in `src` and `dest` respectively.
+ */
+ @inline
+ def arraycopy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int) {
+ System.arraycopy(src, srcPos, dest, destPos, length)
+ }
+
+ /** Creates a new array of the specified type and given length.
+ *
+ * Note that if `elemClass` is a subclass of [[scala.AnyVal]] then the returned value is an Array of the corresponding java primitive type.
+ * For example, the following code `scala.compat.Platform.createArray(classOf[Int], 4)` returns an array of the java primitive type `int`.
+ *
+ * For a [[scala.AnyVal]] array, the values of the array are set to 0 for ''numeric value types'' ([[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]],
+ * [[scala.Short]], and [[scala.Byte]]), and `false` for [[scala.Boolean]]. Creation of an array of type [[scala.Unit]] is not possible.
+ *
+ * For subclasses of [[scala.AnyRef]], the values of the array are set to `null`.
+ *
+ * The caller must cast the returned value to the correct type.
+ *
+ * @example {{{
+ * val a = scala.compat.Platform.createArray(classOf[Int], 4).asInstanceOf[Array[Int]] // returns Array[Int](0, 0, 0, 0)
+ * }}}
+ *
+ * @param elemClass the `Class` object of the component type of the array
+ * @param length the length of the new array.
+ * @return an array of the given component type as an `AnyRef`.
+ * @throws `java.lang.NullPointerException` If `elemClass` is `null`.
+ * @throws `java.lang.IllegalArgumentException` if componentType is [[scala.Unit]] or `java.lang.Void.TYPE`
+ * @throws `java.lang.NegativeArraySizeException` if the specified length is negative
+ */
+ @inline
+ def createArray(elemClass: Class[_], length: Int): AnyRef =
+ java.lang.reflect.Array.newInstance(elemClass, length)
+
+ /** Assigns the value of 0 to each element in the array.
+ * @param arr A non-null Array[Int].
+ * @throws `java.lang.NullPointerException` If `arr` is `null`.
+ */
+ @inline
+ def arrayclear(arr: Array[Int]) { java.util.Arrays.fill(arr, 0) }
+
+ /** Returns the `Class` object associated with the class or interface with the given string name using the current `ClassLoader`.
+ * On the JVM, invoking this method is equivalent to: `java.lang.Class.forName(name)`
+ *
+ * For more information, please see the Java documentation for [[java.lang.Class]].
+ *
+ * @param name the fully qualified name of the desired class.
+ * @return the `Class` object for the class with the specified name.
+ * @throws `java.lang.LinkageError` if the linkage fails
+ * @throws `java.lang.ExceptionInInitializerError` if the initialization provoked by this method fails
+ * @throws `java.lang.ClassNotFoundException` if the class cannot be located
+ * @example {{{
+ * val a = scala.compat.Platform.getClassForName("java.lang.Integer") // returns the Class[_] for java.lang.Integer
+ * }}}
+ */
+ @inline
+ def getClassForName(name: String): Class[_] = java.lang.Class.forName(name)
+
+ /** The default line separator.
+ *
+ * On the JavaScript backend, this is always "\n".
+ */
+ val EOL = "\n"
+
+ /** The current time in milliseconds. The time is counted since 1 January 1970
+ * UTC.
+ *
+ * Note that the operating system timer used to obtain this value may be less
+ * precise than a millisecond.
+ */
+ @inline
+ def currentTime: Long = System.currentTimeMillis()
+
+ /** Runs the garbage collector.
+ *
+ * This is a request that the underlying JVM runs the garbage collector.
+ * The results of this call depends heavily on the JVM used.
+ * The underlying JVM is free to ignore this request.
+ */
+ @inline
+ def collectGarbage(): Unit = System.gc()
+
+ /** The name of the default character set encoding as a string */
+ @inline
+ def defaultCharsetName: String = java.nio.charset.Charset.defaultCharset.name
+}
diff --git a/examples/scala-js/scalalib/overrides-2.11/scala/package.scala b/examples/scala-js/scalalib/overrides-2.11/scala/package.scala
new file mode 100644
index 0000000..21051d4
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides-2.11/scala/package.scala
@@ -0,0 +1,133 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+/**
+ * Core Scala types. They are always available without an explicit import.
+ * @contentDiagram hideNodes "scala.Serializable"
+ */
+package object scala {
+ type Throwable = java.lang.Throwable
+ type Exception = java.lang.Exception
+ type Error = java.lang.Error
+
+ type RuntimeException = java.lang.RuntimeException
+ type NullPointerException = java.lang.NullPointerException
+ type ClassCastException = java.lang.ClassCastException
+ type IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
+ type ArrayIndexOutOfBoundsException = java.lang.ArrayIndexOutOfBoundsException
+ type StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException
+ type UnsupportedOperationException = java.lang.UnsupportedOperationException
+ type IllegalArgumentException = java.lang.IllegalArgumentException
+ type NoSuchElementException = java.util.NoSuchElementException
+ type NumberFormatException = java.lang.NumberFormatException
+ type AbstractMethodError = java.lang.AbstractMethodError
+ type InterruptedException = java.lang.InterruptedException
+
+ // A dummy used by the specialization annotation.
+ val AnyRef = new Specializable {
+ override def toString = "object AnyRef"
+ }
+
+ type TraversableOnce[+A] = scala.collection.TraversableOnce[A]
+
+ type Traversable[+A] = scala.collection.Traversable[A]
+ val Traversable = scala.collection.Traversable
+
+ type Iterable[+A] = scala.collection.Iterable[A]
+ val Iterable = scala.collection.Iterable
+
+ type Seq[+A] = scala.collection.Seq[A]
+ val Seq = scala.collection.Seq
+
+ type IndexedSeq[+A] = scala.collection.IndexedSeq[A]
+ val IndexedSeq = scala.collection.IndexedSeq
+
+ type Iterator[+A] = scala.collection.Iterator[A]
+ val Iterator = scala.collection.Iterator
+
+ type BufferedIterator[+A] = scala.collection.BufferedIterator[A]
+
+ type List[+A] = scala.collection.immutable.List[A]
+ val List = scala.collection.immutable.List
+
+ val Nil = scala.collection.immutable.Nil
+
+ type ::[A] = scala.collection.immutable.::[A]
+ val :: = scala.collection.immutable.::
+
+ val +: = scala.collection.+:
+ val :+ = scala.collection.:+
+
+ type Stream[+A] = scala.collection.immutable.Stream[A]
+ val Stream = scala.collection.immutable.Stream
+ val #:: = scala.collection.immutable.Stream.#::
+
+ type Vector[+A] = scala.collection.immutable.Vector[A]
+ val Vector = scala.collection.immutable.Vector
+
+ type StringBuilder = scala.collection.mutable.StringBuilder
+ val StringBuilder = scala.collection.mutable.StringBuilder
+
+ type Range = scala.collection.immutable.Range
+ val Range = scala.collection.immutable.Range
+
+ // Numeric types which were moved into scala.math.*
+
+ type BigDecimal = scala.math.BigDecimal
+ lazy val BigDecimal = scala.math.BigDecimal
+
+ type BigInt = scala.math.BigInt
+ lazy val BigInt = scala.math.BigInt
+
+ type Equiv[T] = scala.math.Equiv[T]
+ val Equiv = scala.math.Equiv
+
+ type Fractional[T] = scala.math.Fractional[T]
+ val Fractional = scala.math.Fractional
+
+ type Integral[T] = scala.math.Integral[T]
+ val Integral = scala.math.Integral
+
+ type Numeric[T] = scala.math.Numeric[T]
+ val Numeric = scala.math.Numeric
+
+ type Ordered[T] = scala.math.Ordered[T]
+ val Ordered = scala.math.Ordered
+
+ type Ordering[T] = scala.math.Ordering[T]
+ val Ordering = scala.math.Ordering
+
+ type PartialOrdering[T] = scala.math.PartialOrdering[T]
+ type PartiallyOrdered[T] = scala.math.PartiallyOrdered[T]
+
+ type Either[+A, +B] = scala.util.Either[A, B]
+ val Either = scala.util.Either
+
+ type Left[+A, +B] = scala.util.Left[A, B]
+ val Left = scala.util.Left
+
+ type Right[+A, +B] = scala.util.Right[A, B]
+ val Right = scala.util.Right
+
+ // Annotations which we might move to annotation.*
+/*
+ type SerialVersionUID = annotation.SerialVersionUID
+ type deprecated = annotation.deprecated
+ type deprecatedName = annotation.deprecatedName
+ type inline = annotation.inline
+ type native = annotation.native
+ type noinline = annotation.noinline
+ type remote = annotation.remote
+ type specialized = annotation.specialized
+ type transient = annotation.transient
+ type throws = annotation.throws
+ type unchecked = annotation.unchecked.unchecked
+ type volatile = annotation.volatile
+ */
+}
diff --git a/examples/scala-js/scalalib/overrides/scala/App.scala b/examples/scala-js/scalalib/overrides/scala/App.scala
new file mode 100644
index 0000000..c49817b
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/App.scala
@@ -0,0 +1,83 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2010-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+
+import scala.compat.Platform.currentTime
+import scala.collection.mutable.ListBuffer
+
+import scala.scalajs.js.annotation.JSExport
+
+/** The `App` trait can be used to quickly turn objects
+ * into executable programs. Here is an example:
+ * {{{
+ * object Main extends App {
+ * Console.println("Hello World: " + (args mkString ", "))
+ * }
+ * }}}
+ * Here, object `Main` inherits the `main` method of `App`.
+ *
+ * `args` returns the current command line arguments as an array.
+ *
+ * ==Caveats==
+ *
+ * '''''It should be noted that this trait is implemented using the [[DelayedInit]]
+ * functionality, which means that fields of the object will not have been initialized
+ * before the main method has been executed.'''''
+ *
+ * It should also be noted that the `main` method will not normally need to be overridden:
+ * the purpose is to turn the whole class body into the “main method”. You should only
+ * chose to override it if you know what you are doing.
+ *
+ * @author Martin Odersky
+ * @version 2.1, 15/02/2011
+ */
+trait App extends DelayedInit {
+
+ /** The time when the execution of this program started, in milliseconds since 1
+ * January 1970 UTC. */
+ val executionStart: Long = currentTime
+
+ /** The command line arguments passed to the application's `main` method.
+ */
+ protected def args: Array[String] = _args
+
+ private var _args: Array[String] = _
+
+ private val initCode = new ListBuffer[() => Unit]
+
+ /** The init hook. This saves all initialization code for execution within `main`.
+ * This method is normally never called directly from user code.
+ * Instead it is called as compiler-generated code for those classes and objects
+ * (but not traits) that inherit from the `DelayedInit` trait and that do not
+ * themselves define a `delayedInit` method.
+ * @param body the initialization code to be stored for later execution
+ */
+ override def delayedInit(body: => Unit) {
+ initCode += (() => body)
+ }
+
+ /** The main method.
+ * This stores all argument so that they can be retrieved with `args`
+ * and the executes all initialization code segments in the order they were
+ * passed to `delayedInit`
+ *
+ * @param args the arguments passed to the main method
+ */
+ def main(args: Array[String]) = {
+ this._args = args
+ for (proc <- initCode) proc()
+
+ /* DELETED for Scala.js
+ if (util.Properties.propIsSet("scala.time")) {
+ val total = currentTime - executionStart
+ Console.println("[total " + total + "ms]")
+ }
+ */
+ }
+}
diff --git a/examples/scala-js/scalalib/overrides/scala/Enumeration.scala b/examples/scala-js/scalalib/overrides/scala/Enumeration.scala
new file mode 100644
index 0000000..bdc1701
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/Enumeration.scala
@@ -0,0 +1,284 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+
+import scala.collection.{ mutable, immutable, generic, SortedSetLike, AbstractSet }
+import java.lang.reflect.{ Modifier, Method => JMethod, Field => JField }
+import scala.reflect.NameTransformer._
+import java.util.regex.Pattern
+
+/** Defines a finite set of values specific to the enumeration. Typically
+ * these values enumerate all possible forms something can take and provide
+ * a lightweight alternative to case classes.
+ *
+ * Each call to a `Value` method adds a new unique value to the enumeration.
+ * To be accessible, these values are usually defined as `val` members of
+ * the evaluation.
+ *
+ * All values in an enumeration share a common, unique type defined as the
+ * `Value` type member of the enumeration (`Value` selected on the stable
+ * identifier path of the enumeration instance).
+ *
+ * @example {{{
+ * object Main extends App {
+ *
+ * object WeekDay extends Enumeration {
+ * type WeekDay = Value
+ * val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
+ * }
+ * import WeekDay._
+ *
+ * def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun)
+ *
+ * WeekDay.values filter isWorkingDay foreach println
+ * }
+ * // output:
+ * // Mon
+ * // Tue
+ * // Wed
+ * // Thu
+ * // Fri
+ * }}}
+ *
+ * @param initial The initial value from which to count the integers that
+ * identifies values at run-time.
+ * @author Matthias Zenger
+ */
+@SerialVersionUID(8476000850333817230L)
+abstract class Enumeration (initial: Int) extends Serializable {
+ thisenum =>
+
+ def this() = this(0)
+
+ /* Note that `readResolve` cannot be private, since otherwise
+ the JVM does not invoke it when deserializing subclasses. */
+ protected def readResolve(): AnyRef = ???
+
+ /** The name of this enumeration.
+ */
+ override def toString =
+ (getClass.getName.stripSuffix("$").split('.')).last.split('$').last
+
+ /** The mapping from the integer used to identify values to the actual
+ * values. */
+ private val vmap: mutable.Map[Int, Value] = new mutable.HashMap
+
+ /** The cache listing all values of this enumeration. */
+ @transient private var vset: ValueSet = null
+ @transient @volatile private var vsetDefined = false
+
+ /** The mapping from the integer used to identify values to their
+ * names. */
+ private val nmap: mutable.Map[Int, String] = new mutable.HashMap
+
+ /** The values of this enumeration as a set.
+ */
+ def values: ValueSet = {
+ if (!vsetDefined) {
+ vset = (ValueSet.newBuilder ++= vmap.values).result()
+ vsetDefined = true
+ }
+ vset
+ }
+
+ /** The integer to use to identify the next created value. */
+ protected var nextId: Int = initial
+
+ /** The string to use to name the next created value. */
+ protected var nextName: Iterator[String] = _
+
+ private def nextNameOrNull =
+ if (nextName != null && nextName.hasNext) nextName.next() else null
+
+ /** The highest integer amongst those used to identify values in this
+ * enumeration. */
+ private var topId = initial
+
+ /** The lowest integer amongst those used to identify values in this
+ * enumeration, but no higher than 0. */
+ private var bottomId = if(initial < 0) initial else 0
+
+ /** The one higher than the highest integer amongst those used to identify
+ * values in this enumeration. */
+ final def maxId = topId
+
+ /** The value of this enumeration with given id `x`
+ */
+ final def apply(x: Int): Value = vmap(x)
+
+ /** Return a `Value` from this `Enumeration` whose name matches
+ * the argument `s`. The names are determined automatically via reflection.
+ *
+ * @param s an `Enumeration` name
+ * @return the `Value` of this `Enumeration` if its name matches `s`
+ * @throws NoSuchElementException if no `Value` with a matching
+ * name is in this `Enumeration`
+ */
+ final def withName(s: String): Value = {
+ val (unnamed, named) = values partition {
+ _.toString().startsWith("<Unknown name for enum field ")
+ }
+
+ named.find(_.toString == s) match {
+ case Some(v) => v
+ // If we have unnamed values, we issue a detailed error message
+ case None if unnamed.nonEmpty =>
+ throw new NoSuchElementException(
+ s"""Couldn't find enum field with name $s.
+ |However, there were the following unnamed fields:
+ |${unnamed.mkString(" ","\n ","")}""".stripMargin)
+ // Normal case (no unnamed Values)
+ case _ => None.get
+ }
+ }
+
+ /** Creates a fresh value, part of this enumeration. */
+ protected final def Value: Value = Value(nextId)
+
+ /** Creates a fresh value, part of this enumeration, identified by the
+ * integer `i`.
+ *
+ * @param i An integer that identifies this value at run-time. It must be
+ * unique amongst all values of the enumeration.
+ * @return Fresh value identified by `i`.
+ */
+ protected final def Value(i: Int): Value = Value(i, nextNameOrNull)
+
+ /** Creates a fresh value, part of this enumeration, called `name`.
+ *
+ * @param name A human-readable name for that value.
+ * @return Fresh value called `name`.
+ */
+ protected final def Value(name: String): Value = Value(nextId, name)
+
+ /** Creates a fresh value, part of this enumeration, called `name`
+ * and identified by the integer `i`.
+ *
+ * @param i An integer that identifies this value at run-time. It must be
+ * unique amongst all values of the enumeration.
+ * @param name A human-readable name for that value.
+ * @return Fresh value with the provided identifier `i` and name `name`.
+ */
+ protected final def Value(i: Int, name: String): Value = new Val(i, name)
+
+ /** The type of the enumerated values. */
+ @SerialVersionUID(7091335633555234129L)
+ abstract class Value extends Ordered[Value] with Serializable {
+ /** the id and bit location of this enumeration value */
+ def id: Int
+ /** a marker so we can tell whose values belong to whom come reflective-naming time */
+ private[Enumeration] val outerEnum = thisenum
+
+ override def compare(that: Value): Int =
+ if (this.id < that.id) -1
+ else if (this.id == that.id) 0
+ else 1
+ override def equals(other: Any) = other match {
+ case that: Enumeration#Value => (outerEnum eq that.outerEnum) && (id == that.id)
+ case _ => false
+ }
+ override def hashCode: Int = id.##
+
+ /** Create a ValueSet which contains this value and another one */
+ def + (v: Value) = ValueSet(this, v)
+ }
+
+ /** A class implementing the [[scala.Enumeration.Value]] type. This class
+ * can be overridden to change the enumeration's naming and integer
+ * identification behaviour.
+ */
+ @SerialVersionUID(0 - 3501153230598116017L)
+ protected class Val(i: Int, name: String)
+ extends Value with Serializable {
+
+ def this(i: Int) = this(i, nextNameOrNull)
+ def this(name: String) = this(nextId, name)
+ def this() = this(nextId)
+
+ assert(!vmap.isDefinedAt(i), "Duplicate id: " + i)
+ vmap(i) = this
+ vsetDefined = false
+ nextId = i + 1
+ if (nextId > topId) topId = nextId
+ if (i < bottomId) bottomId = i
+ def id = i
+ override def toString() =
+ if (name != null) name
+ // Scala.js specific
+ else s"<Unknown name for enum field #$i of class ${getClass}>"
+
+ protected def readResolve(): AnyRef = {
+ val enum = thisenum.readResolve().asInstanceOf[Enumeration]
+ if (enum.vmap == null) this
+ else enum.vmap(i)
+ }
+ }
+
+ /** An ordering by id for values of this set */
+ object ValueOrdering extends Ordering[Value] {
+ def compare(x: Value, y: Value): Int = x compare y
+ }
+
+ /** A class for sets of values.
+ * Iterating through this set will yield values in increasing order of their ids.
+ *
+ * @param nnIds The set of ids of values (adjusted so that the lowest value does
+ * not fall below zero), organized as a `BitSet`.
+ */
+ class ValueSet private[ValueSet] (private[this] var nnIds: immutable.BitSet)
+ extends AbstractSet[Value]
+ with immutable.SortedSet[Value]
+ with SortedSetLike[Value, ValueSet]
+ with Serializable {
+
+ implicit def ordering: Ordering[Value] = ValueOrdering
+ def rangeImpl(from: Option[Value], until: Option[Value]): ValueSet =
+ new ValueSet(nnIds.rangeImpl(from.map(_.id - bottomId), until.map(_.id - bottomId)))
+
+ override def empty = ValueSet.empty
+ def contains(v: Value) = nnIds contains (v.id - bottomId)
+ def + (value: Value) = new ValueSet(nnIds + (value.id - bottomId))
+ def - (value: Value) = new ValueSet(nnIds - (value.id - bottomId))
+ def iterator = nnIds.iterator map (id => thisenum.apply(bottomId + id))
+ // This is only defined in 2.11. We change its implementation so it also
+ // compiles on 2.10.
+ def keysIteratorFrom(start: Value) = from(start).keySet.toIterator
+ //nnIds keysIteratorFrom start.id map (id => thisenum.apply(bottomId + id))
+ override def stringPrefix = thisenum + ".ValueSet"
+ /** Creates a bit mask for the zero-adjusted ids in this set as a
+ * new array of longs */
+ def toBitMask: Array[Long] = nnIds.toBitMask
+ }
+
+ /** A factory object for value sets */
+ object ValueSet {
+ import generic.CanBuildFrom
+
+ /** The empty value set */
+ val empty = new ValueSet(immutable.BitSet.empty)
+ /** A value set consisting of given elements */
+ def apply(elems: Value*): ValueSet = (newBuilder ++= elems).result()
+ /** A value set containing all the values for the zero-adjusted ids
+ * corresponding to the bits in an array */
+ def fromBitMask(elems: Array[Long]): ValueSet = new ValueSet(immutable.BitSet.fromBitMask(elems))
+ /** A builder object for value sets */
+ def newBuilder: mutable.Builder[Value, ValueSet] = new mutable.Builder[Value, ValueSet] {
+ private[this] val b = new mutable.BitSet
+ def += (x: Value) = { b += (x.id - bottomId); this }
+ def clear() = b.clear()
+ def result() = new ValueSet(b.toImmutable)
+ }
+ /** The implicit builder for value sets */
+ implicit def canBuildFrom: CanBuildFrom[ValueSet, Value, ValueSet] =
+ new CanBuildFrom[ValueSet, Value, ValueSet] {
+ def apply(from: ValueSet) = newBuilder
+ def apply() = newBuilder
+ }
+ }
+} \ No newline at end of file
diff --git a/examples/scala-js/scalalib/overrides/scala/Symbol.scala b/examples/scala-js/scalalib/overrides/scala/Symbol.scala
new file mode 100644
index 0000000..1af9d28
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/Symbol.scala
@@ -0,0 +1,117 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+
+import scala.scalajs.js
+
+/** This class provides a simple way to get unique objects for equal strings.
+ * Since symbols are interned, they can be compared using reference equality.
+ * Instances of `Symbol` can be created easily with Scala's built-in quote
+ * mechanism.
+ *
+ * For instance, the [[http://scala-lang.org/#_top Scala]] term `'mysym` will
+ * invoke the constructor of the `Symbol` class in the following way:
+ * `Symbol("mysym")`.
+ *
+ * @author Martin Odersky, Iulian Dragos
+ * @version 1.8
+ */
+final class Symbol private (val name: String) extends Serializable {
+ /** Converts this symbol to a string.
+ */
+ override def toString(): String = "'" + name
+
+ @throws(classOf[java.io.ObjectStreamException])
+ private def readResolve(): Any = Symbol.apply(name)
+ override def hashCode = name.hashCode()
+ override def equals(other: Any) = this eq other.asInstanceOf[AnyRef]
+}
+
+// Modified to use Scala.js specific cache
+object Symbol extends JSUniquenessCache[Symbol] {
+ override def apply(name: String): Symbol = super.apply(name)
+ protected def valueFromKey(name: String): Symbol = new Symbol(name)
+ protected def keyFromValue(sym: Symbol): Option[String] = Some(sym.name)
+}
+
+private[scala] abstract class JSUniquenessCache[V]
+{
+ private val map = js.Dictionary.empty[js.Any] // V | js.Undefined
+
+ protected def valueFromKey(k: String): V
+ protected def keyFromValue(v: V): Option[String]
+
+ def apply(name: String): V = {
+ val cachedSym = map(name)
+ if (js.isUndefined(cachedSym)) {
+ val sym = valueFromKey(name)
+ map(name) = sym.asInstanceOf[js.Any]
+ sym.asInstanceOf[V]
+ } else {
+ cachedSym.asInstanceOf[V]
+ }
+ }
+
+ def unapply(other: V): Option[String] = keyFromValue(other)
+}
+
+/** This is private so it won't appear in the library API, but
+ * abstracted to offer some hope of reusability. */
+/* DELETED for Scala.js
+private[scala] abstract class UniquenessCache[K >: js.String, V >: Null]
+{
+
+ import java.lang.ref.WeakReference
+ import java.util.WeakHashMap
+ import java.util.concurrent.locks.ReentrantReadWriteLock
+
+ private val rwl = new ReentrantReadWriteLock()
+ private val rlock = rwl.readLock
+ private val wlock = rwl.writeLock
+ private val map = new WeakHashMap[K, WeakReference[V]]
+
+ protected def valueFromKey(k: K): V
+ protected def keyFromValue(v: V): Option[K]
+
+ def apply(name: K): V = {
+ def cached(): V = {
+ rlock.lock
+ try {
+ val reference = map get name
+ if (reference == null) null
+ else reference.get // will be null if we were gc-ed
+ }
+ finally rlock.unlock
+ }
+ def updateCache(): V = {
+ wlock.lock
+ try {
+ val res = cached()
+ if (res != null) res
+ else {
+ // If we don't remove the old String key from the map, we can
+ // wind up with one String as the key and a different String as
+ // as the name field in the Symbol, which can lead to surprising
+ // GC behavior and duplicate Symbols. See SI-6706.
+ map remove name
+ val sym = valueFromKey(name)
+ map.put(name, new WeakReference(sym))
+ sym
+ }
+ }
+ finally wlock.unlock
+ }
+
+ val res = cached()
+ if (res == null) updateCache()
+ else res
+ }
+ def unapply(other: V): Option[K] = keyFromValue(other)
+}
+*/
diff --git a/examples/scala-js/scalalib/overrides/scala/concurrent/impl/AbstractPromise.scala b/examples/scala-js/scalalib/overrides/scala/concurrent/impl/AbstractPromise.scala
new file mode 100644
index 0000000..8ea135e
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/concurrent/impl/AbstractPromise.scala
@@ -0,0 +1,29 @@
+package scala.concurrent.impl
+
+/**
+ * JavaScript specific implementation of AbstractPromise
+ *
+ * This basically implements a "CAS" in Scala for JavaScript. Its
+ * implementation is trivial because there is no multi-threading.
+ *
+ * @author Tobias Schlatter
+ */
+abstract class AbstractPromise {
+
+ private var state: AnyRef = _
+
+ protected final
+ def updateState(oldState: AnyRef, newState: AnyRef): Boolean = {
+ if (state eq oldState) {
+ state = newState
+ true
+ } else false
+ }
+
+ protected final def getState: AnyRef = state
+
+}
+
+object AbstractPromise {
+ protected def updater = ???
+}
diff --git a/examples/scala-js/scalalib/overrides/scala/math/ScalaNumber.scala b/examples/scala-js/scalalib/overrides/scala/math/ScalaNumber.scala
new file mode 100644
index 0000000..811346d
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/math/ScalaNumber.scala
@@ -0,0 +1,21 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+
+package scala.math
+
+/** A marker class for Number types introduced by Scala
+ * @author Martin Odersky, Paul Phillips
+ * @version 2.8
+ * @since 2.8
+ */
+abstract class ScalaNumber extends java.lang.Number {
+ protected def isWhole(): Boolean
+ def underlying(): Object
+}
diff --git a/examples/scala-js/scalalib/overrides/scala/runtime/BoxesRunTime.scala b/examples/scala-js/scalalib/overrides/scala/runtime/BoxesRunTime.scala
new file mode 100644
index 0000000..5df7fd1
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/runtime/BoxesRunTime.scala
@@ -0,0 +1,124 @@
+package scala.runtime
+
+import scala.math.ScalaNumber
+
+object BoxesRunTime {
+ def boxToCharacter(c: Char): java.lang.Character =
+ java.lang.Character.valueOf(c)
+
+ def unboxToChar(c: Object): Char =
+ if (c eq null) 0
+ else c.asInstanceOf[java.lang.Character].charValue()
+
+ def equals(x: Object, y: Object): Boolean =
+ if (x eq y) true
+ else equals2(x, y)
+
+ @inline // only called by equals(), not by codegen
+ def equals2(x: Object, y: Object): Boolean = {
+ x match {
+ case xn: java.lang.Number => equalsNumObject(xn, y)
+ case xc: java.lang.Character => equalsCharObject(xc, y)
+ case null => y eq null
+ case _ => x.equals(y)
+ }
+ }
+
+ def equalsNumObject(xn: java.lang.Number, y: Object): Boolean = {
+ y match {
+ case yn: java.lang.Number => equalsNumNum(xn, yn)
+ case yc: java.lang.Character => equalsNumChar(xn, yc)
+ case _ =>
+ if (xn eq null)
+ y eq null
+ else
+ xn.equals(y)
+ }
+ }
+
+ def equalsNumNum(xn: java.lang.Number, yn: java.lang.Number): Boolean = {
+ (xn: Any) match {
+ case xn: Double =>
+ (yn: Any) match {
+ case yn: Double => xn == yn
+ case yn: Long => xn == yn
+ case yn: ScalaNumber => yn.equals(xn) // xn is not a ScalaNumber
+ case _ => false // xn.equals(yn) must be false here
+ }
+ case xn: Long =>
+ (yn: Any) match {
+ case yn: Long => xn == yn
+ case yn: Double => xn == yn
+ case yn: ScalaNumber => yn.equals(xn) // xn is not a ScalaNumber
+ case _ => false // xn.equals(yn) must be false here
+ }
+ case null => yn eq null
+ case _ => xn.equals(yn)
+ }
+ }
+
+ def equalsCharObject(xc: java.lang.Character, y: Object): Boolean = {
+ y match {
+ case yc: java.lang.Character => xc.charValue() == yc.charValue()
+ case yn: java.lang.Number => equalsNumChar(yn, xc)
+ case _ =>
+ if (xc eq null)
+ y eq null
+ else
+ false // xc.equals(y) must be false here, because y is not a Char
+ }
+ }
+
+ @inline
+ private def equalsNumChar(xn: java.lang.Number, yc: java.lang.Character): Boolean = {
+ (xn: Any) match {
+ case xn: Double => xn == yc.charValue()
+ case xn: Long => xn == yc.charValue()
+ case _ =>
+ if (xn eq null) yc eq null
+ else xn.equals(yc)
+ }
+ }
+
+ def hashFromLong(n: java.lang.Long): Int = {
+ val iv = n.intValue()
+ if (iv == n.longValue()) iv
+ else n.hashCode()
+ }
+
+ def hashFromDouble(n: java.lang.Double): Int = {
+ val iv = n.intValue()
+ val dv = n.doubleValue()
+ if (iv == dv) {
+ iv
+ } else {
+ val lv = n.longValue()
+ if (lv == dv) {
+ java.lang.Long.valueOf(lv).hashCode()
+ } else {
+ // don't test the case floatValue() == dv
+ n.hashCode()
+ }
+ }
+ }
+
+ def hashFromFloat(n: java.lang.Float): Int = {
+ hashFromDouble(java.lang.Double.valueOf(n.doubleValue()))
+ }
+
+ def hashFromNumber(n: java.lang.Number): Int = {
+ (n: Any) match {
+ case n: Int => n
+ case n: java.lang.Long => hashFromLong(n)
+ case n: java.lang.Double => hashFromDouble(n)
+ case n => n.hashCode()
+ }
+ }
+
+ def hashFromObject(a: Object): Int = {
+ a match {
+ case a: java.lang.Number => hashFromNumber(a)
+ case a => a.hashCode()
+ }
+ }
+}
diff --git a/examples/scala-js/scalalib/overrides/scala/util/control/NoStackTrace.scala b/examples/scala-js/scalalib/overrides/scala/util/control/NoStackTrace.scala
new file mode 100644
index 0000000..bcc2839
--- /dev/null
+++ b/examples/scala-js/scalalib/overrides/scala/util/control/NoStackTrace.scala
@@ -0,0 +1,33 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala
+package util.control
+
+/** A trait for exceptions which, for efficiency reasons, do not
+ * fill in the stack trace. Stack trace suppression can be disabled
+ * on a global basis via a system property wrapper in
+ * [[scala.sys.SystemProperties]].
+ *
+ * @author Paul Phillips
+ * @since 2.8
+ */
+trait NoStackTrace extends Throwable {
+ override def fillInStackTrace(): Throwable =
+ if (NoStackTrace.noSuppression) super.fillInStackTrace()
+ else this
+}
+
+object NoStackTrace {
+ final def noSuppression = _noSuppression
+
+ // two-stage init to make checkinit happy, since sys.SystemProperties.noTraceSupression.value calls back into NoStackTrace.noSuppression
+ final private var _noSuppression = false
+ // !!! Disabled in Scala.js because SystemProperties is not supported
+ //_noSuppression = sys.SystemProperties.noTraceSupression.value
+}