diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-06-30 03:37:17 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-07-02 11:48:09 +0200 |
commit | 3237b1cd6fc2b2029080fe9d4b2b76d43ab8011c (patch) | |
tree | 7583751eced61efe1e02686e2f068409ce07ed38 /src/reflect/scala/reflect/api/Printers.scala | |
parent | cba0cbb892e991a0946270d1a7da63993f248225 (diff) | |
download | scala-3237b1cd6fc2b2029080fe9d4b2b76d43ab8011c.tar.gz scala-3237b1cd6fc2b2029080fe9d4b2b76d43ab8011c.tar.bz2 scala-3237b1cd6fc2b2029080fe9d4b2b76d43ab8011c.zip |
further improves reflection printers
Diffstat (limited to 'src/reflect/scala/reflect/api/Printers.scala')
-rw-r--r-- | src/reflect/scala/reflect/api/Printers.scala | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/src/reflect/scala/reflect/api/Printers.scala b/src/reflect/scala/reflect/api/Printers.scala index 7f4ff8a7fb..27d3b8ba7d 100644 --- a/src/reflect/scala/reflect/api/Printers.scala +++ b/src/reflect/scala/reflect/api/Printers.scala @@ -10,12 +10,15 @@ trait Printers { self: Universe => protected var printTypes = false protected var printIds = false protected var printKinds = false + protected var printMirrors = false def withTypes: this.type = { printTypes = true; this } def withoutTypes: this.type = { printTypes = false; this } def withIds: this.type = { printIds = true; this } def withoutIds: this.type = { printIds = false; this } def withKinds: this.type = { printKinds = true; this } def withoutKinds: this.type = { printKinds = false; this } + def withMirrors: this.type = { printMirrors = true; this } + def withoutMirrors: this.type = { printMirrors = false; this } } case class BooleanFlag(val value: Option[Boolean]) @@ -25,13 +28,14 @@ trait Printers { self: Universe => implicit def optionToBooleanFlag(value: Option[Boolean]): BooleanFlag = BooleanFlag(value) } - protected def render(what: Any, mkPrinter: PrintWriter => TreePrinter, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None): String = { + protected def render(what: Any, mkPrinter: PrintWriter => TreePrinter, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = { val buffer = new StringWriter() val writer = new PrintWriter(buffer) var printer = mkPrinter(writer) printTypes.value.map(printTypes => if (printTypes) printer.withTypes else printer.withoutTypes) printIds.value.map(printIds => if (printIds) printer.withIds else printer.withoutIds) printKinds.value.map(printKinds => if (printKinds) printer.withKinds else printer.withoutKinds) + printMirrors.value.map(printMirrors => if (printMirrors) printer.withMirrors else printer.withoutMirrors) printer.print(what) writer.flush() buffer.toString @@ -40,42 +44,25 @@ trait Printers { self: Universe => /** By default trees are printed with `show` */ override protected def treeToString(tree: Tree) = show(tree) - /** Renders a prettified representation of a tree. + /** Renders a prettified representation of a reflection artifact. * Typically it looks very close to the Scala code it represents. - * This function is used in Tree.toString. */ - def show(tree: Tree, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None): String = - render(tree, newTreePrinter(_), printTypes, printIds, printKinds) + def show(any: Any, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = + render(any, newTreePrinter(_), printTypes, printIds, printKinds, printMirrors) - /** Hook to define what `show(tree)` means. + /** Hook to define what `show(...)` means. */ def newTreePrinter(out: PrintWriter): TreePrinter - /** Renders internal structure of a tree. + /** Renders internal structure of a reflection artifact. */ - def showRaw(tree: Tree, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None): String = - render(tree, newRawTreePrinter(_), printTypes, printIds, printKinds) + def showRaw(any: Any, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = + render(any, newRawTreePrinter(_), printTypes, printIds, printKinds, printMirrors) - /** Hook to define what `showRaw(tree)` means. + /** Hook to define what `showRaw(...)` means. */ def newRawTreePrinter(out: PrintWriter): TreePrinter - /** Renders a prettified representation of a symbol. - */ - def show(sym: Symbol): String = sym.toString - - /** Renders internal structure of a symbol. - */ - def showRaw(sym: Symbol): String = render(sym, newRawTreePrinter(_)) - - /** Renders a prettified representation of a type. - */ - def show(tpe: Type): String = tpe.toString - - /** Renders internal structure of a type. - */ - def showRaw(tpe: Type): String = render(tpe, newRawTreePrinter(_)) - /** Renders a prettified representation of a name. */ def show(name: Name): String |