Comments 

Single line comments 

Single line comments are added to an arbitrary tree as follows:

tree withComment("comments here", ...)

For example,

scala> import treehugger.forest._, definitions._, treehuggerDSL._
import treehugger.forest._
import definitions._
import treehuggerDSL._

scala> val tree = LIT(2) withComment("comments are useful",
  "only if they provide more info than the code")
[1m[34mtree[0m: [1m[32mtreehugger.forest.Commented[0m = Commented(Modifiers(, , Map()),List(comments are useful, only if they provide more info than the code),Literal(Constant(2)))

scala> treeToString(tree)
[1m[34mres0[0m: [1m[32mString[0m =
// comments are useful
// only if they provide more info than the code
2

Scaladoc style comments 

Scaladoc style comments are written using withDoc as follows:

tree withDoc("comments" | doctag, ...)

where doctag is a doctag defined as DocTag.See(IntClass), DocTag.Author("Somebody"), etc.

For example,

scala> val tree2 = (DEF("x") := LIT(0)) withDoc(
  "does something",
  DocTag.See(IntClass))
[1m[34mtree2[0m: [1m[32mtreehugger.forest.Commented[0m = Commented(Modifiers(protected, , Map()),List(does something, @see scala.Int),DefDef(Modifiers(, , Map()),x,List(),List(),TypeTree(),Literal(Constant(0))))

scala> treeToString(tree2)
[1m[34mres1[0m: [1m[32mString[0m =
/**
 * does something
 * @see scala.Int
 */
def x = 0