summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/reflect/api/TreePrinters.scala41
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)
}