@@ -5,7 +5,7 @@ package tasty
55import java .util .regex .Pattern
66
77import scala .util .{Try , Success , Failure }
8- import scala .tasty .inspector .DocTastyInspector
8+ import scala .tasty .inspector .{ TastyInspector , Inspector , Tasty }
99import scala .quoted ._
1010
1111import dotty .tools .dotc
@@ -24,24 +24,12 @@ import ScaladocSupport._
2424 *
2525 * Delegates most of the work to [[TastyParser ]] [[dotty.tools.scaladoc.tasty.TastyParser ]].
2626 */
27- case class ScaladocTastyInspector ()(using ctx : DocContext ) extends DocTastyInspector :
27+ case class ScaladocTastyInspector ()(using ctx : DocContext ) extends Inspector :
2828
2929 private val topLevels = Seq .newBuilder[(String , Member )]
3030 private var rootDoc : Option [Comment ] = None
3131
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 =
4533 val symbolsToSkip : Set [reflect.Symbol ] =
4634 ctx.args.identifiersToSkip.flatMap { ref =>
4735 val qrSymbol = reflect.Symbol
@@ -116,7 +104,8 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends DocTastyInspe
116104 rootDoc = Some (parseCommentString(using parser.qctx, summon[DocContext ])(content, topLevelPck, None ))
117105 }
118106
119- hackForeachTree { root =>
107+ for tasty <- tastys do {
108+ val root = tasty.ast
120109 if ! isSkipped(root.symbol) then
121110 val treeRoot = root.asInstanceOf [parser.qctx.reflect.Tree ]
122111 processRootDocIfNeeded(treeRoot)
@@ -138,33 +127,47 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends DocTastyInspe
138127 topLevels += " scala" -> Member (scalaPckg.fullName, " " , scalaPckg.dri, Kind .Package )
139128 topLevels += mergeAnyRefAliasAndObject(parser)
140129
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 ]) =
144145 val filePaths = ctx.args.tastyFiles.map(_.getAbsolutePath).toList
145146 val classpath = ctx.args.classpath.split(java.io.File .pathSeparator).toList
146147
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)
148158
149- val all = topLevels.result()
159+ val all = inspector. topLevels.result()
150160 all.groupBy(_._1).map { case (pckName, members) =>
151161 val (pcks, rest) = members.map(_._2).partition(_.kind == Kind .Package )
152162 val basePck = pcks.reduce( (p1, p2) =>
153163 val withNewMembers = p1.withNewMembers(p2.members)
154164 if withNewMembers.docs.isEmpty then withNewMembers.withDocs(p2.docs) else withNewMembers
155165 )
156166 basePck.withMembers((basePck.members ++ rest).sortBy(_.name))
157- }.toList -> rootDoc
167+ }.toList -> inspector.rootDoc
168+
169+ end ScaladocTastyInspector
158170
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- )
168171/** Parses a single Tasty compilation unit. */
169172case class TastyParser (
170173 qctx : Quotes ,
0 commit comments