Skip to content

Commit e82ffcd

Browse files
committed
CRs. Change logic to use definitions instead of show
1 parent 3c2b323 commit e82ffcd

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ trait JavadocAnchorCreator:
1111
import self.q.reflect._
1212

1313
private val javadocPrimitivesMap = Map(
14-
"scala.Int" -> "int",
15-
"scala.Float" -> "float",
16-
"scala.Double" -> "double",
17-
"scala.Long" -> "long",
18-
"scala.Byte" -> "byte",
19-
"scala.Boolean" -> "boolean",
20-
"scala.Char" -> "char",
21-
"scala.Short" -> "short",
22-
"<special-ops>.<FromJavaObject>" -> "java.lang.Object"
14+
defn.IntClass -> "int",
15+
defn.FloatClass -> "float",
16+
defn.DoubleClass -> "double",
17+
defn.LongClass -> "long",
18+
defn.ByteClass -> "byte",
19+
defn.BooleanClass -> "boolean",
20+
defn.CharClass -> "char",
21+
defn.ShortClass -> "short",
22+
defn.ObjectClass -> "java.lang.Object"
2323
)
2424

25-
private def transformPrimitiveType(s: String): String = javadocPrimitivesMap.getOrElse(s, s)
25+
private def transformPrimitiveType(tpe: TypeRepr): String = tpe.classSymbol
26+
.flatMap(javadocPrimitivesMap.get)
27+
.filter(_ => !tpe.typeSymbol.isTypeParam)
28+
.getOrElse(tpe.show)
2629

2730
private def transformType(tpe: TypeRepr): String = tpe.simplified match {
28-
case AppliedType(tpe, typeList) if tpe.show == "scala.Array" => transformType(typeList.head) + ":A"
29-
case AppliedType(tpe, typeList) if tpe.show == "scala.<repeated>" => transformType(typeList.head) + "..."
30-
case AppliedType(tpe, typeList) => transformPrimitiveType(tpe.show)
31-
case other => transformPrimitiveType(other.show)
31+
case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.ArrayClass) => transformType(typeList.head) + ":A"
32+
case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.RepeatedParamClass) => transformType(typeList.head) + "..."
33+
case AppliedType(tpe, typeList) => transformPrimitiveType(tpe)
34+
case other => transformPrimitiveType(other)
3235
}
3336

3437
def getJavadocType(s: TypeRepr) = transformType(s)

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ package tasty
33

44
import scala.quoted._
55
import dotty.tools.scaladoc.util.Escape._
6+
import scala.collection.mutable.{ Map => MMap }
7+
import dotty.tools.io.AbstractFile
68

79
class SymOps[Q <: Quotes](val q: Q) extends JavadocAnchorCreator with Scaladoc2AnchorCreator:
810
import q.reflect._
911

1012
given Q = q
13+
14+
private val externalLinkCache: scala.collection.mutable.Map[AbstractFile, Option[ExternalDocLink]] = MMap()
15+
1116
extension (sym: Symbol)
1217
def packageName: String = (
1318
if (sym.isPackageDef) sym.fullName
@@ -163,9 +168,14 @@ class SymOps[Q <: Quotes](val q: Q) extends JavadocAnchorCreator with Scaladoc2A
163168
import dotty.tools.dotc
164169
given ctx: dotc.core.Contexts.Context = q.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
165170
val csym = sym.asInstanceOf[dotc.core.Symbols.Symbol]
166-
Option(csym.associatedFile).map(_.path).flatMap( path =>
167-
dctx.externalDocumentationLinks.find(_.originRegexes.exists(r => r.matches(path)))
168-
).map(link => constructPath(location, anchor, link))
171+
val extLink = if externalLinkCache.contains(csym.associatedFile) then externalLinkCache(csym.associatedFile)
172+
else {
173+
val calculatedLink = Option(csym.associatedFile).map(_.path).flatMap( path =>
174+
dctx.externalDocumentationLinks.find(_.originRegexes.exists(r => r.matches(path))))
175+
externalLinkCache += (csym.associatedFile -> calculatedLink)
176+
calculatedLink
177+
}
178+
extLink.map(link => constructPath(location, anchor, link))
169179
}
170180

171181
DRI(

0 commit comments

Comments
 (0)