Classes and Objects 

Templates 

Classes and objects are both defined in terms of templates, whose body is represented using BLOCK(...) in treehugger DSL.

In general, treehugger DSL uses BLOCK(...) wherever curly braces ({}) appear in Scala. BLOCK(...) accepts vararg of trees, such as class member definitions and expressions:

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

scala> object sym {
  val IntQueue: ClassSymbol = RootClass.newClass("IntQueue")  
}
defined module sym

scala> val tree = CLASSDEF(sym.IntQueue) withFlags(Flags.ABSTRACT) := BLOCK(
  DEF("get", IntClass),
  PROC("put") withParams(PARAM("x", IntClass))
)
tree: treehugger.forest.ClassDef = ClassDef(Modifiers(abstract, , Map()),Modifiers(, , Map()),IntQueue,List(),List(),Template(List(),ValDef(Modifiers(private, , Map()),Ident(_),EmptyTree),List(DefDef(Modifiers(, , Map()),get,List(),List(),TypeTree(),EmptyTree), ProcDef(Modifiers(, , Map()),put,List(),List(List(ValDef(Modifiers(<param>, , Map()),Typed(Ident(x),TypeTree()),EmptyTree))),EmptyTree))))

This example prints as:

scala> treeToString(tree)
res0: String = 
abstract class IntQueue {
  def get: Int
  def put(x: Int)
}