@@ -5,10 +5,8 @@ package core
55/** Dotty and Dottydoc imports */
66import dotc .ast .Trees ._
77import dotc .CompilationUnit
8- import dotc .config .Printers .dottydoc
98import dotc .core .Contexts .Context
10- import dotc .core .Comments .ContextDocstrings
11- import dotc .core .Types .{PolyType , NoType }
9+ import dotc .core .Types .PolyType
1210import dotc .core .Phases .Phase
1311import dotc .core .Symbols .{ Symbol , NoSymbol }
1412import dotc .core .NameOps ._
@@ -17,7 +15,6 @@ class DocASTPhase extends Phase {
1715 import model ._
1816 import model .factories ._
1917 import model .internal ._
20- import model .comment .Comment
2118 import dotty .tools .dotc .core .Flags
2219 import dotty .tools .dotc .ast .tpd ._
2320 import dotty .tools .dottydoc .util .syntax ._
@@ -27,20 +24,20 @@ class DocASTPhase extends Phase {
2724 def phaseName = " docASTPhase"
2825
2926 /** Build documentation hierarchy from existing tree */
30- def collect (tree : Tree )(implicit ctx : Context ): Entity = {
27+ def collect (tree : Tree )(implicit ctx : Context ): List [ Entity ] = {
3128 val implicitConversions = ctx.docbase.defs(tree.symbol)
3229
3330 def collectList (xs : List [Tree ]): List [Entity ] =
34- xs.map (collect).filter(_ != NonEntity )
31+ xs.flatMap (collect)
3532
3633 def collectEntityMembers (xs : List [Tree ]) =
3734 collectList(xs).asInstanceOf [List [Entity with Members ]]
3835
3936 def collectMembers (tree : Tree )(implicit ctx : Context ): List [Entity ] = {
40- val defs = ( tree match {
37+ val defs = tree match {
4138 case t : Template => collectList(t.body)
4239 case _ => Nil
43- })
40+ }
4441
4542 defs ++ implicitConversions.flatMap(membersFromSymbol)
4643 }
@@ -83,55 +80,57 @@ class DocASTPhase extends Phase {
8380 }
8481
8582
86- if (tree.symbol.is(Flags .Synthetic ) && ! tree.symbol.is(Flags .Module )) NonEntity
83+ if (tree.symbol.is(Flags .Synthetic ) && ! tree.symbol.is(Flags .Module )) Nil
8784 else tree match {
8885 /** package */
8986 case pd @ PackageDef (pid, st) =>
90- addPackage(PackageImpl (pd.symbol, annotations(pd.symbol), pd.symbol.showFullName, collectEntityMembers(st), path(pd.symbol)))
87+ addPackage(PackageImpl (pd.symbol, annotations(pd.symbol), pd.symbol.showFullName, collectEntityMembers(st), path(pd.symbol))) :: Nil
9188
9289 /** type alias */
9390 case t : TypeDef if ! t.isClassDef =>
9491 val sym = t.symbol
9592 if (sym.is(Flags .Synthetic | Flags .Param ))
96- NonEntity
93+ Nil
9794 else {
9895 val tparams = t.rhs.tpe match {
9996 case tp : PolyType => tp.paramNames.map(_.show)
10097 case _ => Nil
10198 }
102- TypeAliasImpl (sym, annotations(sym), flags(t), t.name.show.split(" \\ $\\ $" ).last, path(sym), alias(t.rhs.tpe), tparams)
99+ TypeAliasImpl (sym, annotations(sym), flags(t), t.name.show.split(" \\ $\\ $" ).last, path(sym), alias(t.rhs.tpe), tparams) :: Nil
103100 }
104101
105102 /** trait */
106103 case t @ TypeDef (n, rhs) if t.symbol.is(Flags .Trait ) =>
107104 // TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
108- TraitImpl (t.symbol, annotations(t.symbol), n.show, collectMembers(rhs), flags(t), path(t.symbol), typeParams(t.symbol), traitParameters(t.symbol), superTypes(t))
105+ TraitImpl (t.symbol, annotations(t.symbol), n.show, collectMembers(rhs), flags(t), path(t.symbol), typeParams(t.symbol), traitParameters(t.symbol), superTypes(t)) :: Nil
109106
110107 /** objects, on the format "Object$" so drop the last letter */
111108 case o @ TypeDef (n, rhs) if o.symbol.is(Flags .Module ) =>
112109 // TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
113- ObjectImpl (o.symbol, annotations(o.symbol), o.name.stripModuleClassSuffix.show, collectMembers(rhs), flags(o), path(o.symbol), superTypes(o))
110+ ObjectImpl (o.symbol, annotations(o.symbol), o.name.stripModuleClassSuffix.show, collectMembers(rhs), flags(o), path(o.symbol), superTypes(o)) :: Nil
114111
115112 /** class / case class */
116113 case c @ TypeDef (n, rhs) if c.symbol.isClass =>
117114 // TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
118- (c.symbol, annotations(c.symbol), n.show, collectMembers(rhs), flags(c), path(c.symbol), typeParams(c.symbol), constructors(c.symbol), superTypes(c), None , Nil , NonEntity ) match {
119- case x if c.symbol.is(Flags .CaseClass ) => CaseClassImpl .tupled(x)
120- case x => ClassImpl .tupled(x)
115+ val parameters = (c.symbol, annotations(c.symbol), n.show, collectMembers(rhs), flags(c), path(c.symbol), typeParams(c.symbol), constructors(c.symbol), superTypes(c), None , Nil , None )
116+ if (c.symbol.is(Flags .CaseClass )) {
117+ CaseClassImpl .tupled(parameters) :: Nil
118+ } else {
119+ ClassImpl .tupled(parameters) :: Nil
121120 }
122121
123122 /** def */
124123 case d : DefDef =>
125- DefImpl (d.symbol, annotations(d.symbol), d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info))
124+ DefImpl (d.symbol, annotations(d.symbol), d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info)) :: Nil
126125
127126 /** val */
128127 case v : ValDef if ! v.symbol.is(Flags .ModuleVal ) =>
129128 val kind = if (v.symbol.is(Flags .Mutable )) " var" else " val"
130- ValImpl (v.symbol, annotations(v.symbol), v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe), kind)
129+ ValImpl (v.symbol, annotations(v.symbol), v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe), kind) :: Nil
131130
132131 case x => {
133132 ctx.docbase.debug(s " Found unwanted entity: $x ( ${x.pos}, \n ${x.show}" )
134- NonEntity
133+ Nil
135134 }
136135 }
137136 }
@@ -158,7 +157,7 @@ class DocASTPhase extends Phase {
158157 if (old.annotations.isEmpty) old.annotations = newPkg.annotations
159158 mergeMembers(newPkg, old)
160159 if (old.superTypes.isEmpty) old.superTypes = newPkg.superTypes
161- if (! old.comment.isDefined ) old.comment = newPkg.comment
160+ if (old.comment.isEmpty ) old.comment = newPkg.comment
162161 old
163162 }
164163
@@ -178,9 +177,9 @@ class DocASTPhase extends Phase {
178177 def createAndInsert (currentPkg : PackageImpl , path : List [String ]): PackageImpl = {
179178 (path : @ unchecked) match {
180179 case x :: Nil => {
181- val existingPkg = currentPkg.members.collect {
180+ val existingPkg = currentPkg.members.collectFirst {
182181 case p : PackageImpl if p.name == newPkg.name => p
183- }.headOption
182+ }
184183
185184 if (existingPkg.isDefined) mergedPackages(existingPkg.get, newPkg)
186185 else {
@@ -190,9 +189,9 @@ class DocASTPhase extends Phase {
190189 }
191190 case x :: xs => {
192191 val subPkg = s " ${currentPkg.name}. $x"
193- val existingPkg = currentPkg.members.collect {
192+ val existingPkg = currentPkg.members.collectFirst {
194193 case p : PackageImpl if p.name == subPkg => p
195- }.headOption
194+ }
196195
197196 if (existingPkg.isDefined) createAndInsert(existingPkg.get, xs)
198197 else {
0 commit comments