11package org .portablescala .reflect
22
33import scala .language .experimental .macros
4-
54import scala .collection .mutable
6-
75import java .lang .reflect ._
8-
96import org .portablescala .reflect .annotation ._
7+ import org .portablescala .reflect .internal .Macros
108
119object Reflect {
12- /** Magic to get cross-compiling access to `blackbox.Context` with a fallback
13- * on `macros.Context`, without deprecation warning in any Scala version.
14- */
15- private object MacroCompat {
16- object Scope1 {
17- object blackbox
18- }
19- import Scope1 ._
20-
21- object Scope2 {
22- import scala .reflect .macros ._
23- object Inner {
24- import blackbox ._
25- type BlackboxContext = Context
26- }
27- }
28- }
29-
30- import MacroCompat .Scope2 .Inner .BlackboxContext
3110
3211 /** Reflectively looks up a loadable module class using the current class
3312 * loader.
@@ -52,17 +31,7 @@ object Reflect {
5231 * Fully-qualified name of the module class, including its trailing `$`
5332 */
5433 def lookupLoadableModuleClass (fqcn : String ): Option [LoadableModuleClass ] =
55- macro lookupLoadableModuleClass_impl
56-
57- def lookupLoadableModuleClass_impl (
58- c : BlackboxContext { type PrefixType = Reflect .type })(
59- fqcn : c.Expr [String ]): c.Expr [Option [LoadableModuleClass ]] = {
60- import c .universe ._
61- val loaderExpr = currentClassLoaderExpr(c)
62- reify {
63- c.prefix.splice.lookupLoadableModuleClass(fqcn.splice, loaderExpr.splice)
64- }
65- }
34+ macro Macros .lookupLoadableModuleClass
6635
6736 /** Reflectively looks up a loadable module class.
6837 *
@@ -111,17 +80,7 @@ object Reflect {
11180 * Fully-qualified name of the class
11281 */
11382 def lookupInstantiatableClass (fqcn : String ): Option [InstantiatableClass ] =
114- macro lookupInstantiatableClass_impl
115-
116- def lookupInstantiatableClass_impl (
117- c : BlackboxContext { type PrefixType = Reflect .type })(
118- fqcn : c.Expr [String ]): c.Expr [Option [InstantiatableClass ]] = {
119- import c .universe ._
120- val loaderExpr = currentClassLoaderExpr(c)
121- reify {
122- c.prefix.splice.lookupInstantiatableClass(fqcn.splice, loaderExpr.splice)
123- }
124- }
83+ macro Macros .lookupInstantiatableClass
12584
12685 /** Reflectively looks up an instantiatable class.
12786 *
@@ -147,18 +106,6 @@ object Reflect {
147106 load(fqcn, loader).filter(isInstantiatableClass).map(new InstantiatableClass (_))
148107 }
149108
150- private def currentClassLoaderExpr (
151- c : BlackboxContext { type PrefixType = Reflect .type }): c.Expr [ClassLoader ] = {
152- import c .universe ._
153- val enclosingClassTree = c.reifyEnclosingRuntimeClass
154- if (enclosingClassTree.isEmpty)
155- c.abort(c.enclosingPosition, " call site does not have an enclosing class" )
156- val enclosingClassExpr = c.Expr [java.lang.Class [_]](enclosingClassTree)
157- reify {
158- enclosingClassExpr.splice.getClassLoader()
159- }
160- }
161-
162109 private def isModuleClass (clazz : Class [_]): Boolean = {
163110 try {
164111 val fld = clazz.getField(" MODULE$" )
0 commit comments