blob: 450cb4d9ea1f3e0ac6004d2e283f67d524a2b080 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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 =>
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]]: _*)
}
}
}
}
|