5

I'm writing a Scala compiler plugin for the refchecks phase.

How do I access the symbol that a "super" call refers to, given the symbol of the callsite?

For example, in

trait A {
  def m() {}
}

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

knowing the symbol for the callsite super.m(), I would like to get the symbol for trait A.

amaurremi
  • 777
  • 1
  • 5
  • 11
  • are getClass() and classOf() for concrete instances and classes/types not what you want or not available at that phase? – Gene T Jul 02 '13 at 02:01

1 Answers1

1

I think using of self type annotations and multiple inheritance will serve you:

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
Mohsen Heydari
  • 7,256
  • 4
  • 31
  • 46