I'm developing a code generator that will output the following classes/objects:
class A {
var a : Int = _
var b : B = _
class B {
var b : Int = _
var c : C = _
class C {
var c : Int = _
}
}
}
object A {
val a = ...
object B extends Base {
val b = ...
object C extends Base {
val c = ...
}
}
}
with the user constructing the terms like this:
A (
a(1),
B (
b(2),
C (
c(3)
)
)
)
Now in order to make it开发者_JAVA百科 work I have to insert 3 imports in the user code:
import A._
import A.B._
import A.B.C._
This looks ugly to me. May be there is another way to tackle the problem that I'm just blind to see?
Thank you in advance.
After import A._
B
will be in the import scope (at least in Scala 2.8), so you can spare a few letters:
import A._
import B._
import C._
You could use def
s in your generated code. For example,
object A {
// ... other code
def b = B.b
def C = B.C
def c = C.c
}
精彩评论