package tool object TreePrinter { import parser.Trees._ /** TreePrinter(tree) will produce the same result as before. */ def apply: (Tree=>String) = apply(false)_ /** TreePrinter.withSymbolIDs(tree) will print the tree with the IDs. */ def withSymbolIDs: (Tree=>String) = apply(true)_ /** We added a parameter and currified the method to build the other two. */ private def apply(withSymbolIDs: Boolean)(t: Tree) = { /* code you had before... */ // ... // This adds a symbol id to identifiers, or question marks if it is unset. case id @ Identifier(value) => { if(withSymbolIDs) { try { id.getSymbol.name + "#" + id.getSymbol.id } catch { case e: java.lang.RuntimeException => value + "#??" } } else value } // ... } }