Skip to content

Commit

Permalink
Add asCode function for dumping raw tree representations.
Browse files Browse the repository at this point in the history
 Intended only for use by Catalyst developers.

Author: Michael Armbrust <[email protected]>

Closes apache#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.
  • Loading branch information
marmbrus authored and rxin committed Mar 21, 2014
1 parent dab5439 commit d780983
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] {
children.foreach(_.generateTreeString(depth + 1, 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(",")})"
}
}

/**
Expand Down

0 comments on commit d780983

Please sign in to comment.