diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-06-03 11:08:50 -0700 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-06-03 11:08:50 -0700 |
commit | 69887ddd682057c4787e2e4377830390faf8ecf1 (patch) | |
tree | 1158f24dd50dac397e867a6d2d861171e7335c4f /src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala | |
parent | c1cd65bb5276b715141df6d09fc95b0c44d2b4c2 (diff) | |
parent | 82f0925b69db8b5f9a3b10f58926c574433ca423 (diff) | |
download | scala-69887ddd682057c4787e2e4377830390faf8ecf1.tar.gz scala-69887ddd682057c4787e2e4377830390faf8ecf1.tar.bz2 scala-69887ddd682057c4787e2e4377830390faf8ecf1.zip |
Merge pull request #2577 from scalamacros/pullrequest/paradise
Backport from paradise/macros
Diffstat (limited to 'src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala')
-rw-r--r-- | src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala b/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala new file mode 100644 index 0000000000..3ef11fad9d --- /dev/null +++ b/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala @@ -0,0 +1,31 @@ +package scala.reflect.macros +package runtime + +import scala.reflect.runtime.ReflectionUtils +import scala.reflect.macros.{Context => ApiContext} + +trait JavaReflectionRuntimes { + self: scala.tools.nsc.typechecker.Analyzer => + + trait JavaReflectionResolvers { + self: MacroRuntimeResolver => + + import global._ + + def resolveJavaReflectionRuntime(classLoader: ClassLoader): MacroRuntime = { + val implClass = Class.forName(className, true, classLoader) + val implMeths = implClass.getDeclaredMethods.find(_.getName == methName) + // relies on the fact that macro impls cannot be overloaded + // so every methName can resolve to at maximum one method + val implMeth = implMeths getOrElse { throw new NoSuchMethodException(s"$className.$methName") } + macroLogVerbose(s"successfully loaded macro impl as ($implClass, $implMeth)") + args => { + val implObj = + if (isBundle) implClass.getConstructor(classOf[ApiContext]).newInstance(args.c) + else ReflectionUtils.staticSingletonInstance(implClass) + val implArgs = if (isBundle) args.others else args.c +: args.others + implMeth.invoke(implObj, implArgs.asInstanceOf[Seq[AnyRef]]: _*) + } + } + } +}
\ No newline at end of file |