summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-04 17:15:18 +0000
committerPaul Phillips <paulp@improving.org>2010-02-04 17:15:18 +0000
commit67b215e9746dcd1f1ceeb54017eb1deeffbed940 (patch)
treecc7f8ba1612ee452423b58adb0dae4d9ae354a52 /src
parent429da0c3c7105510a29fcacd746916431e86d3e2 (diff)
downloadscala-67b215e9746dcd1f1ceeb54017eb1deeffbed940.tar.gz
scala-67b215e9746dcd1f1ceeb54017eb1deeffbed940.tar.bz2
scala-67b215e9746dcd1f1ceeb54017eb1deeffbed940.zip
Some hardening in the repl, and removing some f...
Some hardening in the repl, and removing some functions which now exist in the standard library. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala25
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala7
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Parsed.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/package.scala6
-rw-r--r--src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala6
-rw-r--r--src/library/scala/util/Properties.scala1
6 files changed, 29 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 4ae0540d8b..49ce29a7ff 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -220,16 +220,16 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
private val boundNameMap = new HashMap[Name, Request]()
private def allHandlers = prevRequests.toList flatMap (_.handlers)
- /** Most recent handler which wasn't wholly synthetic. */
- private def mostRecentHandler: MemberHandler = {
+ /** Most recent tree handled which wasn't wholly synthetic. */
+ private def mostRecentlyHandledTree: Option[Tree] = {
for {
req <- prevRequests.reverse
handler <- req.handlers.reverse
name <- handler.generatesValue
if !isSynthVarName(name)
- } return handler
+ } return Some(handler.member)
- error("No handlers found.")
+ None
}
def recordRequest(req: Request) {
@@ -503,7 +503,8 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
}
private[nsc] val powerMkImports = List(
- "mkContext", "mkTree", "mkTrees", "mkAlias", "mkSourceFile", "mkUnit", "mkType", "mkTypedTree", "mkTypedTrees"
+ "mkContext", "mkTree", "mkTrees", "mkAlias", "mkSourceFile", "mkUnit", "mkType", "mkTypedTree", "mkTypedTrees",
+ "treeWrapper"
)
/** Compile an nsc SourceFile. Returns true if there are
@@ -1022,12 +1023,14 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
* Mostly this exists so you can conveniently invoke methods on
* the previous result.
*/
- def mostRecentVar: String = mostRecentHandler.member match {
- case x: ValOrDefDef => x.name
- case Assign(Ident(name), _) => name
- case ModuleDef(_, name, _) => name
- case _ => varNameCreator.mostRecent
- }
+ def mostRecentVar: String =
+ if (mostRecentlyHandledTree.isEmpty) ""
+ else mostRecentlyHandledTree.get match {
+ case x: ValOrDefDef => x.name
+ case Assign(Ident(name), _) => name
+ case ModuleDef(_, name, _) => name
+ case _ => onull(varNameCreator.mostRecent)
+ }
private def requestForName(name: Name): Option[Request] =
prevRequests.reverse find (_.boundNames contains name)
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index edfae44a1f..c5261f8c10 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -16,8 +16,8 @@ class Settings(errorFn: String => Unit) extends ScalacSettings {
def this() = this(Console.println)
// optionizes a system property
- private def syspropopt(name: String): Option[String] = onull(System.getProperty(name))
- private def sysenvopt(name: String): Option[String] = onull(System.getenv(name))
+ private def syspropopt(name: String): Option[String] = Option(System.getProperty(name))
+ private def sysenvopt(name: String): Option[String] = Option(System.getenv(name))
// given any number of possible path segments, flattens down to a
// :-separated style path
@@ -43,9 +43,8 @@ class Settings(errorFn: String => Unit) extends ScalacSettings {
protected def pluginsDirDefault =
guess(List("misc", "scala-devel", "plugins"), _.isDirectory) getOrElse ""
- def onull[T <: AnyRef](x: T): Option[T] = if (x eq null) None else Some(x)
def mkPath(base: String, segments: String*) = new File(base, segments.mkString(File.separator))
- def scalaHome: Option[String] = onull(Properties.scalaHome)
+ def scalaHome: Option[String] = Option(Properties.scalaHome)
// examine path relative to scala home and return Some(path) if it meets condition
private def guess(xs: List[String], cond: (File) => Boolean): Option[String] = {
diff --git a/src/compiler/scala/tools/nsc/interpreter/Parsed.scala b/src/compiler/scala/tools/nsc/interpreter/Parsed.scala
index 05cb2641cd..b130396cc6 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Parsed.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Parsed.scala
@@ -51,7 +51,6 @@ class Parsed private (
}
object Parsed {
- def onull(s: String) = if (s == null) "" else s
def apply(s: String): Parsed = apply(onull(s), onull(s).length)
def apply(s: String, cursor: Int): Parsed = apply(onull(s), cursor, "(){},`; \t" contains _)
def apply(s: String, cursor: Int, delimited: Char => Boolean): Parsed =
diff --git a/src/compiler/scala/tools/nsc/interpreter/package.scala b/src/compiler/scala/tools/nsc/interpreter/package.scala
index 767bc9ca2f..2ded3a7900 100644
--- a/src/compiler/scala/tools/nsc/interpreter/package.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/package.scala
@@ -12,6 +12,12 @@ package object interpreter {
/** Tracing */
def tracing[T](msg: String)(x: T): T = { println("(" + msg + ") " + x) ; x }
+ /** Frequency counter */
+ def freq[T](seq: Seq[T]) = seq groupBy identity mapValues (_.length)
+
+ /** null becomes "", otherwise identity */
+ def onull(s: String) = if (s == null) "" else s
+
/** Class objects */
def classForName(name: String): Option[Class[_]] =
try Some(Class forName name)
diff --git a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
index 95110d6b81..9d65a3b2aa 100644
--- a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
+++ b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
@@ -91,6 +91,7 @@ object ScalaClassLoader {
search(getContextLoader())
}
+ /** The actual bytes for a class file, or an empty array if it can't be found. */
def findBytesForClassName(s: String): Array[Byte] = {
val name = s.replaceAll("""\.""", "/") + ".class"
val url = getSystemLoader.getResource(name)
@@ -98,4 +99,9 @@ object ScalaClassLoader {
if (url == null) Array()
else new io.Streamable.Bytes { def inputStream() = url.openStream } . toByteArray()
}
+
+ /** Finding what jar a clazz or instance came from */
+ def origin(x: Any): Option[URL] = originOfClass(x.asInstanceOf[AnyRef].getClass)
+ def originOfClass(x: Class[_]): Option[URL] =
+ Option(x.getProtectionDomain.getCodeSource) flatMap (x => Option(x.getLocation))
}
diff --git a/src/library/scala/util/Properties.scala b/src/library/scala/util/Properties.scala
index 450738b21d..ee3e68ed76 100644
--- a/src/library/scala/util/Properties.scala
+++ b/src/library/scala/util/Properties.scala
@@ -30,7 +30,6 @@ private[scala] trait PropertiesTrait
props
}
- protected def onull[T <: AnyRef](x: T) = if (x eq null) None else Some(x)
private def quietlyDispose(action: => Unit, disposal: => Unit) =
try { action }
finally {