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)
[1m[34mtree[0m: [1m[32mtreehugger.forest.Import[0m = Import(Ident(mutable),List())
scala> val tree2 = IMPORT("scala.collection.mutable")
[1m[34mtree2[0m: [1m[32mtreehugger.forest.Import[0m = Import(Ident(mutable),List())
scala> val tree3 = IMPORT(MutablePackage, "_")
[1m[34mtree3[0m: [1m[32mtreehugger.forest.Import[0m = Import(Ident(mutable),List(ImportSelector(_,-1,_,-1)))
scala> val tree4 = IMPORT(MutablePackage, "Map", "Set")
[1m[34mtree4[0m: [1m[32mtreehugger.forest.Import[0m = Import(Ident(mutable),List(ImportSelector(Map,-1,Map,-1), ImportSelector(Set,-1,Set,-1)))
scala> val tree5 = IMPORT(MutablePackage, RENAME("Map") ==> "MutableMap")
[1m[34mtree5[0m: [1m[32mtreehugger.forest.Import[0m = Import(Ident(mutable),List(ImportSelector(Map,-1,MutableMap,-1)))
The above examples print as:
scala> treeToString(tree)
[1m[34mres0[0m: [1m[32mString[0m = import scala.collection.mutable
scala> treeToString(tree2)
[1m[34mres1[0m: [1m[32mString[0m = import scala.collection.mutable
scala> treeToString(tree3)
[1m[34mres2[0m: [1m[32mString[0m = import scala.collection.mutable._
scala> treeToString(tree4)
[1m[34mres3[0m: [1m[32mString[0m = import scala.collection.mutable.{Map, Set}
scala> treeToString(tree5)
[1m[34mres4[0m: [1m[32mString[0m = 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.