I would like to catch the name of variable that output of my macro is assigned to. Exactly like project
in build.sbt. I would prefer out of the box solution(library) if there is one, because it looks like pretty general use case.
Here is small example
val someValue = myMacro()
and as an output of myMacro()
I would like to get string "someValue"
.
You are looking for SourceCode.
Example:
scala> def myName(implicit name: sourcecode.Name) = name.value
myName: (implicit name: sourcecode.Name)String
scala> val foo = myName
foo: String = foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With