Skip to content

Commit

Permalink
Add asCode function for dumping raw tree representations. Intended on…
Browse files Browse the repository at this point in the history
…ly for use by Catalyst developers.
  • Loading branch information
marmbrus committed Mar 21, 2014
1 parent e09139d commit 7e8c1d9
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 7e8c1d9

Please sign in to comment.