Reputation: 1467
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"
.
Upvotes: 6
Views: 1164
Reputation: 15086
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
Upvotes: 9