Import Clauses

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

import treehugger.forest._, definitions._, treehuggerDSL._
val tree  = IMPORT(MutablePackage)
val tree2 = IMPORT("scala.collection.mutable")
val tree3 = IMPORT(MutablePackage, "_")
val tree4 = IMPORT(MutablePackage, "Map", "Set")
val tree5 = IMPORT(MutablePackage, RENAME("Map") ==> "MutableMap")

The above examples print as:

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

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

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

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

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.