@@ -111,14 +111,13 @@ object Splicer {
111
111
}
112
112
113
113
protected def interpretStaticMethodCall (fn : Tree , args : => List [Object ])(implicit env : Env ): Object = {
114
- if (fn.symbol == defn.NoneModuleRef .termSymbol) {
115
- // TODO generalize
116
- None
117
- } else {
118
- val (clazz, instance) = loadModule(fn.symbol.owner)
119
- val method = getMethod(clazz, fn.symbol.name, paramsSig(fn.symbol))
120
- stopIfRuntimeException(method.invoke(instance, args : _* ))
121
- }
114
+ val (clazz, instance) = loadModule(fn.symbol.owner)
115
+ val method = getMethod(clazz, fn.symbol.name, paramsSig(fn.symbol))
116
+ stopIfRuntimeException(method.invoke(instance, args : _* ))
117
+ }
118
+
119
+ protected def interpretModuleAccess (fn : Tree )(implicit env : Env ): Object = {
120
+ loadModule(fn.symbol.moduleClass)._2
122
121
}
123
122
124
123
protected def interpretNew (fn : RefTree , args : => List [Result ])(implicit env : Env ): Object = {
@@ -147,7 +146,7 @@ object Splicer {
147
146
try classLoader.loadClass(name.toString)
148
147
catch {
149
148
case _ : ClassNotFoundException =>
150
- val msg = s " Could not find macro class $name in classpath $extraMsg"
149
+ val msg = s " Could not find class $name in classpath $extraMsg"
151
150
throw new StopInterpretation (msg, pos)
152
151
}
153
152
}
@@ -156,7 +155,7 @@ object Splicer {
156
155
try clazz.getMethod(name.toString, paramClasses : _* )
157
156
catch {
158
157
case _ : NoSuchMethodException =>
159
- val msg = em " Could not find macro method ${clazz.getCanonicalName}. $name with parameters ( $paramClasses%, %) $extraMsg"
158
+ val msg = em " Could not find method ${clazz.getCanonicalName}. $name with parameters ( $paramClasses%, %) $extraMsg"
160
159
throw new StopInterpretation (msg, pos)
161
160
}
162
161
}
@@ -257,7 +256,8 @@ object Splicer {
257
256
protected def interpretVarargs (args : List [Boolean ])(implicit env : Env ): Boolean = args.forall(identity)
258
257
protected def interpretTastyContext ()(implicit env : Env ): Boolean = true
259
258
protected def interpretStaticMethodCall (fn : tpd.Tree , args : => List [Boolean ])(implicit env : Env ): Boolean = args.forall(identity)
260
- protected def interpretNew (fn : RefTree , args : => List [Result ])(implicit env : Env ): Boolean = args.forall(identity)
259
+ protected def interpretModuleAccess (fn : Tree )(implicit env : Env ): Boolean = true
260
+ protected def interpretNew (fn : RefTree , args : => List [Boolean ])(implicit env : Env ): Boolean = args.forall(identity)
261
261
262
262
def unexpectedTree (tree : tpd.Tree )(implicit env : Env ): Boolean = {
263
263
// Assuming that top-level splices can only be in inline methods
@@ -278,6 +278,7 @@ object Splicer {
278
278
protected def interpretVarargs (args : List [Result ])(implicit env : Env ): Result
279
279
protected def interpretTastyContext ()(implicit env : Env ): Result
280
280
protected def interpretStaticMethodCall (fn : Tree , args : => List [Result ])(implicit env : Env ): Result
281
+ protected def interpretModuleAccess (fn : Tree )(implicit env : Env ): Result
281
282
protected def interpretNew (fn : RefTree , args : => List [Result ])(implicit env : Env ): Result
282
283
protected def unexpectedTree (tree : Tree )(implicit env : Env ): Result
283
284
@@ -294,8 +295,13 @@ object Splicer {
294
295
case _ if tree.symbol == defn.TastyTasty_macroContext =>
295
296
interpretTastyContext()
296
297
297
- case StaticMethodCall (fn, args) =>
298
- interpretStaticMethodCall(fn, args.map(arg => interpretTree(arg)))
298
+ case StaticCall (fn, args) =>
299
+ if (fn.symbol.is(Module )) {
300
+ assert(args.isEmpty)
301
+ interpretModuleAccess(fn)
302
+ } else {
303
+ interpretStaticMethodCall(fn, args.map(arg => interpretTree(arg)))
304
+ }
299
305
300
306
// Interpret `foo(j = x, i = y)` which it is expanded to
301
307
// `val j$1 = x; val i$1 = y; foo(i = y, j = x)`
@@ -324,11 +330,11 @@ object Splicer {
324
330
unexpectedTree(tree)
325
331
}
326
332
327
- object StaticMethodCall {
333
+ object StaticCall {
328
334
def unapply (arg : Tree ): Option [(RefTree , List [Tree ])] = arg match {
329
335
case fn : RefTree if fn.symbol.isStatic => Some ((fn, Nil ))
330
- case Apply (StaticMethodCall (fn, args1), args2) => Some ((fn, args1 ::: args2)) // TODO improve performance
331
- case TypeApply (StaticMethodCall (fn, args), _) => Some ((fn, args))
336
+ case Apply (StaticCall (fn, args1), args2) => Some ((fn, args1 ::: args2)) // TODO improve performance
337
+ case TypeApply (StaticCall (fn, args), _) => Some ((fn, args))
332
338
case _ => None
333
339
}
334
340
}
0 commit comments