@@ -5,10 +5,8 @@ package core
5
5
/** Dotty and Dottydoc imports */
6
6
import dotc .ast .Trees ._
7
7
import dotc .CompilationUnit
8
- import dotc .config .Printers .dottydoc
9
8
import dotc .core .Contexts .Context
10
- import dotc .core .Comments .ContextDocstrings
11
- import dotc .core .Types .{PolyType , NoType }
9
+ import dotc .core .Types .PolyType
12
10
import dotc .core .Phases .Phase
13
11
import dotc .core .Symbols .{ Symbol , NoSymbol }
14
12
import dotc .core .NameOps ._
@@ -17,7 +15,6 @@ class DocASTPhase extends Phase {
17
15
import model ._
18
16
import model .factories ._
19
17
import model .internal ._
20
- import model .comment .Comment
21
18
import dotty .tools .dotc .core .Flags
22
19
import dotty .tools .dotc .ast .tpd ._
23
20
import dotty .tools .dottydoc .util .syntax ._
@@ -27,20 +24,20 @@ class DocASTPhase extends Phase {
27
24
def phaseName = " docASTPhase"
28
25
29
26
/** 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 ] = {
31
28
val implicitConversions = ctx.docbase.defs(tree.symbol)
32
29
33
30
def collectList (xs : List [Tree ]): List [Entity ] =
34
- xs.map (collect).filter(_ != NonEntity )
31
+ xs.flatMap (collect)
35
32
36
33
def collectEntityMembers (xs : List [Tree ]) =
37
34
collectList(xs).asInstanceOf [List [Entity with Members ]]
38
35
39
36
def collectMembers (tree : Tree )(implicit ctx : Context ): List [Entity ] = {
40
- val defs = ( tree match {
37
+ val defs = tree match {
41
38
case t : Template => collectList(t.body)
42
39
case _ => Nil
43
- })
40
+ }
44
41
45
42
defs ++ implicitConversions.flatMap(membersFromSymbol)
46
43
}
@@ -83,55 +80,57 @@ class DocASTPhase extends Phase {
83
80
}
84
81
85
82
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
87
84
else tree match {
88
85
/** package */
89
86
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
91
88
92
89
/** type alias */
93
90
case t : TypeDef if ! t.isClassDef =>
94
91
val sym = t.symbol
95
92
if (sym.is(Flags .Synthetic | Flags .Param ))
96
- NonEntity
93
+ Nil
97
94
else {
98
95
val tparams = t.rhs.tpe match {
99
96
case tp : PolyType => tp.paramNames.map(_.show)
100
97
case _ => Nil
101
98
}
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
103
100
}
104
101
105
102
/** trait */
106
103
case t @ TypeDef (n, rhs) if t.symbol.is(Flags .Trait ) =>
107
104
// 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
109
106
110
107
/** objects, on the format "Object$" so drop the last letter */
111
108
case o @ TypeDef (n, rhs) if o.symbol.is(Flags .Module ) =>
112
109
// 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
114
111
115
112
/** class / case class */
116
113
case c @ TypeDef (n, rhs) if c.symbol.isClass =>
117
114
// 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
121
120
}
122
121
123
122
/** def */
124
123
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
126
125
127
126
/** val */
128
127
case v : ValDef if ! v.symbol.is(Flags .ModuleVal ) =>
129
128
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
131
130
132
131
case x => {
133
132
ctx.docbase.debug(s " Found unwanted entity: $x ( ${x.pos}, \n ${x.show}" )
134
- NonEntity
133
+ Nil
135
134
}
136
135
}
137
136
}
@@ -158,7 +157,7 @@ class DocASTPhase extends Phase {
158
157
if (old.annotations.isEmpty) old.annotations = newPkg.annotations
159
158
mergeMembers(newPkg, old)
160
159
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
162
161
old
163
162
}
164
163
@@ -178,9 +177,9 @@ class DocASTPhase extends Phase {
178
177
def createAndInsert (currentPkg : PackageImpl , path : List [String ]): PackageImpl = {
179
178
(path : @ unchecked) match {
180
179
case x :: Nil => {
181
- val existingPkg = currentPkg.members.collect {
180
+ val existingPkg = currentPkg.members.collectFirst {
182
181
case p : PackageImpl if p.name == newPkg.name => p
183
- }.headOption
182
+ }
184
183
185
184
if (existingPkg.isDefined) mergedPackages(existingPkg.get, newPkg)
186
185
else {
@@ -190,9 +189,9 @@ class DocASTPhase extends Phase {
190
189
}
191
190
case x :: xs => {
192
191
val subPkg = s " ${currentPkg.name}. $x"
193
- val existingPkg = currentPkg.members.collect {
192
+ val existingPkg = currentPkg.members.collectFirst {
194
193
case p : PackageImpl if p.name == subPkg => p
195
- }.headOption
194
+ }
196
195
197
196
if (existingPkg.isDefined) createAndInsert(existingPkg.get, xs)
198
197
else {
0 commit comments