summaryrefslogtreecommitdiff
path: root/test/files/run/macro-enclosures
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-31 15:47:56 +0100
committerEugene Burmako <xeno.by@gmail.com>2014-02-14 23:51:23 +0100
commit483bd3cacb34df3b3c2cc205338cb8e12cb89838 (patch)
treefb3986311fe90c2960405c05de4378138f258281 /test/files/run/macro-enclosures
parentd7dd68faa4cd279714c32965ebf83e118c915e0a (diff)
downloadscala-483bd3cacb34df3b3c2cc205338cb8e12cb89838.tar.gz
scala-483bd3cacb34df3b3c2cc205338cb8e12cb89838.tar.bz2
scala-483bd3cacb34df3b3c2cc205338cb8e12cb89838.zip
adds Context.enclosingOwner
As per discussion at https://groups.google.com/forum/#!topic/scala-internals/nf_ooEBn6-k, this commit introduces the new c.enclosingOwner API that is going to serve two purposes: 1) provide a better controlled alternative to c.enclosingTree, 2) enable low-level tinkering with owner chains without having to cast to compiler internals. This solution is not ideal, because: 1) symbols are much more than I would like to expose about enclosing lexical contexts (after the aforementioned discussion I’m no longer completely sure whether exposing nothing is the right thing to do, but exposing symbol completers is definitely something that should be avoided), 2) we shouldn’t have to do that low-level stuff in the first place. However, let’s face the facts. This change represents both an improvement over the state of the art wrt #1 and a long-awaited capability wrt #2. I think this pretty much warrants its place in trunk in the spirit of gradual, evolutionary development of reflection API.
Diffstat (limited to 'test/files/run/macro-enclosures')
-rw-r--r--test/files/run/macro-enclosures/Impls_Macros_1.scala22
1 files changed, 14 insertions, 8 deletions
diff --git a/test/files/run/macro-enclosures/Impls_Macros_1.scala b/test/files/run/macro-enclosures/Impls_Macros_1.scala
index 5b04cf29e9..a0f66a6b98 100644
--- a/test/files/run/macro-enclosures/Impls_Macros_1.scala
+++ b/test/files/run/macro-enclosures/Impls_Macros_1.scala
@@ -3,15 +3,21 @@ import scala.reflect.macros.blackbox.Context
object Macros {
def impl(c: Context) = {
import c.universe._
- reify {
- println("enclosingPackage = " + c.Expr[String](Literal(Constant(c.enclosingPackage.toString))).splice)
- println("enclosingClass = " + c.Expr[String](Literal(Constant(c.enclosingClass.toString))).splice)
- println("enclosingImpl = " + c.Expr[String](Literal(Constant(c.enclosingImpl.toString))).splice)
- println("enclosingTemplate = " + c.Expr[String](Literal(Constant(c.enclosingTemplate.toString))).splice)
- println("enclosingMethod = " + c.Expr[String](Literal(Constant(c.enclosingMethod.toString))).splice)
- println("enclosingDef = " + c.Expr[String](Literal(Constant(c.enclosingDef.toString))).splice)
+ def chain(sym: Symbol): List[Symbol] = sym.owner match {
+ case NoSymbol => sym :: Nil
+ case owner => sym :: chain(owner)
}
+ q"""
+ println("enclosingPackage = " + ${c.enclosingPackage.toString})
+ println("enclosingClass = " + ${c.enclosingClass.toString})
+ println("enclosingImpl = " + ${c.enclosingImpl.toString})
+ println("enclosingTemplate = " + ${c.enclosingTemplate.toString})
+ println("enclosingMethod = " + ${c.enclosingMethod.toString})
+ println("enclosingDef = " + ${c.enclosingDef.toString})
+ println("enclosingOwner = " + ${c.enclosingOwner.toString})
+ println("enclosingOwnerChain = " + ${chain(c.enclosingOwner).toString})
+ """
}
- def foo = macro impl
+ def foo: Any = macro impl
} \ No newline at end of file