@@ -3,18 +3,21 @@ package tasty
3
3
4
4
import collection .JavaConverters ._
5
5
6
+ import scala .quoted ._
7
+
6
8
import NameNormalizer ._
7
9
import SyntheticsSupport ._
8
10
9
11
trait TypesSupport :
10
12
self : TastyParser =>
11
- import qctx .reflect ._
12
- private given qctx .type = qctx
13
13
14
14
type DocSignaturePart = String | Link
15
15
type DocSignature = List [DocSignaturePart ]
16
16
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
+
18
21
def extractTypeSymbol (t : Tree ): Option [Symbol ] = t match
19
22
case tpeTree : TypeTree =>
20
23
inner(tpeTree.tpe)
@@ -41,46 +44,50 @@ trait TypesSupport:
41
44
}.flatten.map(_.asSignature)
42
45
43
46
given TreeSyntax : AnyRef with
44
- extension (tpeTree : Tree )
47
+ extension (using Quotes )( tpeTree : quotes.reflect. Tree )
45
48
def asSignature : DocSignature =
49
+ import quotes .reflect ._
46
50
tpeTree match
47
51
case TypeBoundsTree (low, high) => typeBoundsTreeOfHigherKindedType(low.tpe, high.tpe)
48
52
case tpeTree : TypeTree => inner(tpeTree.tpe)
49
53
case term : Term => inner(term.tpe)
50
54
51
55
given TypeSyntax : AnyRef with
52
- extension (tpe : TypeRepr )
56
+ extension (using Quotes )( tpe : quotes.reflect. TypeRepr )
53
57
def asSignature : DocSignature = inner(tpe)
54
58
55
59
56
60
private def text (str : String ): DocSignaturePart = str
57
61
58
62
private def texts (str : String ): DocSignature = List (text(str))
59
63
60
- private def link (symbol : Symbol ): DocSignature =
64
+ private def link (using Quotes )( symbol : quotes.reflect. Symbol ): DocSignature =
61
65
val suffix = if symbol.isValDef then texts(" .type" ) else Nil
62
66
Link (symbol.normalizedName, symbol.dri) :: suffix
63
67
64
68
private def commas (lists : List [DocSignature ]) = lists match
65
69
case List (single) => single
66
70
case other => other.reduce((r, e) => r ++ texts(" , " ) ++ e)
67
71
68
- private def isRepeatedAnnotation (term : Term ) =
72
+ private def isRepeatedAnnotation (using Quotes )(term : quotes.reflect.Term ) =
73
+ import quotes .reflect ._
69
74
term.tpe match
70
75
case t : TypeRef => t.name == " Repeated" && t.qualifier.match
71
76
case ThisType (tref : TypeRef ) if tref.name == " internal" => true
72
77
case _ => false
73
78
case _ => false
74
79
75
- private def isRepeated (typeRepr : TypeRepr ) =
80
+ private def isRepeated (using Quotes )(typeRepr : quotes.reflect.TypeRepr ) =
81
+ import quotes .reflect ._
76
82
typeRepr match
77
83
case t : TypeRef => t.name == " <repeated>" && t.qualifier.match
78
84
case ThisType (tref : TypeRef ) if tref.name == " scala" => true
79
85
case _ => false
80
86
case _ => false
81
87
82
88
// 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 ._
84
91
def noSupported (name : String ): DocSignature =
85
92
println(s " WARN: Unsupported type: $name: ${tp.show}" )
86
93
List (text(s " Unsupported[ $name] " ))
@@ -265,8 +272,9 @@ trait TypesSupport:
265
272
266
273
case RecursiveType (tp) => inner(tp)
267
274
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
270
278
val prefix = text(if low then " >: " else " <: " )
271
279
t match {
272
280
case l : TypeLambda => prefix :: texts(" (" ) ++ inner(l) ++ texts(" )" )
@@ -275,7 +283,8 @@ trait TypesSupport:
275
283
case _ => Nil
276
284
}
277
285
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 ._
279
288
def regularTypeBounds (low : TypeRepr , high : TypeRepr ) =
280
289
typeBound(low, low = true ) ++ typeBound(high, low = false )
281
290
high.match
0 commit comments