1
1
package dotty .tastydoc
2
2
3
- import scala .tasty . Reflection
3
+ import scala .quoted . _
4
4
import dotty .tastydoc .comment .{CommentParser , CommentCleaner , Comment , WikiComment , MarkdownComment }
5
5
import dotty .tastydoc .references ._
6
6
import dotty .tastydoc .representations ._
7
7
8
8
/** A trait containing useful methods for extracting information from the reflect API */
9
9
trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentCleaner {
10
- def extractPath (reflect : Reflection )(symbol : reflect .Symbol ) : List [String ] = {
11
- import reflect .{ given _ , _ }
10
+ def extractPath (using QuoteContext )(symbol : qctx.tasty .Symbol ) : List [String ] = {
11
+ import qctx . tasty . _
12
12
13
13
val pathArray = symbol.show.split(" \\ ." ) // NOTE: this should print w/o colors, inspect afterwards
14
14
pathArray.iterator.slice(0 , pathArray.length - 1 ).toList
15
15
}
16
16
17
- def extractModifiers (reflect : Reflection )(flags : reflect. Flags , privateWithin : Option [reflect. Type ], protectedWithin : Option [reflect .Type ]) : (List [String ], Option [Reference ], Option [Reference ]) = {
18
- import reflect .{ given _ , _ }
17
+ def extractModifiers (using QuoteContext )(flags : qctx.tasty. Flags , privateWithin : Option [qctx.tasty. Type ], protectedWithin : Option [qctx.tasty .Type ]) : (List [String ], Option [Reference ], Option [Reference ]) = {
18
+ import qctx . tasty . _
19
19
20
20
(((if (flags.is(Flags .Override )) " override" else " " ) ::
21
21
(if (flags.is(Flags .Private )) " private" else " " )::
@@ -30,18 +30,16 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
30
30
Nil ) filter (_ != " " ),
31
31
32
32
privateWithin match {
33
- case Some (t) => Some (convertTypeToReference(reflect)( t))
33
+ case Some (t) => Some (convertTypeToReference(t))
34
34
case None => None
35
35
},
36
36
protectedWithin match {
37
- case Some (t) => Some (convertTypeToReference(reflect)( t))
37
+ case Some (t) => Some (convertTypeToReference(t))
38
38
case None => None
39
39
})
40
40
}
41
41
42
- def extractComments (reflect : Reflection )(comment : Option [reflect.Comment ], rep : Representation ) : (Map [String , EmulatedPackageRepresentation ], String ) => Option [Comment ] = {
43
- import reflect .{given _ , _ }
44
-
42
+ def extractComments (using QuoteContext )(comment : Option [qctx.tasty.Comment ], rep : Representation ) : (Map [String , EmulatedPackageRepresentation ], String ) => Option [Comment ] = {
45
43
comment match {
46
44
case Some (com) =>
47
45
(packages, userDocSyntax) => {
@@ -58,13 +56,13 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
58
56
}
59
57
}
60
58
61
- def extractClassMembers (reflect : Reflection )(body : List [reflect. Statement ], symbol : reflect .Symbol , parentRepresentation : Some [Representation ])(using mutablePackagesMap : scala.collection.mutable.HashMap [String , EmulatedPackageRepresentation ]) : List [Representation with Modifiers ] = {
62
- import reflect .{ given _ , _ }
59
+ def extractClassMembers (using QuoteContext )(body : List [qctx.tasty. Statement ], symbol : qctx.tasty .Symbol , parentRepresentation : Some [Representation ])(using mutablePackagesMap : scala.collection.mutable.HashMap [String , EmulatedPackageRepresentation ]) : List [Representation with Modifiers ] = {
60
+ import qctx . tasty . _
63
61
64
62
/** Filter fields which shouldn't be displayed in the doc
65
63
*/
66
- def filterSymbol (symbol : reflect. Symbol ): Boolean = {
67
- val ownerPath = extractPath(reflect)( symbol.owner)
64
+ def filterSymbol (symbol : Symbol ): Boolean = {
65
+ val ownerPath = extractPath(symbol.owner)
68
66
69
67
! symbol.flags.is(Flags .Synthetic ) &&
70
68
! symbol.flags.is(Flags .Artifact ) &&
@@ -79,16 +77,16 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
79
77
case _ : ValDef => None // No val/var, they are appended with symbol.fields below
80
78
case _ : Inlined => None // Inlined aren't desirable members
81
79
case x => Some (x)
82
- }.filter(x => filterSymbol(x.symbol)).map(convertToRepresentation(reflect)( _, parentRepresentation)) ++
83
- symbol.methods.filter(x => filterSymbol(x)).map{x => convertToRepresentation(reflect)( x.tree, parentRepresentation)} ++
80
+ }.filter(x => filterSymbol(x.symbol)).map(convertToRepresentation(_, parentRepresentation)) ++
81
+ symbol.methods.filter(x => filterSymbol(x)).map{x => convertToRepresentation(x.tree, parentRepresentation)} ++
84
82
symbol.fields.filter { x =>
85
83
filterSymbol(x)
86
84
}.flatMap {
87
85
case x if x.isValDef => Some (x)
88
- // case reflect .IsValDefSymbol(x) => Some(x)
86
+ // case qctx.tasty .IsValDefSymbol(x) => Some(x)
89
87
case _ => None
90
88
}.map { x =>
91
- convertToRepresentation(reflect)( x.tree, parentRepresentation)
89
+ convertToRepresentation(x.tree, parentRepresentation)
92
90
}
93
91
)
94
92
.flatMap{
@@ -98,12 +96,12 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
98
96
.sortBy(_.name)
99
97
}
100
98
101
- def extractParents (reflect : Reflection )(parents : List [reflect .Tree ]): List [Reference ] = {
102
- import reflect .{ given _ , _ }
99
+ def extractParents (using QuoteContext )(parents : List [qctx.tasty .Tree ]): List [Reference ] = {
100
+ import qctx . tasty . _
103
101
104
102
val parentsReferences = parents.map{
105
- case c : TypeTree => convertTypeToReference(reflect)( c.tpe)
106
- case c : Term => convertTypeToReference(reflect)( c.tpe)
103
+ case c : TypeTree => convertTypeToReference(c.tpe)
104
+ case c : Term => convertTypeToReference(c.tpe)
107
105
case _ => throw Exception (" Unhandeld case in parents. Please open an issue." )
108
106
}
109
107
@@ -117,12 +115,12 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
117
115
*
118
116
* @return (is case, is a trait, is an object, the kind as a String)
119
117
*/
120
- def extractKind (reflect : Reflection )(flags : reflect .Flags ): (Boolean , Boolean , Boolean , String ) = {
121
- import reflect .{ given _ , _ }
118
+ def extractKind (using QuoteContext )(flags : qctx.tasty .Flags ): (Boolean , Boolean , Boolean , String ) = {
119
+ import qctx . tasty . _
122
120
123
- val isCase = flags.is(reflect. Flags .Case )
124
- val isTrait = flags.is(reflect. Flags .Trait )
125
- val isObject = flags.is(reflect. Flags .Object )
121
+ val isCase = flags.is(Flags .Case )
122
+ val isTrait = flags.is(Flags .Trait )
123
+ val isObject = flags.is(Flags .Object )
126
124
val kind = {
127
125
if (isTrait){
128
126
" trait"
@@ -142,38 +140,38 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
142
140
(isCase, isTrait, isObject, kind)
143
141
}
144
142
145
- def extractCompanion (reflect : Reflection )(companionModule : Option [reflect. Symbol ], companionClass : Option [reflect .Symbol ], companionIsObject : Boolean ): Option [CompanionReference ] = {
146
- import reflect .{ given _ , _ }
143
+ def extractCompanion (using QuoteContext )(companionModule : Option [qctx.tasty. Symbol ], companionClass : Option [qctx.tasty .Symbol ], companionIsObject : Boolean ): Option [CompanionReference ] = {
144
+ import qctx . tasty . _
147
145
148
146
if (companionIsObject){
149
147
companionModule match {
150
148
case Some (c) =>
151
- val path = extractPath(reflect)( c)
152
- val (_, _, _, kind) = extractKind(reflect)( c.flags)
149
+ val path = extractPath(c)
150
+ val (_, _, _, kind) = extractKind(c.flags)
153
151
Some (CompanionReference (c.name + " $" , path.mkString(" /" , " /" , " " ), kind))
154
152
case None => None
155
153
}
156
154
}else {
157
155
companionClass match {
158
156
case Some (c) =>
159
- val path = extractPath(reflect)( c)
160
- val (_, _, _, kind) = extractKind(reflect)( c.flags)
157
+ val path = extractPath(c)
158
+ val (_, _, _, kind) = extractKind(c.flags)
161
159
Some (CompanionReference (c.name, path.mkString(" /" , " /" , " " ), kind))
162
160
case None => None
163
161
}
164
162
}
165
163
}
166
164
167
- def extractAnnotations (reflect : Reflection )(annots : List [reflect .Term ]): List [TypeReference ] = {
168
- import reflect .{ given _ , _ }
165
+ def extractAnnotations (using QuoteContext )(annots : List [qctx.tasty .Term ]): List [TypeReference ] = {
166
+ import qctx . tasty . _
169
167
170
168
def keepAnnot (label : String , link : String ): Boolean = {
171
169
! (label == " SourceFile" && link == " /internal" ) &&
172
170
! (label == " Child" && link == " /internal" )
173
171
}
174
172
175
173
annots.flatMap{a =>
176
- convertTypeToReference(reflect)( a.tpe) match {
174
+ convertTypeToReference(a.tpe) match {
177
175
case ref@ TypeReference (label, link, _, _) if keepAnnot(label, link) => Some (ref)
178
176
case _ => None
179
177
}
0 commit comments