summaryrefslogtreecommitdiff
path: root/test/instrumented/library/scala/runtime/ScalaRunTime.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-06-04 13:53:13 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-06-08 15:32:17 +0200
commit7b0f0a142bb526f4bd108a8c208ec9a8952398c9 (patch)
treeee13d036756be41521a9eb3f1e05898410ab744e /test/instrumented/library/scala/runtime/ScalaRunTime.scala
parentd9103e01b467634d61baa3b131aeb93fca9e20a5 (diff)
downloadscala-7b0f0a142bb526f4bd108a8c208ec9a8952398c9.tar.gz
scala-7b0f0a142bb526f4bd108a8c208ec9a8952398c9.tar.bz2
scala-7b0f0a142bb526f4bd108a8c208ec9a8952398c9.zip
repairs the tests after the refactoring spree
Diffstat (limited to 'test/instrumented/library/scala/runtime/ScalaRunTime.scala')
-rw-r--r--test/instrumented/library/scala/runtime/ScalaRunTime.scala32
1 files changed, 20 insertions, 12 deletions
diff --git a/test/instrumented/library/scala/runtime/ScalaRunTime.scala b/test/instrumented/library/scala/runtime/ScalaRunTime.scala
index 63908fcc29..f0d452a9be 100644
--- a/test/instrumented/library/scala/runtime/ScalaRunTime.scala
+++ b/test/instrumented/library/scala/runtime/ScalaRunTime.scala
@@ -14,6 +14,7 @@ import scala.collection.{ Seq, IndexedSeq, TraversableView, AbstractIterator }
import scala.collection.mutable.WrappedArray
import scala.collection.immutable.{ StringLike, NumericRange, List, Stream, Nil, :: }
import scala.collection.generic.{ Sorted }
+import scala.reflect.{ ArrayTag, ClassTag, arrayTag, classTag }
import scala.util.control.ControlThrowable
import scala.xml.{ Node, MetaData }
@@ -61,7 +62,7 @@ object ScalaRunTime {
*/
def arrayElementClass(schematic: Any): Class[_] = schematic match {
case cls: Class[_] => cls.getComponentType
- case tag: ClassTag[_] => tag.erasure
+ case tag: ClassTag[_] => tag.runtimeClass
case tag: ArrayTag[_] => tag.newArray(0).getClass.getComponentType
case _ => throw new UnsupportedOperationException("unsupported schematic %s (%s)".format(schematic, if (schematic == null) "null" else schematic.getClass))
}
@@ -71,7 +72,7 @@ object ScalaRunTime {
* rewrites expressions like 5.getClass to come here.
*/
def anyValClass[T <: AnyVal : ClassTag](value: T): Class[T] =
- classTag[T].erasure.asInstanceOf[Class[T]]
+ classTag[T].runtimeClass.asInstanceOf[Class[T]]
var arrayApplyCount = 0
@@ -142,16 +143,18 @@ object ScalaRunTime {
case null => throw new NullPointerException
}
- /** Convert a numeric value array to an object array.
+ /** Convert an array to an object array.
* Needed to deal with vararg arguments of primitive types that are passed
* to a generic Java vararg parameter T ...
*/
- def toObjectArray(src: AnyRef): Array[Object] = {
- val length = array_length(src)
- val dest = new Array[Object](length)
- for (i <- 0 until length)
- array_update(dest, i, array_apply(src, i))
- dest
+ def toObjectArray(src: AnyRef): Array[Object] = src match {
+ case x: Array[AnyRef] => x
+ case _ =>
+ val length = array_length(src)
+ val dest = new Array[Object](length)
+ for (i <- 0 until length)
+ array_update(dest, i, array_apply(src, i))
+ dest
}
def toArray[T](xs: collection.Seq[T]) = {
@@ -305,8 +308,12 @@ object ScalaRunTime {
*/
def stringOf(arg: Any): String = stringOf(arg, scala.Int.MaxValue)
def stringOf(arg: Any, maxElements: Int): String = {
- def isScalaClass(x: AnyRef) =
- Option(x.getClass.getPackage) exists (_.getName startsWith "scala.")
+ def packageOf(x: AnyRef) = x.getClass.getPackage match {
+ case null => ""
+ case p => p.getName
+ }
+ def isScalaClass(x: AnyRef) = packageOf(x) startsWith "scala."
+ def isScalaCompilerClass(x: AnyRef) = packageOf(x) startsWith "scala.tools.nsc."
// When doing our own iteration is dangerous
def useOwnToString(x: Any) = x match {
@@ -322,7 +329,8 @@ object ScalaRunTime {
case _: TraversableView[_, _] => true
// Don't want to a) traverse infinity or b) be overly helpful with peoples' custom
// collections which may have useful toString methods - ticket #3710
- case x: Traversable[_] => !x.hasDefiniteSize || !isScalaClass(x)
+ // or c) print AbstractFiles which are somehow also Iterable[AbstractFile]s.
+ case x: Traversable[_] => !x.hasDefiniteSize || !isScalaClass(x) || isScalaCompilerClass(x)
// Otherwise, nothing could possibly go wrong
case _ => false
}