I would like to print Scala source code of IF condition while being in THEN section.
Example: IF{ 2 + 2 < 5 } THEN { println("I am in THEN because: " + sourceCodeOfCondition) }
Let's skip THEN section right now, the question is: how to get source code of block after IF?
I assume that IF should be a macro...
Note: this question is redefined version of Macro to access source code of function at runtime where I described that { val i = 5; List(1, 2, 3); true }.logValueImpl
works for me (according to other question Macro to access source code text at runtime).
Off-the-cuff implementation since I only have a minute:
And then:
And finally:
It's a desugared representation of the source, but off the top of my head I think that's the best you're going to get.
See my blog post here for some discussion of the technique.