Skip to content

Commit 636a430

Browse files
committed
Heuristic to determine a way for displaying static methods
1 parent 4afc522 commit 636a430

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

scaladoc/src/dotty/tools/scaladoc/tasty/InkuireSupport.scala

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ trait InkuireSupport:
9999
Some(classType)
100100
.filter(_ => !isModule)
101101
.orElse(methodSymbol.extendedSymbol.flatMap(s => partialAsInkuire(vars).lift(s.tpt)))
102+
val (name, ownerName) = nameAndOwnerName(classDef, methodSymbol)
102103
val sgn = Inkuire.ExternalSignature(
103104
signature = Inkuire.Signature(
104105
receiver = receiver,
@@ -111,8 +112,8 @@ trait InkuireSupport:
111112
constraints = Map.empty //TODO [Inkuire] Type bounds
112113
)
113114
),
114-
name = methodSymbol.name,
115-
packageName = methodSymbol.dri.location,
115+
name = name,
116+
packageName = ownerName,
116117
uri = methodSymbol.dri.externalLink.getOrElse(""),
117118
entryType = "def"
118119
)
@@ -128,6 +129,7 @@ trait InkuireSupport:
128129
val receiver: Option[Inkuire.TypeLike] =
129130
Some(classType)
130131
.filter(_ => !isModule)
132+
val (name, ownerName) = nameAndOwnerName(classDef, valSymbol)
131133
val sgn = Inkuire.ExternalSignature(
132134
signature = Inkuire.Signature(
133135
receiver = receiver,
@@ -138,8 +140,8 @@ trait InkuireSupport:
138140
constraints = Map.empty //TODO [Inkuire] Type bounds
139141
)
140142
),
141-
name = valSymbol.name,
142-
packageName = valSymbol.dri.location,
143+
name = name,
144+
packageName = ownerName,
143145
uri = valSymbol.dri.externalLink.getOrElse(""),
144146
entryType = "val"
145147
)
@@ -148,6 +150,26 @@ trait InkuireSupport:
148150
}
149151
}
150152

153+
private def nameAndOwnerName(classDef: ClassDef, symbol: Symbol): (String, String) =
154+
if classDef.symbol.flags.is(Flags.Module)
155+
&& (classDef.symbol.companionClass != Symbol.noSymbol || (Seq("apply", "unapply").contains(symbol.name))) then
156+
(
157+
symbol.maybeOwner.normalizedName + "." + symbol.name,
158+
ownerNameChain(classDef.symbol.maybeOwner).mkString(".")
159+
)
160+
else
161+
(
162+
symbol.name,
163+
ownerNameChain(classDef.symbol).mkString(".")
164+
)
165+
166+
def ownerNameChain(sym: Symbol): List[String] =
167+
if sym.isNoSymbol then List.empty
168+
else if sym == defn.EmptyPackageClass then List.empty
169+
else if sym == defn.RootPackage then List.empty
170+
else if sym == defn.RootClass then List.empty
171+
else ownerNameChain(sym.owner) :+ sym.normalizedName
172+
151173
private def paramsForClass(classDef: ClassDef, vars: Set[String]): Seq[Inkuire.Variance] =
152174
classDef.getTypeParams.map(mkTypeArgumentInkuire)
153175

0 commit comments

Comments
 (0)