@@ -9,8 +9,8 @@ object NameOfImpl {
99 @ tailrec def extract (tree : Tree ): String = tree match {
1010 case Ident (name) => name
1111 case Select (_, name) => name
12- case Block (List (stmt), term) => extract(stmt)
1312 case DefDef (" $anonfun" , _, _, Some (term)) => extract(term)
13+ case Block (List (stmt), _) => extract(stmt)
1414 case Block (_, term) => extract(term)
1515 case Apply (term, _) if term.symbol.fullName != " <special-ops>.throw" => extract(term)
1616 case TypeApply (term, _) => extract(term)
@@ -22,6 +22,24 @@ object NameOfImpl {
2222 Expr (name)
2323 }
2424
25+ def qualifiedNameOf (expr : Expr [Any ])(using Quotes ): Expr [String ] = {
26+ import quotes .reflect .*
27+ def extract (tree : Tree ): List [String ] = tree match {
28+ case Ident (name) => List (name)
29+ case Select (tree, name) => extract(tree) :+ name
30+ case DefDef (" $anonfun" , _, _, Some (term)) => extract(term)
31+ case Block (List (stmt), _) => extract(stmt)
32+ case Block (_, term) => extract(term)
33+ case Apply (term, _) if term.symbol.fullName != " <special-ops>.throw" => extract(term)
34+ case TypeApply (term, _) => extract(term)
35+ case Inlined (_, _, term) => extract(term)
36+ case Typed (term, _) => extract(term)
37+ case _ => throw new MatchError (s " Unsupported expression: ${expr.show}" )
38+ }
39+ val name = extract(expr.asTerm).drop(1 ).mkString(" ." )
40+ Expr (name)
41+ }
42+
2543 def nameOfType [T ](using Quotes , Type [T ]): Expr [String ] = {
2644 import quotes .reflect .*
2745 val name = TypeTree .of[T ].tpe.dealias match {
0 commit comments