Pretty print tuples in the repl. Closes #3655, no review.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@22829 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
38709ac48c
commit
6ca71c2315
|
@ -240,10 +240,11 @@ object ScalaRunTime {
|
|||
// maxPrintString limit will kick in way before this
|
||||
val maxElements = 10000
|
||||
|
||||
def isScalaClass(x: AnyRef) = {
|
||||
val pkg = x.getClass.getPackage
|
||||
(pkg != null) && (pkg.getName startsWith "scala.")
|
||||
}
|
||||
def isScalaClass(x: AnyRef) =
|
||||
Option(x.getClass.getPackage) exists (_.getName startsWith "scala.")
|
||||
|
||||
def isTuple(x: AnyRef) =
|
||||
x.getClass.getName matches """^scala\.Tuple(\d+).*"""
|
||||
|
||||
// When doing our own iteration is dangerous
|
||||
def useOwnToString(x: Any) = x match {
|
||||
|
@ -268,6 +269,8 @@ object ScalaRunTime {
|
|||
case x if useOwnToString(x) => x.toString
|
||||
case x: AnyRef if isArray(x) => WrappedArray make x map inner mkString ("Array(", ", ", ")")
|
||||
case x: Traversable[_] => x take maxElements map inner mkString (x.stringPrefix + "(", ", ", ")")
|
||||
case x: Product1[_] if isTuple(x) => "(" + inner(x._1) + ",)" // that special trailing comma
|
||||
case x: Product if isTuple(x) => x.productIterator map inner mkString ("(", ",", ")")
|
||||
case x => x toString
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue