Skip to content

Commit 0348d48

Browse files
committed
Partial cleanup of TypesSupport
1 parent 48bab6d commit 0348d48

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ package tasty
33

44
import collection.JavaConverters._
55

6+
import scala.quoted._
7+
68
import NameNormalizer._
79
import SyntheticsSupport._
810

911
trait TypesSupport:
1012
self: TastyParser =>
11-
import qctx.reflect._
12-
private given qctx.type = qctx
1313

1414
type DocSignaturePart = String | Link
1515
type DocSignature = List[DocSignaturePart]
1616

17-
def getGivenInstance(method: DefDef): Option[DocSignature] =
17+
def getGivenInstance(method: qctx.reflect.DefDef): Option[DocSignature] =
18+
import qctx.reflect._
19+
given qctx.type = qctx
20+
1821
def extractTypeSymbol(t: Tree): Option[Symbol] = t match
1922
case tpeTree: TypeTree =>
2023
inner(tpeTree.tpe)
@@ -41,46 +44,50 @@ trait TypesSupport:
4144
}.flatten.map(_.asSignature)
4245

4346
given TreeSyntax: AnyRef with
44-
extension (tpeTree: Tree)
47+
extension (using Quotes)(tpeTree: quotes.reflect.Tree)
4548
def asSignature: DocSignature =
49+
import quotes.reflect._
4650
tpeTree match
4751
case TypeBoundsTree(low, high) => typeBoundsTreeOfHigherKindedType(low.tpe, high.tpe)
4852
case tpeTree: TypeTree => inner(tpeTree.tpe)
4953
case term: Term => inner(term.tpe)
5054

5155
given TypeSyntax: AnyRef with
52-
extension (tpe: TypeRepr)
56+
extension (using Quotes)(tpe: quotes.reflect.TypeRepr)
5357
def asSignature: DocSignature = inner(tpe)
5458

5559

5660
private def text(str: String): DocSignaturePart = str
5761

5862
private def texts(str: String): DocSignature = List(text(str))
5963

60-
private def link(symbol: Symbol): DocSignature =
64+
private def link(using Quotes)(symbol: quotes.reflect.Symbol): DocSignature =
6165
val suffix = if symbol.isValDef then texts(".type") else Nil
6266
Link(symbol.normalizedName, symbol.dri) :: suffix
6367

6468
private def commas(lists: List[DocSignature]) = lists match
6569
case List(single) => single
6670
case other => other.reduce((r, e) => r ++ texts(", ") ++ e)
6771

68-
private def isRepeatedAnnotation(term: Term) =
72+
private def isRepeatedAnnotation(using Quotes)(term: quotes.reflect.Term) =
73+
import quotes.reflect._
6974
term.tpe match
7075
case t: TypeRef => t.name == "Repeated" && t.qualifier.match
7176
case ThisType(tref: TypeRef) if tref.name == "internal" => true
7277
case _ => false
7378
case _ => false
7479

75-
private def isRepeated(typeRepr: TypeRepr) =
80+
private def isRepeated(using Quotes)(typeRepr: quotes.reflect.TypeRepr) =
81+
import quotes.reflect._
7682
typeRepr match
7783
case t: TypeRef => t.name == "<repeated>" && t.qualifier.match
7884
case ThisType(tref: TypeRef) if tref.name == "scala" => true
7985
case _ => false
8086
case _ => false
8187

8288
// TODO #23 add support for all types signatures that makes sense
83-
private def inner(tp: TypeRepr): DocSignature =
89+
private def inner(using Quotes)(tp: quotes.reflect.TypeRepr): DocSignature =
90+
import quotes.reflect._
8491
def noSupported(name: String): DocSignature =
8592
println(s"WARN: Unsupported type: $name: ${tp.show}")
8693
List(text(s"Unsupported[$name]"))
@@ -265,8 +272,9 @@ trait TypesSupport:
265272

266273
case RecursiveType(tp) => inner(tp)
267274

268-
private def typeBound(t: TypeRepr, low: Boolean) =
269-
val ignore = if(low) t.typeSymbol == defn.NothingClass else t.typeSymbol == defn.AnyClass
275+
private def typeBound(using Quotes)(t: quotes.reflect.TypeRepr, low: Boolean) =
276+
import quotes.reflect._
277+
val ignore = if (low) t.typeSymbol == defn.NothingClass else t.typeSymbol == defn.AnyClass
270278
val prefix = text(if low then " >: " else " <: ")
271279
t match {
272280
case l: TypeLambda => prefix :: texts("(") ++ inner(l) ++ texts(")")
@@ -275,7 +283,8 @@ trait TypesSupport:
275283
case _ => Nil
276284
}
277285

278-
private def typeBoundsTreeOfHigherKindedType(low: TypeRepr, high: TypeRepr) =
286+
private def typeBoundsTreeOfHigherKindedType(using Quotes)(low: quotes.reflect.TypeRepr, high: quotes.reflect.TypeRepr) =
287+
import quotes.reflect._
279288
def regularTypeBounds(low: TypeRepr, high: TypeRepr) =
280289
typeBound(low, low = true) ++ typeBound(high, low = false)
281290
high.match

0 commit comments

Comments
 (0)