diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2011-12-24 16:57:43 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-01-17 21:48:33 +0100 |
commit | 7be585a0a29ba70845c2a5ed2f52d50db06a8189 (patch) | |
tree | 21c3da6803058cc80f75f9ada37713779c3f7d61 /src | |
parent | 3192048a4bfb59966f93bb87a3c4f6b7ccfc80b2 (diff) | |
download | scala-7be585a0a29ba70845c2a5ed2f52d50db06a8189.tar.gz scala-7be585a0a29ba70845c2a5ed2f52d50db06a8189.tar.bz2 scala-7be585a0a29ba70845c2a5ed2f52d50db06a8189.zip |
Upgraded the implementation of showRaw
Now showRaw no longer significantly lags behind -Yreify-copypaste.
Didn't put very much effort into it, since quite soon LiftCode
will become a macro and we'll be able to reuse it in RawTreePrinter.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/reflect/api/TreePrinters.scala | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/library/scala/reflect/api/TreePrinters.scala b/src/library/scala/reflect/api/TreePrinters.scala index 15fba0e418..88ef450ed9 100644 --- a/src/library/scala/reflect/api/TreePrinters.scala +++ b/src/library/scala/reflect/api/TreePrinters.scala @@ -28,7 +28,21 @@ trait TreePrinters { self: Universe => */ def newTreePrinter(out: PrintWriter): TreePrinter + // emits more or less verbatim representation of the provided tree + // todo. when LiftCode becomes a macro, throw this code away and use that macro class RawTreePrinter(out: PrintWriter) extends TreePrinter { + import scala.reflect.api.Modifier + import scala.reflect.api.Modifier._ + + def copypasteModifier(mod: Modifier.Value): String = mod match { + case mod @ ( + `protected` | `private` | `override` | + `abstract` | `final` | `sealed` | + `implicit` | `lazy` | `macro` | + `case` | `trait`) => "`" + mod.toString + "`" + case mod => mod.toString + } + def print(args: Any*): Unit = args foreach { case EmptyTree => print("EmptyTree") @@ -48,10 +62,35 @@ trait TreePrinters { self: Universe => case arg => print(arg) } - print(if (it.hasNext) ", " else ")") + print(if (it.hasNext) ", " else "") } + print(")") if (typesPrinted) print(".setType(", tree.tpe, ")") + case list: List[_] => + print("List(") + val it = list.iterator + while (it.hasNext) { + print(it.next()) + print(if (it.hasNext) ", " else "") + } + print(")") + case mods: Modifiers => + val parts = collection.mutable.ListBuffer[String]() + parts += "Set(" + mods.allModifiers.map{copypasteModifier}.mkString(", ") + ")" + parts += "newTypeName(\"" + mods.privateWithin.toString + "\")" + parts += "List(" + mods.annotations.map{showRaw}.mkString(", ") + ")" + + var keep = 3 + if (keep == 3 && mods.annotations.isEmpty) keep -= 1 + if (keep == 2 && mods.privateWithin == EmptyTypeName) keep -= 1 + if (keep == 1 && mods.allModifiers.isEmpty) keep -= 1 + + print("Modifiers(", parts.take(keep).mkString(", "), ")") + case name: Name => + if (name.isTermName) print("newTermName(\"") else print("newTypeName(\"") + print(name.toString) + print("\")") case arg => out.print(arg) } |