summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-01-19 22:08:11 -0800
committerPaul Phillips <paulp@improving.org>2012-01-19 22:08:11 -0800
commit7a7e049c205a0dda6666f158b1b37558bf214e90 (patch)
treeeab288d9916db45832b66de1e15a1fe774f316ce /src/library
parent14ef1090325c3b85aa8c2dd7911445ec7e934743 (diff)
parent35e676ded0f9bfd006a5f090841abdea3ff1759c (diff)
downloadscala-7a7e049c205a0dda6666f158b1b37558bf214e90.tar.gz
scala-7a7e049c205a0dda6666f158b1b37558bf214e90.tar.bz2
scala-7a7e049c205a0dda6666f158b1b37558bf214e90.zip
Merge remote-tracking branch 'kepler/topic/macros' into develop
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/reflect/ReflectionUtils.scala12
-rw-r--r--src/library/scala/reflect/api/Mirror.scala6
-rw-r--r--src/library/scala/reflect/macro/Context.scala (renamed from src/library/scala/reflect/api/MacroContext.scala)6
-rw-r--r--src/library/scala/reflect/package.scala2
4 files changed, 17 insertions, 9 deletions
diff --git a/src/library/scala/reflect/ReflectionUtils.scala b/src/library/scala/reflect/ReflectionUtils.scala
index b63a8645de..dfadfb4976 100644
--- a/src/library/scala/reflect/ReflectionUtils.scala
+++ b/src/library/scala/reflect/ReflectionUtils.scala
@@ -27,11 +27,15 @@ object ReflectionUtils {
case ex if pf isDefinedAt unwrapThrowable(ex) => pf(unwrapThrowable(ex))
}
- // Retrieves the MODULE$ field for the given class name.
- def singletonInstance(className: String, cl: ClassLoader = getClass.getClassLoader): Option[AnyRef] = {
+ def singletonInstance(className: String, cl: ClassLoader = getClass.getClassLoader): AnyRef = {
val name = if (className endsWith "$") className else className + "$"
+ val clazz = java.lang.Class.forName(name, true, cl)
+ val singleton = clazz getField "MODULE$" get null
+ singleton
+ }
- try Some(java.lang.Class.forName(name, true, cl) getField "MODULE$" get null)
+ // Retrieves the MODULE$ field for the given class name.
+ def singletonInstanceOpt(className: String, cl: ClassLoader = getClass.getClassLoader): Option[AnyRef] =
+ try Some(singletonInstance(className, cl))
catch { case _: ClassNotFoundException => None }
- }
}
diff --git a/src/library/scala/reflect/api/Mirror.scala b/src/library/scala/reflect/api/Mirror.scala
index 53ac84f8cb..136f52b05f 100644
--- a/src/library/scala/reflect/api/Mirror.scala
+++ b/src/library/scala/reflect/api/Mirror.scala
@@ -13,7 +13,11 @@ trait Mirror extends Universe with RuntimeTypes with TreeBuildUtil {
* to do: throws anything else?
*/
def classWithName(name: String): Symbol
-
+
+ /** Return a reference to the companion object of this class symbol
+ */
+ def getCompanionObject(clazz: Symbol): AnyRef
+
/** The Scala class symbol corresponding to the runtime class of given object
* @param The object from which the class is returned
* @throws ?
diff --git a/src/library/scala/reflect/api/MacroContext.scala b/src/library/scala/reflect/macro/Context.scala
index e23357d26e..d0a2787fdf 100644
--- a/src/library/scala/reflect/api/MacroContext.scala
+++ b/src/library/scala/reflect/macro/Context.scala
@@ -1,7 +1,7 @@
package scala.reflect
-package api
+package macro
-trait MacroContext extends Universe {
+trait Context extends api.Universe {
/** Mark a variable as captured; i.e. force boxing in a *Ref type.
*/
@@ -12,4 +12,4 @@ trait MacroContext extends Universe {
*/
def referenceCapturedVariable(id: Ident): Tree
-} \ No newline at end of file
+}
diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala
index 62592baa27..1c3e618520 100644
--- a/src/library/scala/reflect/package.scala
+++ b/src/library/scala/reflect/package.scala
@@ -8,7 +8,7 @@ package object reflect {
// initialization, but in response to a doomed attempt to utilize it.
lazy val mirror: api.Mirror = {
// we use (Java) reflection here so that we can keep reflect.runtime and reflect.internals in a seperate jar
- ReflectionUtils.singletonInstance("scala.reflect.runtime.Mirror") collect { case x: api.Mirror => x } getOrElse {
+ ReflectionUtils.singletonInstanceOpt("scala.reflect.runtime.Mirror") collect { case x: api.Mirror => x } getOrElse {
throw new UnsupportedOperationException("Scala reflection not available on this platform")
}
}