0

I'm having this issue I cannot fix. I would like to get recursively the classes starting from the macro.

Class A{
  def myfunc = macro mymacro
}
Class B{
  val b = new A().myfunc
}
Class C{
 val c = new B().b
}

At the end I want to get the resulting stacktrace so [C.c,B.b,A.myfunc]. Is there any way to do this? I already tried to get the owner of the encoding class but I don't know how to identify the class who really called B. Please consider the case where I have also a class D like below:

Class D{
  val d = new B().b
}

and a main like below:

Main {
  new C.c
}
  • It it something that depends on the runtime more like the the compile time, so macro cannot solve that in an universal and reliable way. Something like: http://stackoverflow.com/questions/1069066/get-current-stack-trace-in-java – Mateusz Kubuszok Feb 23 '17 at 18:19
  • Java Stacktrace is expensive and not a clean solution. I don't like the idea to call a stacktrace at runtime to recreate the tree of calling classes. Macro has all the information they need on the AST in order to get the class who's calleing my function (or my other class). One of the main issue is that we don't have any tool to access the parent of a tree. The only solution seems to access to the owner symbol and typechecking expanding the macro. Although I'm not able to find the caller class this way. – matrizvalo Feb 24 '17 at 02:26
  • I create Main2 in another project, import your project and use your functions - stack trace generated by macro would be invalid as it only would have access to classes in its compile time. Of course assuming that AST in would have access to whatever calls the method. In practice you DO NOT have access to what calls you, unless you would like to create your own parser, which would scan all of your files, calculate whatever uses your call recursively, but then it still would not work in case I described above. Long story short, Java Stacktrace is the only solutions that would work in practice. – Mateusz Kubuszok Feb 24 '17 at 10:07

0 Answers0