1
1
package org .portablescala .reflect
2
2
3
3
import scala .language .experimental .macros
4
-
5
4
import scala .collection .mutable
6
-
7
5
import java .lang .reflect ._
8
-
9
6
import org .portablescala .reflect .annotation ._
7
+ import org .portablescala .reflect .internal .Macros
10
8
11
9
object 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
31
10
32
11
/** Reflectively looks up a loadable module class using the current class
33
12
* loader.
@@ -52,17 +31,7 @@ object Reflect {
52
31
* Fully-qualified name of the module class, including its trailing `$`
53
32
*/
54
33
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
66
35
67
36
/** Reflectively looks up a loadable module class.
68
37
*
@@ -111,17 +80,7 @@ object Reflect {
111
80
* Fully-qualified name of the class
112
81
*/
113
82
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
125
84
126
85
/** Reflectively looks up an instantiatable class.
127
86
*
@@ -147,18 +106,6 @@ object Reflect {
147
106
load(fqcn, loader).filter(isInstantiatableClass).map(new InstantiatableClass (_))
148
107
}
149
108
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
-
162
109
private def isModuleClass (clazz : Class [_]): Boolean = {
163
110
try {
164
111
val fld = clazz.getField(" MODULE$" )
0 commit comments