refchecksフェーズ用の Scala コンパイラ プラグインを作成しています。
コールサイトのシンボルを指定して、「スーパー」コールが参照するシンボルにアクセスするにはどうすればよいですか?
たとえば、
trait A {
def m() {}
}
trait B extends A {
def m() { super.m() }
}
callsite のシンボルを知っているのでsuper.m()
、 trait のシンボルを取得したいと思いますA
。
自己型注釈と多重継承を使用すると役立つと思います。
trait HelperTrait {
def helperMethod {println("calling helperMethod of HelperTrait")}
}
trait PublicInterface { this: HelperTrait =>
def useHelperMethod
{
println("calling useHelperMethod of PublicInterface")
helperMethod
}
}
class ImplementationClass extends PublicInterface with HelperTrait
var obj = new ImplementationClass()
obj.useHelperMethod
obj.helperMethod