summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-12 21:39:26 +0000
committerPaul Phillips <paulp@improving.org>2009-11-12 21:39:26 +0000
commit07c295560c191297b3e4dae591878913b6461f74 (patch)
tree954b799c8e9fb6f040d3db77929f3b548efbc731
parent523a9a265817aad06d9ed58507d3a1eea420f3ab (diff)
downloadscala-07c295560c191297b3e4dae591878913b6461f74.tar.gz
scala-07c295560c191297b3e4dae591878913b6461f74.tar.bz2
scala-07c295560c191297b3e4dae591878913b6461f74.zip
Moved those bits of Predef into the scala packa...
Moved those bits of Predef into the scala package object which would go without a fight.
-rw-r--r--src/library/scala/Predef.scala83
-rw-r--r--src/library/scala/package.scala25
-rw-r--r--src/library/scala/runtime/StreamCons.scala17
3 files changed, 55 insertions, 70 deletions
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index d220b922c3..892e90d581 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -20,14 +20,12 @@ import collection.generic.CanBuildFrom
* qualification.
*/
object Predef extends LowPriorityImplicits {
-
- // classOf dummy ------------------------------------------------------
-
- /** Return the runtime representation of a class type. */
+ /** Return the runtime representation of a class type. This is a stub method.
+ * The actual implementation is filled in by the compiler.
+ */
def classOf[T]: Class[T] = null
// aliases ------------------------------------------------------------
-
@deprecated("lower-case type aliases will be removed") type byte = scala.Byte
@deprecated("lower-case type aliases will be removed") type short = scala.Short
@deprecated("lower-case type aliases will be removed") type char = scala.Char
@@ -40,37 +38,16 @@ object Predef extends LowPriorityImplicits {
type String = java.lang.String
type Class[T] = java.lang.Class[T]
- type Runnable = java.lang.Runnable
-
- 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
// miscelleaneous -----------------------------------------------------
-
- private val P = scala.`package` // to force scala package object to be seen.
- private val L = scala.collection.immutable.List // to force Nil, :: to be seen.
- private val S = scala.collection.mutable.StringBuilder // to force StringBuilder to be seen.
-
- val $scope = scala.xml.TopScope
+ scala.`package` // to force scala package object to be seen.
+ scala.collection.immutable.List // to force Nil, :: to be seen.
+ scala.collection.mutable.StringBuilder // to force StringBuilder to be seen.
type Function[-A, +B] = Function1[A, B]
type Map[A, +B] = collection.immutable.Map[A, B]
type Set[A] = collection.immutable.Set[A]
-
val Map = collection.immutable.Map
val Set = collection.immutable.Set
@@ -80,7 +57,6 @@ object Predef extends LowPriorityImplicits {
def manifest[T](implicit m: Manifest[T]) = m
def classManifest[T](implicit m: ClassManifest[T]) = m
- // will soon stop being a view: subsumed by `conforms` (which is less likely to give rise to ambiguities)
// @see `conforms` for the implicit version
def identity[A](x: A): A = x
@@ -152,6 +128,14 @@ object Predef extends LowPriorityImplicits {
throw new IllegalArgumentException("requirement failed: "+ message)
}
+ class Ensuring[A](x: A) {
+ def ensuring(cond: Boolean): A = { assert(cond); x }
+ def ensuring(cond: Boolean, msg: Any): A = { assert(cond, msg); x }
+ def ensuring(cond: A => Boolean): A = { assert(cond(x)); x }
+ def ensuring(cond: A => Boolean, msg: Any): A = { assert(cond(x), msg); x }
+ }
+ implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x)
+
// tupling ------------------------------------------------------------
type Pair[+A, +B] = Tuple2[A, B]
@@ -166,14 +150,6 @@ object Predef extends LowPriorityImplicits {
def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x)
}
- class Ensuring[A](x: A) {
- def ensuring(cond: Boolean): A = { assert(cond); x }
- def ensuring(cond: Boolean, msg: Any): A = { assert(cond, msg); x }
- def ensuring(cond: A => Boolean): A = { assert(cond(x)); x }
- def ensuring(cond: A => Boolean, msg: Any): A = { assert(cond(x), msg); x }
- }
- implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x)
-
class ArrowAssoc[A](x: A) {
def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y)
def →[B](y: B): Tuple2[A, B] = ->(y)
@@ -222,19 +198,9 @@ object Predef extends LowPriorityImplicits {
implicit def longWrapper(x: Long) = new runtime.RichLong(x)
implicit def floatWrapper(x: Float) = new runtime.RichFloat(x)
implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x)
-
implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x)
- implicit def augmentString(x: String): StringOps = new StringOps(x)
- implicit def unaugmentString(x: StringOps): String = x.repr
-
- implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] =
- new CanBuildFrom[String, Char, String] {
- def apply(from: String) = new scala.collection.mutable.StringBuilder
- def apply() = new scala.collection.mutable.StringBuilder
- }
-
- implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
+ implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc)
implicit def genericArrayOps[T](xs: Array[T]): ArrayOps[T] = (xs: AnyRef) match { // !!! drop the AnyRef and get unreachable code errors!
case x: Array[AnyRef] => refArrayOps[AnyRef](x).asInstanceOf[ArrayOps[T]]
@@ -261,7 +227,7 @@ object Predef extends LowPriorityImplicits {
implicit def booleanArrayOps(xs: Array[Boolean]): ArrayOps[Boolean] = new ArrayOps.ofBoolean(xs)
implicit def unitArrayOps(xs: Array[Unit]): ArrayOps[Unit] = new ArrayOps.ofUnit(xs)
- implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc)
+ // Primitive Widenings --------------------------------------------------------------
implicit def byte2short(x: Byte): Short = x.toShort
implicit def byte2int(x: Byte): Int = x.toInt
@@ -288,6 +254,8 @@ object Predef extends LowPriorityImplicits {
implicit def float2double(x: Float): Double = x.toDouble
+ // "Autoboxing" --------------------------------------------------------------
+
implicit def byte2Byte(x: Byte) = java.lang.Byte.valueOf(x)
implicit def short2Short(x: Short) = java.lang.Short.valueOf(x)
implicit def char2Character(x: Char) = java.lang.Character.valueOf(x)
@@ -297,10 +265,17 @@ object Predef extends LowPriorityImplicits {
implicit def double2Double(x: Double) = java.lang.Double.valueOf(x)
implicit def boolean2Boolean(x: Boolean) = java.lang.Boolean.valueOf(x)
- /** any array projection can be automatically converted into an array */
- //implicit def forceArrayProjection[A](x: Array.Projection[A]): Array[A] = x.force !!! re-enable?
+ // Strings and CharSequences --------------------------------------------------------------
- //implicit def lazyStreamToConsable[A](xs: => Stream[A]) = new runtime.StreamCons(xs)
+ implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
+ implicit def augmentString(x: String): StringOps = new StringOps(x)
+ implicit def unaugmentString(x: StringOps): String = x.repr
+
+ implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] =
+ new CanBuildFrom[String, Char, String] {
+ def apply(from: String) = new scala.collection.mutable.StringBuilder
+ def apply() = new scala.collection.mutable.StringBuilder
+ }
implicit def seqToCharSequence(xs: collection.IndexedSeq[Char]): CharSequence = new CharSequence {
def length: Int = xs.length
@@ -316,6 +291,8 @@ object Predef extends LowPriorityImplicits {
override def toString: String = xs.mkString("")
}
+ // Type Constraints --------------------------------------------------------------
+
// used, for example, in the encoding of generalized constraints
// we need a new type constructor `<:<` and evidence `conforms`, as
// reusing `Function2` and `identity` leads to ambiguities (any2stringadd is inferred)
diff --git a/src/library/scala/package.scala b/src/library/scala/package.scala
index e45e5cebe7..7c25757e57 100644
--- a/src/library/scala/package.scala
+++ b/src/library/scala/package.scala
@@ -10,6 +10,21 @@
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 Traversable[+A] = scala.collection.Traversable[A]
val Traversable = scala.collection.Traversable
@@ -49,6 +64,11 @@ package object scala {
type Range = scala.collection.immutable.Range
val Range = scala.collection.immutable.Range
+ // Migrated from Predef
+
+ val $scope = scala.xml.TopScope
+ def currentThread = java.lang.Thread.currentThread()
+
// Numeric types which were moved into scala.math.*
type BigDecimal = scala.math.BigDecimal
@@ -73,6 +93,11 @@ package object scala {
type PartialOrdering[T] = scala.math.PartialOrdering[T]
type PartiallyOrdered[T] = scala.math.PartiallyOrdered[T]
+ @deprecated("use <code>java.lang.Integer</code> instead")
+ type Integer = java.lang.Integer
+ @deprecated("use <code>java.lang.Character</code> instead")
+ type Character = java.lang.Character
+
@deprecated("use Iterable instead") type Collection[+A] = Iterable[A]
@deprecated("use Iterable instead") val Collection = Iterable
diff --git a/src/library/scala/runtime/StreamCons.scala b/src/library/scala/runtime/StreamCons.scala
deleted file mode 100644
index 96b236f8cf..0000000000
--- a/src/library/scala/runtime/StreamCons.scala
+++ /dev/null
@@ -1,17 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime
-
-final class StreamCons[T](xs: => Stream[T]) {
- def lazy_:: (x: T): Stream[T] = Stream.cons(x, xs)
- def lazy_::: (ys: Stream[T]): Stream[T] = ys append xs
-}