@@ -5,7 +5,7 @@ package tasty
5
5
import java .util .regex .Pattern
6
6
7
7
import scala .util .{Try , Success , Failure }
8
- import scala .tasty .inspector .{ TastyInspector , Inspector , Tasty }
8
+ import scala .tasty .inspector .DocTastyInspector
9
9
import scala .quoted ._
10
10
11
11
import dotty .tools .dotc
@@ -24,12 +24,24 @@ import ScaladocSupport._
24
24
*
25
25
* Delegates most of the work to [[TastyParser ]] [[dotty.tools.scaladoc.tasty.TastyParser ]].
26
26
*/
27
- case class ScaladocTastyInspector ()(using ctx : DocContext ) extends Inspector :
27
+ case class ScaladocTastyInspector ()(using ctx : DocContext ) extends DocTastyInspector :
28
28
29
29
private val topLevels = Seq .newBuilder[(String , Member )]
30
30
private var rootDoc : Option [Comment ] = None
31
31
32
- def inspect (using Quotes )(tastys : List [scala.tasty.inspector.Tasty [quotes.type ]]): Unit =
32
+ def processCompilationUnit (using Quotes )(root : reflect.Tree ): Unit = ()
33
+
34
+ override def postProcess (using Quotes ): Unit =
35
+ // hack into the compiler to get a list of all top-level trees
36
+ // in principle, to do this, one would collect trees in processCompilationUnit
37
+ // however, path-dependent types disallow doing so w/o using casts
38
+ inline def hackForeachTree (thunk : reflect.Tree => Unit ): Unit =
39
+ given dctx : dotc.core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
40
+ dctx.run.nn.units.foreach { compilationUnit =>
41
+ // mirrors code from TastyInspector
42
+ thunk(compilationUnit.tpdTree.asInstanceOf [reflect.Tree ])
43
+ }
44
+
33
45
val symbolsToSkip : Set [reflect.Symbol ] =
34
46
ctx.args.identifiersToSkip.flatMap { ref =>
35
47
val qrSymbol = reflect.Symbol
@@ -104,8 +116,7 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends Inspector:
104
116
rootDoc = Some (parseCommentString(using parser.qctx, summon[DocContext ])(content, topLevelPck, None ))
105
117
}
106
118
107
- for tasty <- tastys do {
108
- val root = tasty.ast
119
+ hackForeachTree { root =>
109
120
if ! isSkipped(root.symbol) then
110
121
val treeRoot = root.asInstanceOf [parser.qctx.reflect.Tree ]
111
122
processRootDocIfNeeded(treeRoot)
@@ -130,7 +141,23 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends Inspector:
130
141
topLevels += " scala" -> Member (scalaPckg.fullName, " " , scalaPckg.dri, Kind .Package )
131
142
topLevels += mergeAnyRefAliasAndObject(parser)
132
143
144
+ def result (): (List [Member ], Option [Comment ]) =
145
+ topLevels.clear()
146
+ rootDoc = None
147
+ val filePaths = ctx.args.tastyFiles.map(_.getAbsolutePath).toList
148
+ val classpath = ctx.args.classpath.split(java.io.File .pathSeparator).toList
133
149
150
+ if filePaths.nonEmpty then inspectFilesInContext(classpath, filePaths)
151
+
152
+ val all = topLevels.result()
153
+ all.groupBy(_._1).map { case (pckName, members) =>
154
+ val (pcks, rest) = members.map(_._2).partition(_.kind == Kind .Package )
155
+ val basePck = pcks.reduce( (p1, p2) =>
156
+ val withNewMembers = p1.withNewMembers(p2.members)
157
+ if withNewMembers.docs.isEmpty then withNewMembers.withDocs(p2.docs) else withNewMembers
158
+ )
159
+ basePck.withMembers((basePck.members ++ rest).sortBy(_.name))
160
+ }.toList -> rootDoc
134
161
135
162
def mergeAnyRefAliasAndObject (parser : TastyParser ) =
136
163
import parser .qctx .reflect ._
@@ -144,36 +171,6 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends Inspector:
144
171
kind = Kind .Class (Nil , Nil ),
145
172
members = objectMembers
146
173
)
147
-
148
- object ScaladocTastyInspector :
149
-
150
- def loadDocs ()(using ctx : DocContext ): (List [Member ], Option [Comment ]) =
151
- val filePaths = ctx.args.tastyFiles.map(_.getAbsolutePath).toList
152
- val classpath = ctx.args.classpath.split(java.io.File .pathSeparator).toList
153
-
154
- val inspector = new ScaladocTastyInspector
155
-
156
- val (tastyPaths, nonTastyPaths) = filePaths.partition(_.endsWith(" .tasty" ))
157
- val (jarPaths, invalidPaths) = nonTastyPaths.partition(_.endsWith(" .jar" ))
158
-
159
- for invalidPath <- invalidPaths do
160
- report.error(" File extension is not `tasty` or `jar`: " + invalidPath)
161
-
162
- if tastyPaths.nonEmpty then
163
- TastyInspector .inspectAllTastyFiles(tastyPaths, jarPaths, classpath)(inspector)
164
-
165
- val all = inspector.topLevels.result()
166
- all.groupBy(_._1).map { case (pckName, members) =>
167
- val (pcks, rest) = members.map(_._2).partition(_.kind == Kind .Package )
168
- val basePck = pcks.reduce( (p1, p2) =>
169
- val withNewMembers = p1.withNewMembers(p2.members)
170
- if withNewMembers.docs.isEmpty then withNewMembers.withDocs(p2.docs) else withNewMembers
171
- )
172
- basePck.withMembers((basePck.members ++ rest).sortBy(_.name))
173
- }.toList -> inspector.rootDoc
174
-
175
- end ScaladocTastyInspector
176
-
177
174
/** Parses a single Tasty compilation unit. */
178
175
case class TastyParser (
179
176
qctx : Quotes ,
0 commit comments