@@ -7,36 +7,25 @@ import dotc.ast.Trees._
7
7
import dotc .CompilationUnit
8
8
import dotc .config .Printers .dottydoc
9
9
import dotc .core .Contexts .Context
10
+ import dotc .core .Comments .ContextDocstrings
10
11
import dotc .core .Phases .Phase
11
12
import dotc .core .Symbols .{ Symbol , NoSymbol }
12
13
13
14
class DocASTPhase extends Phase {
14
15
import model ._
15
16
import model .factories ._
16
17
import model .internal ._
17
- import model .parsers .WikiParser
18
18
import model .comment .Comment
19
19
import dotty .tools .dotc .core .Flags
20
20
import dotty .tools .dotc .ast .tpd ._
21
+ import dotty .tools .dottydoc .util .syntax ._
21
22
import util .traversing ._
22
23
import util .internal .setters ._
23
24
24
25
def phaseName = " docphase"
25
26
26
- private [this ] val commentParser = new WikiParser
27
-
28
- /** Saves the commentParser function for later evaluation, for when the AST has been filled */
29
- def track (symbol : Symbol , ctx : Context , parent : Symbol = NoSymbol )(op : => Entity ) = {
30
- val entity = op
31
-
32
- if (entity != NonEntity )
33
- commentParser += (entity, symbol, parent, ctx)
34
-
35
- entity
36
- }
37
-
38
27
/** Build documentation hierarchy from existing tree */
39
- def collect (tree : Tree , prev : List [String ] = Nil )(implicit ctx : Context ): Entity = track(tree.symbol, ctx) {
28
+ def collect (tree : Tree , prev : List [String ] = Nil )(implicit ctx : Context ): Entity = {
40
29
val implicitConversions = ctx.docbase.defs(tree.symbol)
41
30
42
31
def collectList (xs : List [Tree ], ps : List [String ]): List [Entity ] =
@@ -58,28 +47,26 @@ class DocASTPhase extends Phase {
58
47
val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags .Method , Flags .Synthetic | Flags .Private )
59
48
.filterNot(_.symbol.owner.name.show == " Any" )
60
49
.map { meth =>
61
- track(meth.symbol, ctx, tree.symbol) {
62
- DefImpl (
63
- meth.symbol.name.show,
64
- Nil ,
65
- path(meth.symbol),
66
- returnType(meth.info),
67
- typeParams(meth.symbol),
68
- paramLists(meth.info),
69
- implicitlyAddedFrom = Some (returnType(meth.symbol.owner.info))
70
- )
71
- }
50
+ DefImpl (
51
+ meth.symbol,
52
+ meth.symbol.name.show,
53
+ Nil ,
54
+ path(meth.symbol),
55
+ returnType(meth.info),
56
+ typeParams(meth.symbol),
57
+ paramLists(meth.info),
58
+ implicitlyAddedFrom = Some (returnType(meth.symbol.owner.info))
59
+ )
72
60
}.toList
73
61
74
62
val vals = sym.info.fields.filterNot(_.symbol.is(Flags .Private | Flags .Synthetic )).map { value =>
75
- track(value.symbol, ctx, tree.symbol) {
76
- ValImpl (
77
- value.symbol.name.show,
78
- Nil , path(value.symbol),
79
- returnType(value.info),
80
- implicitlyAddedFrom = Some (returnType(value.symbol.owner.info))
81
- )
82
- }
63
+ ValImpl (
64
+ value.symbol,
65
+ value.symbol.name.show,
66
+ Nil , path(value.symbol),
67
+ returnType(value.info),
68
+ implicitlyAddedFrom = Some (returnType(value.symbol.owner.info))
69
+ )
83
70
}
84
71
85
72
defs ++ vals
@@ -90,38 +77,38 @@ class DocASTPhase extends Phase {
90
77
/** package */
91
78
case pd @ PackageDef (pid, st) =>
92
79
val newPath = prev :+ pid.name.toString
93
- addEntity(PackageImpl (newPath.mkString(" ." ), collectEntityMembers(st, newPath), newPath))
80
+ addEntity(PackageImpl (pd.symbol, newPath.mkString(" ." ), collectEntityMembers(st, newPath), newPath))
94
81
95
82
/** trait */
96
83
case t @ TypeDef (n, rhs) if t.symbol.is(Flags .Trait ) =>
97
84
val name = n.decode.toString
98
85
val newPath = prev :+ name
99
86
// TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
100
- TraitImpl (name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), traitParameters(t.symbol), superTypes(t))
87
+ TraitImpl (t.symbol, name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), traitParameters(t.symbol), superTypes(t))
101
88
102
89
/** objects, on the format "Object$" so drop the last letter */
103
90
case o @ TypeDef (n, rhs) if o.symbol.is(Flags .Module ) =>
104
91
val name = n.decode.toString.dropRight(1 )
105
92
// TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
106
- ObjectImpl (name, collectMembers(rhs, prev :+ name), flags(o), prev :+ (name + " $" ), superTypes(o))
93
+ ObjectImpl (o.symbol, name, collectMembers(rhs, prev :+ name), flags(o), prev :+ (name + " $" ), superTypes(o))
107
94
108
95
/** class / case class */
109
96
case c @ TypeDef (n, rhs) if c.symbol.isClass =>
110
97
val name = n.decode.toString
111
98
val newPath = prev :+ name
112
99
// TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well
113
- (name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), constructors(c.symbol), superTypes(c), None ) match {
100
+ (c.symbol, name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), constructors(c.symbol), superTypes(c), None ) match {
114
101
case x if c.symbol.is(Flags .CaseClass ) => CaseClassImpl .tupled(x)
115
102
case x => ClassImpl .tupled(x)
116
103
}
117
104
118
105
/** def */
119
106
case d : DefDef =>
120
- DefImpl (d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info))
107
+ DefImpl (d.symbol, d. name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info))
121
108
122
109
/** val */
123
110
case v : ValDef if ! v.symbol.is(Flags .ModuleVal ) =>
124
- ValImpl (v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe))
111
+ ValImpl (v.symbol, v. name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe))
125
112
126
113
case x => {
127
114
// dottydoc.println(s"Found unwanted entity: $x (${x.pos},\n${x.show}")
@@ -175,15 +162,8 @@ class DocASTPhase extends Phase {
175
162
child <- parent.children
176
163
} setParent(child, to = parent)
177
164
178
- // (3) Create documentation template from docstrings, with internal links
179
- println(" Generating documentation, this might take a while..." )
180
- commentParser.parse(packages)
181
-
182
- // (4) Clear caches
183
- commentParser.clear()
184
-
185
- // (5) Update Doc AST in ctx.base
186
- for (kv <- packages) ctx.docbase.packages += kv
165
+ // (3) Update Doc AST in ctx.base
166
+ for (kv <- packages) ctx.docbase.packagesMutable += kv
187
167
188
168
// Return super's result
189
169
compUnits
0 commit comments