diff options
author | Paul Phillips <paulp@improving.org> | 2010-11-13 03:18:12 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-11-13 03:18:12 +0000 |
commit | 6bf1e7a2684c19f21ebc6367a39bc3e19b32e321 (patch) | |
tree | 3d3284bf656edc70a66c736e472077cc67bf6008 /src/compiler/scala/tools/nsc/io/Path.scala | |
parent | a061def4dd3d16b226f17a5246470255623177c2 (diff) | |
download | scala-6bf1e7a2684c19f21ebc6367a39bc3e19b32e321.tar.gz scala-6bf1e7a2684c19f21ebc6367a39bc3e19b32e321.tar.bz2 scala-6bf1e7a2684c19f21ebc6367a39bc3e19b32e321.zip |
Another exciting development in the world of -Y...
Another exciting development in the world of -Y options which I and
three other people will use. Today's is -Yrich-exceptions. Use it like
so:
SOURCEPATH=/path/to/src scalac -Yrich-exceptions a.scala
In the repl, -Yrich-exceptions will cause lastException to be bound to
an Exceptional instead of old rusty Throwable. That spins up new powers:
scala> Nil.head
[Nil.head] (List.scala:389)
(access lastException for the full trace)
scala> lastException.show
/* The repl internal portion of the stack trace is elided. */
[Nil.head]
386: override def isEmpty = true
387: override def head: Nothing =
388: throw new NoSuchElementException("head of empty list")
*389: override def tail: List[Nothing] =
390: throw new UnsupportedOperationException("tail of empty list")
391: // Removal of equals method here might lead to an infinite recursion similar to IntMap.equals.
392: override def equals(that: Any) = that match {
[line0.<init>] (<console>:6)
[line0.<clinit>] (<console>:-1)
Also try "lastException.showTable" but this is getting a little long for
more excerpt. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io/Path.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Path.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala index 4373cc64a5..5d3fcee11e 100644 --- a/src/compiler/scala/tools/nsc/io/Path.scala +++ b/src/compiler/scala/tools/nsc/io/Path.scala @@ -1,5 +1,6 @@ /* NSC -- new Scala compiler * Copyright 2005-2010 LAMP/EPFL + * @author Paul Phillips */ package scala.tools.nsc @@ -41,6 +42,21 @@ object Path { implicit def string2path(s: String): Path = apply(s) implicit def jfile2path(jfile: JFile): Path = apply(jfile) + def locateJarByClass(clazz: Class[_]): Option[File] = { + try Some(File(clazz.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())) + catch { case _: Exception => None } + } + /** Walks upward from wherever the scala library jar is searching for + * the given jar name. This approach finds the scala library jar in the + * release layout and in trunk builds going up from pack. + */ + def locateJarByName(name: String): Option[File] = { + def toSrc(d: Directory) = d.dirs.toList map (_ / name) + def walk(d: Directory) = d.parents flatMap toSrc find (_.isFile) map (_.toFile) + + locateJarByClass(classOf[ScalaObject]) flatMap (x => walk(x.parent)) + } + // java 7 style, we don't use it yet // object AccessMode extends Enumeration("AccessMode") { // val EXECUTE, READ, WRITE = Value |