casualjim
4/11/2011 - 10:18 PM

gistfile1.scala

import collection.JavaConversions._
trait Base {
  
  def invoke(curr: String) {
    println("invoking: " + curr)
    Thread.currentThread.getStackTrace.foreach(st => println("className: " + st.getClassName + " methodName: " + st.getMethodName ))
  }
}

class Top extends Base {
  
  invoke("top")
  
}

class Hello extends Top {
  invoke("hello 1")
  invoke("hello 2")
}

/*

Apparently the key is to find the first <init> method after the call we want to check 

scala> new Hello
invoking: top
... garbage ...
className: Top methodName: invoke
... potentially more method calls ...
className: Top methodName: <init>
className: Hello methodName: <init>
... garbage ...
invoking: hello 1
... garbage ...
className: Top methodName: invoke
... potentially more method calls ...
className: Hello methodName: <init>
... garbage ...
invoking: hello 2
... garbage ...
className: Top methodName: invoke
... potentially more method calls ...
className: Hello methodName: <init>
... garbage ...
res0: Hello = Hello@5dcdd76a
*/