summaryrefslogtreecommitdiff
path: root/src/library/scala/reflect/ReflectionUtils.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-01-20 01:52:40 +0100
committerEugene Burmako <xeno.by@gmail.com>2012-01-20 06:54:20 +0100
commit35e676ded0f9bfd006a5f090841abdea3ff1759c (patch)
treeade8247e0ebc66964189875194f78b85c6596d27 /src/library/scala/reflect/ReflectionUtils.scala
parent58cb15c40dc431e45eaa0a5278874d9996e42104 (diff)
downloadscala-35e676ded0f9bfd006a5f090841abdea3ff1759c.tar.gz
scala-35e676ded0f9bfd006a5f090841abdea3ff1759c.tar.bz2
scala-35e676ded0f9bfd006a5f090841abdea3ff1759c.zip
Progress with macros
A short recap: * Macro expansion now works finely for instance macro invocations * Macros are now hidden behind -Xmacros * Bodies of macros now have "import _context._" in their preamble * Macros are now loaded from classpath, much like regular libraries * Macros can now override methods (in that case macro expansion does not crash if macro is not found, it just falls back to super) Review by @odersky.
Diffstat (limited to 'src/library/scala/reflect/ReflectionUtils.scala')
-rw-r--r--src/library/scala/reflect/ReflectionUtils.scala12
1 files changed, 8 insertions, 4 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 }
- }
}