Skip to content

Commit 6a75146

Browse files
committed
Cleanup JavadocAnchorCreator
1 parent c11a1bc commit 6a75146

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,33 @@ import dotty.tools.scaladoc.util.Escape._
66
import scala.util.matching.Regex
77

88
trait JavadocAnchorCreator:
9-
self: SymOps[_] =>
109

11-
import self.q.reflect._
10+
private def javadocPrimitive(using Quotes)(sym: quotes.reflect.Symbol): Option[String] =
11+
import quotes.reflect.defn
12+
if sym == defn.IntClass then Some("int")
13+
else if sym == defn.FloatClass then Some("float")
14+
else if sym == defn.DoubleClass then Some("double")
15+
else if sym == defn.LongClass then Some("long")
16+
else if sym == defn.ByteClass then Some("byte")
17+
else if sym == defn.BooleanClass then Some("boolean")
18+
else if sym == defn.CharClass then Some("char")
19+
else if sym == defn.ShortClass then Some("short")
20+
else if sym == defn.ShortClass then Some("java.lang.Object")
21+
else None
1222

13-
private val javadocPrimitivesMap = Map(
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"
23-
)
23+
private def transformPrimitiveType(using Quotes)(tpe: quotes.reflect.TypeRepr): String =
24+
tpe.classSymbol
25+
.filter(_ => !tpe.typeSymbol.isTypeParam)
26+
.flatMap(javadocPrimitive)
27+
.getOrElse(tpe.show)
2428

25-
private def transformPrimitiveType(tpe: TypeRepr): String = tpe.classSymbol
26-
.flatMap(javadocPrimitivesMap.get)
27-
.filter(_ => !tpe.typeSymbol.isTypeParam)
28-
.getOrElse(tpe.show)
29+
private def transformType(using Quotes)(tpe: quotes.reflect.TypeRepr): String =
30+
import quotes.reflect.*
31+
tpe.simplified match {
32+
case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.ArrayClass) => transformType(typeList.head) + ":A"
33+
case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.RepeatedParamClass) => transformType(typeList.head) + "..."
34+
case AppliedType(tpe, typeList) => transformPrimitiveType(tpe)
35+
case other => transformPrimitiveType(other)
36+
}
2937

30-
private def transformType(tpe: TypeRepr): String = tpe.simplified match {
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)
35-
}
36-
37-
def getJavadocType(s: TypeRepr) = transformType(s)
38+
def getJavadocType(using Quotes)(s: quotes.reflect.TypeRepr) = transformType(s)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import dotty.tools.io.AbstractFile
99
class SymOps[Q <: Quotes](val q: Q) extends JavadocAnchorCreator with Scaladoc2AnchorCreator:
1010
import q.reflect._
1111

12-
given Q = q
12+
given q.type = q
1313

1414
private val externalLinkCache: scala.collection.mutable.Map[AbstractFile, Option[ExternalDocLink]] = MMap()
1515

@@ -128,7 +128,7 @@ class SymOps[Q <: Quotes](val q: Q) extends JavadocAnchorCreator with Scaladoc2A
128128
val javadocAnchor = if anchor.isDefined then {
129129
val paramSigs = sym.paramSymss.flatten.map(_.tree).collect {
130130
case v: ValDef => v.tpt.tpe
131-
}.map(getJavadocType)
131+
}.map(getJavadocType(using q))
132132
"#" + sym.name + paramSigs.mkString("-","-","-")
133133
} else ""
134134
docURL + l + extension + javadocAnchor

0 commit comments

Comments
 (0)