|
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 | 10 |
|
13 | | - // Macro definitions are enclosed in a dedicated `Macros` object, |
14 | | - // so that their metadata (the types involved etc.) don't pollute `Reflect`'s metadata. |
15 | | - // This enables using `Reflect`'s methods without `scala-reflect` JAR |
16 | | - // https://github.com/scala/bug/issues/8090 |
17 | | - // https://github.com/xeno-by/sbt-example-paradise210/issues/1#issuecomment-20996354 |
18 | | - object Macros { |
19 | | - /** Magic to get cross-compiling access to `blackbox.Context` with a fallback |
20 | | - * on `macros.Context`, without deprecation warning in any Scala version. |
21 | | - */ |
22 | | - private object MacroCompat { |
23 | | - object Scope1 { |
24 | | - object blackbox |
25 | | - } |
26 | | - import Scope1._ |
27 | | - |
28 | | - object Scope2 { |
29 | | - import scala.reflect.macros._ |
30 | | - object Inner { |
31 | | - import blackbox._ |
32 | | - type BlackboxContext = Context |
33 | | - } |
34 | | - } |
35 | | - } |
36 | | - |
37 | | - import MacroCompat.Scope2.Inner.BlackboxContext |
38 | | - |
39 | | - private def currentClassLoaderExpr( |
40 | | - c: BlackboxContext { type PrefixType = Reflect.type }): c.Expr[ClassLoader] = { |
41 | | - import c.universe._ |
42 | | - val enclosingClassTree = c.reifyEnclosingRuntimeClass |
43 | | - if (enclosingClassTree.isEmpty) |
44 | | - c.abort(c.enclosingPosition, "call site does not have an enclosing class") |
45 | | - val enclosingClassExpr = c.Expr[java.lang.Class[_]](enclosingClassTree) |
46 | | - reify { |
47 | | - enclosingClassExpr.splice.getClassLoader() |
48 | | - } |
49 | | - } |
50 | | - |
51 | | - def lookupLoadableModuleClass( |
52 | | - c: BlackboxContext { type PrefixType = Reflect.type })( |
53 | | - fqcn: c.Expr[String]): c.Expr[Option[LoadableModuleClass]] = { |
54 | | - import c.universe._ |
55 | | - val loaderExpr = currentClassLoaderExpr(c) |
56 | | - reify { |
57 | | - c.prefix.splice.lookupLoadableModuleClass(fqcn.splice, loaderExpr.splice) |
58 | | - } |
59 | | - } |
60 | | - |
61 | | - def lookupInstantiatableClass( |
62 | | - c: BlackboxContext { type PrefixType = Reflect.type })( |
63 | | - fqcn: c.Expr[String]): c.Expr[Option[InstantiatableClass]] = { |
64 | | - import c.universe._ |
65 | | - val loaderExpr = currentClassLoaderExpr(c) |
66 | | - reify { |
67 | | - c.prefix.splice.lookupInstantiatableClass(fqcn.splice, loaderExpr.splice) |
68 | | - } |
69 | | - } |
70 | | - } |
71 | | - |
72 | 11 | /** Reflectively looks up a loadable module class using the current class |
73 | 12 | * loader. |
74 | 13 | * |
|
0 commit comments