diff options
author | Seth Tisue <seth@tisue.net> | 2016-10-26 10:16:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-26 10:16:02 -0700 |
commit | 92db1dcc7f9bf7161bb986060d7151f86d5fca66 (patch) | |
tree | c4f5feff25613920a031b52285e3f19126d4e59b /src/compiler/scala | |
parent | eff0aabb7824513498a4081072845001dbe4897f (diff) | |
parent | 10336958aba9b8af5f9127a4dc21c0899836ff8d (diff) | |
download | scala-92db1dcc7f9bf7161bb986060d7151f86d5fca66.tar.gz scala-92db1dcc7f9bf7161bb986060d7151f86d5fca66.tar.bz2 scala-92db1dcc7f9bf7161bb986060d7151f86d5fca66.zip |
Merge pull request #5276 from som-snytt/issue/9750
SI-9750 scala.util.Properties.isJavaAtLeast works with JDK9
Diffstat (limited to 'src/compiler/scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/StackTracing.scala | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/util/StackTracing.scala b/src/compiler/scala/tools/nsc/util/StackTracing.scala index 0765bb923f..c6749a13f3 100644 --- a/src/compiler/scala/tools/nsc/util/StackTracing.scala +++ b/src/compiler/scala/tools/nsc/util/StackTracing.scala @@ -8,7 +8,7 @@ private[util] trait StackTracing extends Any { /** Format a stack trace, returning the prefix consisting of frames that satisfy * a given predicate. - * The format is similar to the typical case described in the JavaDoc + * The format is similar to the typical case described in the Javadoc * for [[java.lang.Throwable#printStackTrace]]. * If a stack trace is truncated, it will be followed by a line of the form * `... 3 elided`, by analogy to the lines `... 3 more` which indicate @@ -19,25 +19,18 @@ private[util] trait StackTracing extends Any { def stackTracePrefixString(e: Throwable)(p: StackTraceElement => Boolean): String = { import collection.mutable.{ ArrayBuffer, ListBuffer } import compat.Platform.EOL - import scala.util.Properties.isJavaAtLeast - - val sb = ListBuffer.empty[String] type TraceRelation = String val Self = new TraceRelation("") val CausedBy = new TraceRelation("Caused by: ") val Suppressed = new TraceRelation("Suppressed: ") - val suppressable = isJavaAtLeast("1.7") - - def clazz(e: Throwable) = e.getClass.getName + def clazz(e: Throwable): String = e.getClass.getName def because(e: Throwable): String = e.getCause match { case null => null ; case c => header(c) } def msg(e: Throwable): String = e.getMessage match { case null => because(e) ; case s => s } def txt(e: Throwable): String = msg(e) match { case null => "" ; case s => s": $s" } def header(e: Throwable): String = s"${clazz(e)}${txt(e)}" - val indent = "\u0020\u0020" - val seen = new ArrayBuffer[Throwable](16) def unseen(t: Throwable) = { def inSeen = seen exists (_ eq t) @@ -46,28 +39,25 @@ private[util] trait StackTracing extends Any { interesting } + val sb = ListBuffer.empty[String] + + // format the stack trace, skipping the shared trace def print(e: Throwable, r: TraceRelation, share: Array[StackTraceElement], indents: Int): Unit = if (unseen(e)) { val trace = e.getStackTrace - val frames = ( - if (share.nonEmpty) { - val spare = share.reverseIterator - val trimmed = trace.reverse dropWhile (spare.hasNext && spare.next == _) - trimmed.reverse - } else trace - ) - val prefix = frames takeWhile p - val margin = indent * indents - val indented = margin + indent + val frames = if (share.isEmpty) trace else { + val spare = share.reverseIterator + val trimmed = trace.reverse dropWhile (spare.hasNext && spare.next == _) + trimmed.reverse + } + val prefix = frames takeWhile p + val margin = " " * indents + val indent = margin + " " sb append s"${margin}${r}${header(e)}" - prefix foreach (f => sb append s"${indented}at $f") - if (frames.size < trace.size) sb append s"$indented... ${trace.size - frames.size} more" - if (r == Self && prefix.size < frames.size) sb append s"$indented... ${frames.size - prefix.size} elided" + prefix foreach (f => sb append s"${margin} at $f") + if (frames.size < trace.size) sb append s"${margin} ... ${trace.size - frames.size} more" + if (r == Self && prefix.size < frames.size) sb append s"${margin} ... ${frames.size - prefix.size} elided" print(e.getCause, CausedBy, trace, indents) - if (suppressable) { - import scala.language.reflectiveCalls - type Suppressing = { def getSuppressed(): Array[Throwable] } - for (s <- e.asInstanceOf[Suppressing].getSuppressed) print(s, Suppressed, frames, indents + 1) - } + e.getSuppressed foreach (t => print(t, Suppressed, frames, indents + 1)) } print(e, Self, share = Array.empty, indents = 0) |