Skip to content

Commit 073d045

Browse files
committed
Add symbols to Doc AST, needed for @usecase
Also eliminates the need for comment processing to be part of the `DocASTPhase`, so this should be put into a DocMiniPhase
1 parent 265ade0 commit 073d045

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class DocASTPhase extends Phase {
6060
.map { meth =>
6161
track(meth.symbol, ctx, tree.symbol) {
6262
DefImpl(
63+
meth.symbol,
6364
meth.symbol.name.show,
6465
Nil,
6566
path(meth.symbol),
@@ -74,6 +75,7 @@ class DocASTPhase extends Phase {
7475
val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
7576
track(value.symbol, ctx, tree.symbol) {
7677
ValImpl(
78+
value.symbol,
7779
value.symbol.name.show,
7880
Nil, path(value.symbol),
7981
returnType(value.info),
@@ -90,38 +92,38 @@ class DocASTPhase extends Phase {
9092
/** package */
9193
case pd @ PackageDef(pid, st) =>
9294
val newPath = prev :+ pid.name.toString
93-
addEntity(PackageImpl(newPath.mkString("."), collectEntityMembers(st, newPath), newPath))
95+
addEntity(PackageImpl(pd.symbol, newPath.mkString("."), collectEntityMembers(st, newPath), newPath))
9496

9597
/** trait */
9698
case t @ TypeDef(n, rhs) if t.symbol.is(Flags.Trait) =>
9799
val name = n.decode.toString
98100
val newPath = prev :+ name
99101
//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))
102+
TraitImpl(t.symbol, name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), traitParameters(t.symbol), superTypes(t))
101103

102104
/** objects, on the format "Object$" so drop the last letter */
103105
case o @ TypeDef(n, rhs) if o.symbol.is(Flags.Module) =>
104106
val name = n.decode.toString.dropRight(1)
105107
//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))
108+
ObjectImpl(o.symbol, name, collectMembers(rhs, prev :+ name), flags(o), prev :+ (name + "$"), superTypes(o))
107109

108110
/** class / case class */
109111
case c @ TypeDef(n, rhs) if c.symbol.isClass =>
110112
val name = n.decode.toString
111113
val newPath = prev :+ name
112114
//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 {
115+
(c.symbol, name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), constructors(c.symbol), superTypes(c), None) match {
114116
case x if c.symbol.is(Flags.CaseClass) => CaseClassImpl.tupled(x)
115117
case x => ClassImpl.tupled(x)
116118
}
117119

118120
/** def */
119121
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))
122+
DefImpl(d.symbol, d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info))
121123

122124
/** val */
123125
case v: ValDef if !v.symbol.is(Flags.ModuleVal) =>
124-
ValImpl(v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe))
126+
ValImpl(v.symbol, v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe))
125127

126128
case x => {
127129
//dottydoc.println(s"Found unwanted entity: $x (${x.pos},\n${x.show}")

dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ object transform {
7777
def traverse(ent: Entity): Entity = ent match {
7878
case p: Package => transformEntity(p, _.packageTransformation) { p =>
7979
val newPackage = PackageImpl(
80+
p.symbol,
8081
p.name,
8182
p.members.map(traverse),
8283
p.path,
@@ -90,6 +91,7 @@ object transform {
9091
}
9192
case c: Class => transformEntity(c, _.classTransformation) { cls =>
9293
ClassImpl(
94+
cls.symbol,
9395
cls.name,
9496
cls.members.map(traverse),
9597
cls.modifiers,
@@ -102,6 +104,7 @@ object transform {
102104
}
103105
case cc: CaseClass => transformEntity(cc, _.caseClassTransformation) { cc =>
104106
CaseClassImpl(
107+
cc.symbol,
105108
cc.name,
106109
cc.members.map(traverse),
107110
cc.modifiers,
@@ -114,6 +117,7 @@ object transform {
114117
}
115118
case trt: Trait => transformEntity(trt, _.traitTransformation) { trt =>
116119
TraitImpl(
120+
trt.symbol,
117121
trt.name,
118122
trt.members.map(traverse),
119123
trt.modifiers,
@@ -126,6 +130,7 @@ object transform {
126130
}
127131
case obj: Object => transformEntity(obj, _.objectTransformation) { obj =>
128132
ObjectImpl(
133+
obj.symbol,
129134
obj.name,
130135
obj.members.map(traverse),
131136
obj.modifiers,
@@ -136,6 +141,7 @@ object transform {
136141
}
137142
case df: Def => transformEntity(df, _.defTransformation) { df =>
138143
DefImpl(
144+
df.symbol,
139145
df.name,
140146
df.modifiers,
141147
df.path,
@@ -148,6 +154,7 @@ object transform {
148154
}
149155
case vl: Val => transformEntity(vl, _.valTransformation) { vl =>
150156
ValImpl(
157+
vl.symbol,
151158
vl.name,
152159
vl.modifiers,
153160
vl.path,

dottydoc/src/dotty/tools/dottydoc/model/entities.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package model
33

44
import comment._
55
import references._
6+
import dotty.tools.dotc.core.Symbols.{ Symbol, NoSymbol }
67

78
trait Entity {
9+
def symbol: Symbol
10+
811
def name: String
912

1013
/** Path from root, i.e. `scala.Option$` */
@@ -103,6 +106,7 @@ trait Var extends Entity with Modifiers with ReturnValue {
103106

104107
trait NonEntity extends Entity {
105108
val name = ""
109+
val symbol = NoSymbol
106110
val comment = None
107111
val path = Nil
108112
val kind = ""

dottydoc/src/dotty/tools/dottydoc/model/internal.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package model
33

44
import comment.Comment
55
import references._
6+
import dotty.tools.dotc.core.Symbols.Symbol
67

78
object internal {
89

@@ -11,6 +12,7 @@ object internal {
1112
}
1213

1314
final case class PackageImpl(
15+
symbol: Symbol,
1416
name: String,
1517
var members: List[Entity],
1618
path: List[String],
@@ -21,6 +23,7 @@ object internal {
2123
}
2224

2325
final case class ClassImpl(
26+
symbol: Symbol,
2427
name: String,
2528
members: List[Entity],
2629
modifiers: List[String],
@@ -32,6 +35,7 @@ object internal {
3235
) extends Class with Impl
3336

3437
final case class CaseClassImpl(
38+
symbol: Symbol,
3539
name: String,
3640
members: List[Entity],
3741
modifiers: List[String],
@@ -43,6 +47,7 @@ object internal {
4347
) extends CaseClass with Impl
4448

4549
final case class TraitImpl(
50+
symbol: Symbol,
4651
name: String,
4752
members: List[Entity],
4853
modifiers: List[String],
@@ -54,6 +59,7 @@ object internal {
5459
) extends Trait with Impl
5560

5661
final case class ObjectImpl(
62+
symbol: Symbol,
5763
name: String,
5864
members: List[Entity],
5965
modifiers: List[String],
@@ -63,6 +69,7 @@ object internal {
6369
) extends Object with Impl
6470

6571
final case class DefImpl(
72+
symbol: Symbol,
6673
name: String,
6774
modifiers: List[String],
6875
path: List[String],
@@ -74,6 +81,7 @@ object internal {
7481
) extends Def with Impl
7582

7683
final case class ValImpl(
84+
symbol: Symbol,
7785
name: String,
7886
modifiers: List[String],
7987
path: List[String],

dottydoc/test/ConstructorTest.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Constructors extends DottyTest {
2222

2323
checkSources(source :: Nil) { packages =>
2424
packages("scala") match {
25-
case PackageImpl(_, List(cls: Class), _, _) =>
25+
case PackageImpl(_, _, List(cls: Class), _, _) =>
2626
cls.constructors.headOption match {
2727
case Some(ParamListImpl(NamedReference("str", _, false, false) :: Nil, false) :: Nil) =>
2828
// success!
@@ -44,7 +44,7 @@ class Constructors extends DottyTest {
4444

4545
checkSources(source :: Nil) { packages =>
4646
packages("scala") match {
47-
case PackageImpl(_, List(cls: Class), _, _) =>
47+
case PackageImpl(_, _, List(cls: Class), _, _) =>
4848
cls.constructors match {
4949
case (
5050
ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) ::
@@ -69,7 +69,7 @@ class Constructors extends DottyTest {
6969

7070
checkSources(source :: Nil) { packages =>
7171
packages("scala") match {
72-
case PackageImpl(_, List(cls: Class), _, _) =>
72+
case PackageImpl(_, _, List(cls: Class), _, _) =>
7373
cls.constructors match {
7474
case (
7575
ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) ::
@@ -101,7 +101,7 @@ class Constructors extends DottyTest {
101101

102102
checkSources(source :: Nil) { packages =>
103103
packages("scala") match {
104-
case PackageImpl(_, List(cls: Class), _, _) =>
104+
case PackageImpl(_, _, List(cls: Class), _, _) =>
105105
cls.constructors match {
106106
case (
107107
ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil
@@ -139,7 +139,7 @@ class Constructors extends DottyTest {
139139

140140
checkSources(source :: Nil) { packages =>
141141
packages("scala") match {
142-
case PackageImpl(_, List(cls: CaseClass, obj: Object), _, _) =>
142+
case PackageImpl(_, _, List(cls: CaseClass, obj: Object), _, _) =>
143143
cls.constructors match {
144144
case (
145145
ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil
@@ -172,7 +172,7 @@ class Constructors extends DottyTest {
172172

173173
checkSources(source :: Nil) { packages =>
174174
packages("scala") match {
175-
case PackageImpl(_, List(trt: Trait), _, _) =>
175+
case PackageImpl(_, _, List(trt: Trait), _, _) =>
176176
trt.traitParams match {
177177
case ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil =>
178178
case _ =>
@@ -199,7 +199,7 @@ class Constructors extends DottyTest {
199199

200200
checkSources(source :: Nil) { packages =>
201201
packages("scala") match {
202-
case PackageImpl(_, List(cc: CaseClass, _, cls: Class, trt: Trait), _, _) =>
202+
case PackageImpl(_, _, List(cc: CaseClass, _, cls: Class, trt: Trait), _, _) =>
203203
import model.json._
204204
lazy val incorrectJson = s"The json generated for:\n$actualSource\n\nIs not correct"
205205
assert(cc.json.contains(s""""constructors":[[{"list":[{"title":"main""""), incorrectJson)

dottydoc/test/PackageStructure.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PackageStructure extends DottyTest {
2929

3030
checkSources(source1 :: source2 :: Nil) { packages =>
3131
packages("scala") match {
32-
case PackageImpl(_, List(tA, tB), _, _) =>
32+
case PackageImpl(_, _, List(tA, tB), _, _) =>
3333
assert(
3434
tA.name == "A" && tB.name == "B",
3535
s"trait A had name '${tA.name}' and trait B had name '${tB.name}'"
@@ -62,8 +62,9 @@ class PackageStructure extends DottyTest {
6262
checkSources(source1 :: source2 :: Nil) { packages =>
6363
packages("scala") match {
6464
case PackageImpl(
65+
_,
6566
"scala",
66-
List(PackageImpl("scala.collection", List(tA, tB), _, _)),
67+
List(PackageImpl(_, "scala.collection", List(tA, tB), _, _)),
6768
_, _
6869
) =>
6970
assert(
@@ -76,7 +77,7 @@ class PackageStructure extends DottyTest {
7677
}
7778

7879
packages("scala.collection") match {
79-
case PackageImpl("scala.collection", List(tA, tB), _, _) =>
80+
case PackageImpl(_, "scala.collection", List(tA, tB), _, _) =>
8081
assert(
8182
tA.name == "A" && tB.name == "B",
8283
s"trait A had name '${tA.name}' and trait B had name '${tB.name}'"

0 commit comments

Comments
 (0)