summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-09-05 14:38:31 +0200
committerDen Shabalin <den.shabalin@gmail.com>2013-09-05 20:42:11 +0200
commitcdac66f750acb6fbf000215b8534f27f51da00a3 (patch)
tree48a977d3a0a575b3c1a76636a5360760de923a3f /src/reflect
parent230f36d9ca99abe33f4379ffd573702b2671f83a (diff)
downloadscala-cdac66f750acb6fbf000215b8534f27f51da00a3.tar.gz
scala-cdac66f750acb6fbf000215b8534f27f51da00a3.tar.bz2
scala-cdac66f750acb6fbf000215b8534f27f51da00a3.zip
streamline implementation of annotation splicing
Syntax spec mislead me to believe that annotation can't have type parameters or multiple argument lists... I guess the lesson here is don't trust the spec.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/api/BuildUtils.scala4
-rw-r--r--src/reflect/scala/reflect/internal/BuildUtils.scala15
2 files changed, 11 insertions, 8 deletions
diff --git a/src/reflect/scala/reflect/api/BuildUtils.scala b/src/reflect/scala/reflect/api/BuildUtils.scala
index ee6515b547..60c2a81947 100644
--- a/src/reflect/scala/reflect/api/BuildUtils.scala
+++ b/src/reflect/scala/reflect/api/BuildUtils.scala
@@ -72,7 +72,9 @@ private[reflect] trait BuildUtils { self: Universe =>
def setSymbol[T <: Tree](tree: T, sym: Symbol): T
- def mkAnnotation(tree: Tree, args: List[Tree]): Tree
+ def mkAnnotation(tree: Tree): Tree
+
+ def mkAnnotation(trees: List[Tree]): List[Tree]
def mkRefineStat(stat: Tree): Tree
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala
index 2376787116..06a6e10c30 100644
--- a/src/reflect/scala/reflect/internal/BuildUtils.scala
+++ b/src/reflect/scala/reflect/internal/BuildUtils.scala
@@ -61,15 +61,16 @@ trait BuildUtils { self: SymbolTable =>
def setSymbol[T <: Tree](tree: T, sym: Symbol): T = { tree.setSymbol(sym); tree }
- def mkAnnotation(tree: Tree, args: List[Tree]): Tree = tree match {
- case ident: Ident => Apply(self.Select(New(ident), nme.CONSTRUCTOR: TermName), args)
- case call @ Apply(Select(New(ident: Ident), nme.CONSTRUCTOR), _) =>
- if (args.nonEmpty)
- throw new IllegalArgumentException("Can't splice annotation that already contains args with extra args, consider merging these lists together")
- call
- case _ => throw new IllegalArgumentException(s"Tree ${showRaw(tree)} isn't a correct representation of annotation, consider passing Ident as a first argument")
+ def mkAnnotation(tree: Tree): Tree = tree match {
+ case SyntacticNew(Nil, SyntacticApplied(SyntacticTypeApplied(_, _), _) :: Nil, emptyValDef, Nil) =>
+ tree
+ case _ =>
+ throw new IllegalArgumentException(s"Tree ${showRaw(tree)} isn't a correct representation of annotation." +
+ """Consider reformatting it into a q"new $name[..$targs](...$argss)" shape""")
}
+ def mkAnnotation(trees: List[Tree]): List[Tree] = trees.map(mkAnnotation)
+
def mkVparamss(argss: List[List[ValDef]]): List[List[ValDef]] = argss.map(_.map(mkParam))
def mkParam(vd: ValDef): ValDef = {