@@ -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 .DocTastyInspector
8
+ import scala .tasty .inspector .{ TastyInspector , Inspector , Tasty }
9
9
import scala .quoted ._
10
10
11
11
import dotty .tools .dotc
@@ -24,24 +24,12 @@ 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 DocTastyInspector :
27
+ case class ScaladocTastyInspector ()(using ctx : DocContext ) extends Inspector :
28
28
29
29
private val topLevels = Seq .newBuilder[(String , Member )]
30
30
private var rootDoc : Option [Comment ] = None
31
31
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
-
32
+ def inspect (using Quotes )(tastys : List [scala.tasty.inspector.Tasty [quotes.type ]]): Unit =
45
33
val symbolsToSkip : Set [reflect.Symbol ] =
46
34
ctx.args.identifiersToSkip.flatMap { ref =>
47
35
val qrSymbol = reflect.Symbol
@@ -116,7 +104,8 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends DocTastyInspe
116
104
rootDoc = Some (parseCommentString(using parser.qctx, summon[DocContext ])(content, topLevelPck, None ))
117
105
}
118
106
119
- hackForeachTree { root =>
107
+ for tasty <- tastys do {
108
+ val root = tasty.ast
120
109
if ! isSkipped(root.symbol) then
121
110
val treeRoot = root.asInstanceOf [parser.qctx.reflect.Tree ]
122
111
processRootDocIfNeeded(treeRoot)
@@ -138,33 +127,47 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends DocTastyInspe
138
127
topLevels += " scala" -> Member (scalaPckg.fullName, " " , scalaPckg.dri, Kind .Package )
139
128
topLevels += mergeAnyRefAliasAndObject(parser)
140
129
141
- def result (): (List [Member ], Option [Comment ]) =
142
- topLevels.clear()
143
- rootDoc = None
130
+
131
+
132
+ def mergeAnyRefAliasAndObject (parser : TastyParser ) =
133
+ import parser .qctx .reflect ._
134
+ val javaLangObjectDef = defn.ObjectClass .tree.asInstanceOf [ClassDef ]
135
+ val objectMembers = parser.extractPatchedMembers(javaLangObjectDef)
136
+ val aM = parser.parseTypeDef(defn.AnyRefClass .tree.asInstanceOf [TypeDef ])
137
+ " scala" -> aM.copy(
138
+ kind = Kind .Class (Nil , Nil ),
139
+ members = objectMembers
140
+ )
141
+
142
+ object ScaladocTastyInspector :
143
+
144
+ def loadDocs ()(using ctx : DocContext ): (List [Member ], Option [Comment ]) =
144
145
val filePaths = ctx.args.tastyFiles.map(_.getAbsolutePath).toList
145
146
val classpath = ctx.args.classpath.split(java.io.File .pathSeparator).toList
146
147
147
- if filePaths.nonEmpty then inspectFilesInContext(classpath, filePaths)
148
+ val inspector = new ScaladocTastyInspector
149
+
150
+ val (tastyPaths, nonTastyPaths) = filePaths.partition(_.endsWith(" .tasty" ))
151
+ val (jarPaths, invalidPaths) = nonTastyPaths.partition(_.endsWith(" .jar" ))
152
+
153
+ for invalidPath <- invalidPaths do
154
+ report.error(" File extension is not `tasty` or `jar`: " + invalidPath)
155
+
156
+ if tastyPaths.nonEmpty then
157
+ TastyInspector .inspectAllTastyFiles(tastyPaths, jarPaths, classpath)(inspector)
148
158
149
- val all = topLevels.result()
159
+ val all = inspector. topLevels.result()
150
160
all.groupBy(_._1).map { case (pckName, members) =>
151
161
val (pcks, rest) = members.map(_._2).partition(_.kind == Kind .Package )
152
162
val basePck = pcks.reduce( (p1, p2) =>
153
163
val withNewMembers = p1.withNewMembers(p2.members)
154
164
if withNewMembers.docs.isEmpty then withNewMembers.withDocs(p2.docs) else withNewMembers
155
165
)
156
166
basePck.withMembers((basePck.members ++ rest).sortBy(_.name))
157
- }.toList -> rootDoc
167
+ }.toList -> inspector.rootDoc
168
+
169
+ end ScaladocTastyInspector
158
170
159
- def mergeAnyRefAliasAndObject (parser : TastyParser ) =
160
- import parser .qctx .reflect ._
161
- val javaLangObjectDef = defn.ObjectClass .tree.asInstanceOf [ClassDef ]
162
- val objectMembers = parser.extractPatchedMembers(javaLangObjectDef)
163
- val aM = parser.parseTypeDef(defn.AnyRefClass .tree.asInstanceOf [TypeDef ])
164
- " scala" -> aM.copy(
165
- kind = Kind .Class (Nil , Nil ),
166
- members = objectMembers
167
- )
168
171
/** Parses a single Tasty compilation unit. */
169
172
case class TastyParser (
170
173
qctx : Quotes ,
0 commit comments