Import Clauses 

Import clauses are written using IMPORT(...). Optionally, import selectors may be specified:

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

scala> val tree  = IMPORT(MutablePackage)
tree: treehugger.forest.Import = Import(Ident(mutable),List())

scala> val tree2 = IMPORT("scala.collection.mutable")
tree2: treehugger.forest.Import = Import(Ident(mutable),List())

scala> val tree3 = IMPORT(MutablePackage, "_")
tree3: treehugger.forest.Import = Import(Ident(mutable),List(ImportSelector(_,-1,_,-1)))

scala> val tree4 = IMPORT(MutablePackage, "Map", "Set")
tree4: treehugger.forest.Import = Import(Ident(mutable),List(ImportSelector(Map,-1,Map,-1), ImportSelector(Set,-1,Set,-1)))

scala> val tree5 = IMPORT(MutablePackage, RENAME("Map") ==> "MutableMap")
tree5: treehugger.forest.Import = Import(Ident(mutable),List(ImportSelector(Map,-1,MutableMap,-1)))

The above examples print as:

scala> treeToString(tree)
res0: String = import scala.collection.mutable

scala> treeToString(tree2)
res1: String = import scala.collection.mutable

scala> treeToString(tree3)
res2: String = import scala.collection.mutable._

scala> treeToString(tree4)
res3: String = import scala.collection.mutable.{Map, Set}

scala> treeToString(tree5)
res4: String = import scala.collection.mutable.{Map => MutableMap}

In general:

IMPORT(sym|"x.y.z", ["X" | RENAME("X") ==> "Y"]*)

The only odd thing is ==> operator used for RENAME(...). Because => is already taken by Scala, treehugger DSL uses ==> instead.