diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-18 14:22:23 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-18 14:22:23 -0800 |
commit | 8f9b66200880087e0d8d1d95ae8be5de928825b5 (patch) | |
tree | a602ed270b774db760509692b56fc3adb2838e1b | |
parent | 26afbf85bf17e3839f03cb9e2d981cdccdd2ee69 (diff) | |
parent | 7be585a0a29ba70845c2a5ed2f52d50db06a8189 (diff) | |
download | scala-8f9b66200880087e0d8d1d95ae8be5de928825b5.tar.gz scala-8f9b66200880087e0d8d1d95ae8be5de928825b5.tar.bz2 scala-8f9b66200880087e0d8d1d95ae8be5de928825b5.zip |
Merge remote-tracking branches 'kmizu/pull-request-fix-SI-5377' and 'kepler/topic/showraw'
-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) } |