Skip to content
Snippets Groups Projects
Commit d7809836 authored by Michael Armbrust's avatar Michael Armbrust Committed by Reynold Xin
Browse files

Add asCode function for dumping raw tree representations.

 Intended only for use by Catalyst developers.

Author: Michael Armbrust <michael@databricks.com>

Closes #200 from marmbrus/asCode and squashes the following commits:

7e8c1d9 [Michael Armbrust] Add asCode function for dumping raw tree representations.  Intended only for use by Catalyst developers.
parent dab5439a
No related branches found
No related tags found
No related merge requests found
...@@ -336,6 +336,21 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] { ...@@ -336,6 +336,21 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] {
children.foreach(_.generateTreeString(depth + 1, builder)) children.foreach(_.generateTreeString(depth + 1, builder))
builder builder
} }
/**
* Returns a 'scala code' representation of this `TreeNode` and its children. Intended for use
* when debugging where the prettier toString function is obfuscating the actual structure. In the
* case of 'pure' `TreeNodes` that only contain primitives and other TreeNodes, the result can be
* pasted in the REPL to build an equivalent Tree.
*/
def asCode: String = {
val args = productIterator.map {
case tn: TreeNode[_] => tn.asCode
case s: String => "\"" + s + "\""
case other => other.toString
}
s"$nodeName(${args.mkString(",")})"
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment