5

refchecksフェーズ用の Scala コンパイラ プラグインを作成しています。

コールサイトのシンボルを指定して、「スーパー」コールが参照するシンボルにアクセスするにはどうすればよいですか?

たとえば、

trait A {
  def m() {}
}

trait B extends A {
  def m() { super.m() }
}

callsite のシンボルを知っているのでsuper.m()、 trait のシンボルを取得したいと思いますA

4

1 に答える 1

1

自己型注釈と多重継承を使用すると役立つと思います。

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
于 2013-07-03T05:17:26.063 に答える