@@ -5,15 +5,22 @@ import scala.quoted._
5
5
6
6
trait MemberLookup {
7
7
8
+ def memberLookupResult (using Quotes )(
9
+ symbol : quotes.reflect.Symbol ,
10
+ label : String ,
11
+ inheritingParent : Option [quotes.reflect.Symbol ] = None
12
+ ): (quotes.reflect.Symbol , String , Option [quotes.reflect.Symbol ]) =
13
+ (symbol, label, inheritingParent)
14
+
8
15
def lookup (using Quotes , DocContext )(
9
16
query : Query ,
10
17
owner : quotes.reflect.Symbol ,
11
- ): Option [(quotes.reflect.Symbol , String )] = lookupOpt(query, Some (owner))
18
+ ): Option [(quotes.reflect.Symbol , String , Option [quotes.reflect. Symbol ] )] = lookupOpt(query, Some (owner))
12
19
13
20
def lookupOpt (using Quotes , DocContext )(
14
21
query : Query ,
15
22
ownerOpt : Option [quotes.reflect.Symbol ],
16
- ): Option [(quotes.reflect.Symbol , String )] =
23
+ ): Option [(quotes.reflect.Symbol , String , Option [quotes.reflect. Symbol ] )] =
17
24
try
18
25
import quotes .reflect ._
19
26
@@ -26,7 +33,7 @@ trait MemberLookup {
26
33
def nearestMembered (sym : Symbol ): Symbol =
27
34
if sym.isClassDef || sym.flags.is(Flags .Package ) then sym else nearestMembered(sym.owner)
28
35
29
- val res : Option [(Symbol , String )] = {
36
+ val res : Option [(Symbol , String , Option [ Symbol ] )] = {
30
37
def toplevelLookup (querystrings : List [String ]) =
31
38
downwardLookup(querystrings, defn.PredefModule .moduleClass)
32
39
.orElse(downwardLookup(querystrings, defn.ScalaPackage ))
@@ -38,7 +45,7 @@ trait MemberLookup {
38
45
val nearest = nearestMembered(owner)
39
46
val nearestCls = nearestClass(owner)
40
47
val nearestPkg = nearestPackage(owner)
41
- def relativeLookup (querystrings : List [String ], owner : Symbol ): Option [Symbol ] = {
48
+ def relativeLookup (querystrings : List [String ], owner : Symbol ): Option [( Symbol , Option [ Symbol ]) ] = {
42
49
val isMeaningful =
43
50
owner.exists
44
51
// those are just an optimisation, they can be dropped if problems show up
@@ -56,20 +63,20 @@ trait MemberLookup {
56
63
57
64
query match {
58
65
case Query .StrictMemberId (id) =>
59
- downwardLookup(List (id), nearest).map(_ -> id )
66
+ downwardLookup(List (id), nearest).map(memberLookupResult(_, id, _) )
60
67
case Query .QualifiedId (Query .Qual .This , _, rest) =>
61
- downwardLookup(rest.asList, nearestCls).map(_ -> rest.join)
68
+ downwardLookup(rest.asList, nearestCls).map(memberLookupResult(_, rest.join, _) )
62
69
case Query .QualifiedId (Query .Qual .Package , _, rest) =>
63
- downwardLookup(rest.asList, nearestPkg).map(_ -> rest.join)
70
+ downwardLookup(rest.asList, nearestPkg).map(memberLookupResult(_, rest.join, _) )
64
71
case query =>
65
72
val ql = query.asList
66
73
toplevelLookup(ql)
67
74
.orElse(relativeLookup(ql, nearest))
68
- .map(_ -> query.join)
75
+ .map(memberLookupResult(_, query.join, _) )
69
76
}
70
77
71
78
case None =>
72
- toplevelLookup(query.asList).map(_ -> query.join)
79
+ toplevelLookup(query.asList).map(memberLookupResult(_, query.join, _) )
73
80
}
74
81
}
75
82
@@ -165,13 +172,15 @@ trait MemberLookup {
165
172
}
166
173
}
167
174
168
- private def downwardLookup (using Quotes )(query : List [String ], owner : quotes.reflect.Symbol ): Option [quotes.reflect.Symbol ] = {
175
+ private def downwardLookup (using Quotes )(
176
+ query : List [String ], owner : quotes.reflect.Symbol
177
+ ): Option [(quotes.reflect.Symbol , Option [quotes.reflect.Symbol ])] = {
169
178
import quotes .reflect ._
170
179
query match {
171
180
case Nil => None
172
181
case q :: Nil =>
173
182
val sel = MemberLookup .Selector .fromString(q)
174
- sel.kind match {
183
+ val res = sel.kind match {
175
184
case MemberLookup .SelectorKind .NoForce =>
176
185
val lookedUp = localLookup(sel, owner).toSeq
177
186
// note: those flag lookups are necessary b/c for objects we return their classes
@@ -180,7 +189,16 @@ trait MemberLookup {
180
189
)
181
190
case _ =>
182
191
localLookup(sel, owner).nextOption
183
-
192
+ }
193
+ res match {
194
+ case None => None
195
+ case Some (sym) =>
196
+ val externalOwner : Option [quotes.reflect.Symbol ] =
197
+ if owner eq sym.owner then None
198
+ else if owner.flags.is(Flags .Module ) then Some (owner.moduleClass)
199
+ else if owner.isClassDef then Some (owner)
200
+ else None
201
+ Some (sym -> externalOwner)
184
202
}
185
203
case q :: qs =>
186
204
val sel = MemberLookup .Selector .fromString(q)
0 commit comments