Instance Creation Expressions 

Constructor invocations 

Instance creations are written using NEW(path|typ|"C"):

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

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

scala> NEW(sym.A)                   // new A
res0: treehugger.forest.Tree = New(TypeTree())

scala> NEW("C")                     // new C
res1: treehugger.forest.Tree = New(TypeTree())

scala> NEW(REF("B") DOT "C")        // new B.C
res2: treehugger.forest.Tree = New(Select(Ident(B),C))

Optionally, arguments may be passed into the constructor using NEW(path|typ|"C", arg, ...):

scala> val tree = NEW("C", LIT(0), LIT(1))
tree: treehugger.forest.Tree = Apply(Select(New(TypeTree()),<init>),List(Literal(Constant(0)), Literal(Constant(1))))

scala> treeToString(tree)
res3: String = new C(0, 1)

Anonymous classes 

Anonymous classes are created by passing ANONDEF(parent|"C", ...) into NEW(...):

scala> val tree2 = NEW(ANONDEF() := BLOCK(
  DEF("name") := LIT("Robert")
))
tree2: treehugger.forest.Tree = New(ClassDef(Modifiers(, , Map()),Modifiers(, , Map()),$anon,List(),List(),Template(List(),ValDef(Modifiers(private, , Map()),Ident(_),EmptyTree),List(DefDef(Modifiers(, , Map()),name,List(),List(),TypeTree(),Literal(Constant(Robert)))))))

scala> val tree3 = NEW(ANONDEF("C") := BLOCK(
  DEF("name") := LIT("Robert")
))
tree3: treehugger.forest.Tree = New(ClassDef(Modifiers(, , Map()),Modifiers(, , Map()),$anon,List(),List(),Template(List(TypeTree()),ValDef(Modifiers(private, , Map()),Ident(_),EmptyTree),List(DefDef(Modifiers(, , Map()),name,List(),List(),TypeTree(),Literal(Constant(Robert)))))))

scala> val tree4 = NEW(ANONDEF("C") withEarlyDefs(
  VAL("name") := LIT("Robert")
))
tree4: treehugger.forest.Tree = New(ClassDef(Modifiers(, , Map()),Modifiers(, , Map()),$anon,List(),List(),Template(List(Block(List(),ValDef(Modifiers(, , Map()),Ident(name),Literal(Constant(Robert)))), TypeTree()),ValDef(Modifiers(private, , Map()),Ident(_),EmptyTree),List())))

These examples print as:

scala> treeToString(tree2)
res4: String = 
new {
  def name = "Robert"
}

scala> treeToString(tree3)
res5: String = 
new C {
  def name = "Robert"
}

scala> treeToString(tree4)
res6: String = 
new {
  val name = "Robert"
} with C