diff options
Diffstat (limited to 'dottydoc')
6 files changed, 38 insertions, 16 deletions
diff --git a/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala index 7744752ce..8df00d894 100644 --- a/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala +++ b/dottydoc/src/dotty/tools/dottydoc/core/DocASTPhase.scala @@ -60,6 +60,7 @@ class DocASTPhase extends Phase { .map { meth => track(meth.symbol, ctx, tree.symbol) { DefImpl( + meth.symbol, meth.symbol.name.show, Nil, path(meth.symbol), @@ -74,6 +75,7 @@ class DocASTPhase extends Phase { val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value => track(value.symbol, ctx, tree.symbol) { ValImpl( + value.symbol, value.symbol.name.show, Nil, path(value.symbol), returnType(value.info), @@ -90,38 +92,38 @@ class DocASTPhase extends Phase { /** package */ case pd @ PackageDef(pid, st) => val newPath = prev :+ pid.name.toString - addEntity(PackageImpl(newPath.mkString("."), collectEntityMembers(st, newPath), newPath)) + addEntity(PackageImpl(pd.symbol, newPath.mkString("."), collectEntityMembers(st, newPath), newPath)) /** trait */ case t @ TypeDef(n, rhs) if t.symbol.is(Flags.Trait) => val name = n.decode.toString val newPath = prev :+ name //TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well - TraitImpl(name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), traitParameters(t.symbol), superTypes(t)) + TraitImpl(t.symbol, name, collectMembers(rhs), flags(t), newPath, typeParams(t.symbol), traitParameters(t.symbol), superTypes(t)) /** objects, on the format "Object$" so drop the last letter */ case o @ TypeDef(n, rhs) if o.symbol.is(Flags.Module) => val name = n.decode.toString.dropRight(1) //TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well - ObjectImpl(name, collectMembers(rhs, prev :+ name), flags(o), prev :+ (name + "$"), superTypes(o)) + ObjectImpl(o.symbol, name, collectMembers(rhs, prev :+ name), flags(o), prev :+ (name + "$"), superTypes(o)) /** class / case class */ case c @ TypeDef(n, rhs) if c.symbol.isClass => val name = n.decode.toString val newPath = prev :+ name //TODO: should not `collectMember` from `rhs` - instead: get from symbol, will get inherited members as well - (name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), constructors(c.symbol), superTypes(c), None) match { + (c.symbol, name, collectMembers(rhs), flags(c), newPath, typeParams(c.symbol), constructors(c.symbol), superTypes(c), None) match { case x if c.symbol.is(Flags.CaseClass) => CaseClassImpl.tupled(x) case x => ClassImpl.tupled(x) } /** def */ case d: DefDef => - DefImpl(d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info)) + DefImpl(d.symbol, d.name.decode.toString, flags(d), path(d.symbol), returnType(d.tpt.tpe), typeParams(d.symbol), paramLists(d.symbol.info)) /** val */ case v: ValDef if !v.symbol.is(Flags.ModuleVal) => - ValImpl(v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe)) + ValImpl(v.symbol, v.name.decode.toString, flags(v), path(v.symbol), returnType(v.tpt.tpe)) case x => { //dottydoc.println(s"Found unwanted entity: $x (${x.pos},\n${x.show}") diff --git a/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala b/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala index 2690ac7b7..fc0b40955 100644 --- a/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala +++ b/dottydoc/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala @@ -77,6 +77,7 @@ object transform { def traverse(ent: Entity): Entity = ent match { case p: Package => transformEntity(p, _.packageTransformation) { p => val newPackage = PackageImpl( + p.symbol, p.name, p.members.map(traverse), p.path, @@ -90,6 +91,7 @@ object transform { } case c: Class => transformEntity(c, _.classTransformation) { cls => ClassImpl( + cls.symbol, cls.name, cls.members.map(traverse), cls.modifiers, @@ -102,6 +104,7 @@ object transform { } case cc: CaseClass => transformEntity(cc, _.caseClassTransformation) { cc => CaseClassImpl( + cc.symbol, cc.name, cc.members.map(traverse), cc.modifiers, @@ -114,6 +117,7 @@ object transform { } case trt: Trait => transformEntity(trt, _.traitTransformation) { trt => TraitImpl( + trt.symbol, trt.name, trt.members.map(traverse), trt.modifiers, @@ -126,6 +130,7 @@ object transform { } case obj: Object => transformEntity(obj, _.objectTransformation) { obj => ObjectImpl( + obj.symbol, obj.name, obj.members.map(traverse), obj.modifiers, @@ -136,6 +141,7 @@ object transform { } case df: Def => transformEntity(df, _.defTransformation) { df => DefImpl( + df.symbol, df.name, df.modifiers, df.path, @@ -148,6 +154,7 @@ object transform { } case vl: Val => transformEntity(vl, _.valTransformation) { vl => ValImpl( + vl.symbol, vl.name, vl.modifiers, vl.path, diff --git a/dottydoc/src/dotty/tools/dottydoc/model/entities.scala b/dottydoc/src/dotty/tools/dottydoc/model/entities.scala index 76792070c..52379f9ad 100644 --- a/dottydoc/src/dotty/tools/dottydoc/model/entities.scala +++ b/dottydoc/src/dotty/tools/dottydoc/model/entities.scala @@ -3,8 +3,11 @@ package model import comment._ import references._ +import dotty.tools.dotc.core.Symbols.{ Symbol, NoSymbol } trait Entity { + def symbol: Symbol + def name: String /** Path from root, i.e. `scala.Option$` */ @@ -103,6 +106,7 @@ trait Var extends Entity with Modifiers with ReturnValue { trait NonEntity extends Entity { val name = "" + val symbol = NoSymbol val comment = None val path = Nil val kind = "" diff --git a/dottydoc/src/dotty/tools/dottydoc/model/internal.scala b/dottydoc/src/dotty/tools/dottydoc/model/internal.scala index 6afb1ec9b..09f642d0b 100644 --- a/dottydoc/src/dotty/tools/dottydoc/model/internal.scala +++ b/dottydoc/src/dotty/tools/dottydoc/model/internal.scala @@ -3,6 +3,7 @@ package model import comment.Comment import references._ +import dotty.tools.dotc.core.Symbols.Symbol object internal { @@ -11,6 +12,7 @@ object internal { } final case class PackageImpl( + symbol: Symbol, name: String, var members: List[Entity], path: List[String], @@ -21,6 +23,7 @@ object internal { } final case class ClassImpl( + symbol: Symbol, name: String, members: List[Entity], modifiers: List[String], @@ -32,6 +35,7 @@ object internal { ) extends Class with Impl final case class CaseClassImpl( + symbol: Symbol, name: String, members: List[Entity], modifiers: List[String], @@ -43,6 +47,7 @@ object internal { ) extends CaseClass with Impl final case class TraitImpl( + symbol: Symbol, name: String, members: List[Entity], modifiers: List[String], @@ -54,6 +59,7 @@ object internal { ) extends Trait with Impl final case class ObjectImpl( + symbol: Symbol, name: String, members: List[Entity], modifiers: List[String], @@ -63,6 +69,7 @@ object internal { ) extends Object with Impl final case class DefImpl( + symbol: Symbol, name: String, modifiers: List[String], path: List[String], @@ -74,6 +81,7 @@ object internal { ) extends Def with Impl final case class ValImpl( + symbol: Symbol, name: String, modifiers: List[String], path: List[String], diff --git a/dottydoc/test/ConstructorTest.scala b/dottydoc/test/ConstructorTest.scala index 8aa883022..44a05acad 100644 --- a/dottydoc/test/ConstructorTest.scala +++ b/dottydoc/test/ConstructorTest.scala @@ -22,7 +22,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(cls: Class), _, _) => + case PackageImpl(_, _, List(cls: Class), _, _) => cls.constructors.headOption match { case Some(ParamListImpl(NamedReference("str", _, false, false) :: Nil, false) :: Nil) => // success! @@ -44,7 +44,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(cls: Class), _, _) => + case PackageImpl(_, _, List(cls: Class), _, _) => cls.constructors match { case ( ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) :: @@ -69,7 +69,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(cls: Class), _, _) => + case PackageImpl(_, _, List(cls: Class), _, _) => cls.constructors match { case ( ParamListImpl(NamedReference("str1", _, false, false) :: Nil, false) :: @@ -101,7 +101,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(cls: Class), _, _) => + case PackageImpl(_, _, List(cls: Class), _, _) => cls.constructors match { case ( ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil @@ -139,7 +139,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(cls: CaseClass, obj: Object), _, _) => + case PackageImpl(_, _, List(cls: CaseClass, obj: Object), _, _) => cls.constructors match { case ( ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil @@ -172,7 +172,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(trt: Trait), _, _) => + case PackageImpl(_, _, List(trt: Trait), _, _) => trt.traitParams match { case ParamListImpl(NamedReference("main", _, false, false) :: Nil, false) :: Nil => case _ => @@ -199,7 +199,7 @@ class Constructors extends DottyTest { checkSources(source :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(cc: CaseClass, _, cls: Class, trt: Trait), _, _) => + case PackageImpl(_, _, List(cc: CaseClass, _, cls: Class, trt: Trait), _, _) => import model.json._ lazy val incorrectJson = s"The json generated for:\n$actualSource\n\nIs not correct" assert(cc.json.contains(s""""constructors":[[{"list":[{"title":"main""""), incorrectJson) diff --git a/dottydoc/test/PackageStructure.scala b/dottydoc/test/PackageStructure.scala index 00caaa2c0..4e7006bfe 100644 --- a/dottydoc/test/PackageStructure.scala +++ b/dottydoc/test/PackageStructure.scala @@ -29,7 +29,7 @@ class PackageStructure extends DottyTest { checkSources(source1 :: source2 :: Nil) { packages => packages("scala") match { - case PackageImpl(_, List(tA, tB), _, _) => + case PackageImpl(_, _, List(tA, tB), _, _) => assert( tA.name == "A" && tB.name == "B", s"trait A had name '${tA.name}' and trait B had name '${tB.name}'" @@ -62,8 +62,9 @@ class PackageStructure extends DottyTest { checkSources(source1 :: source2 :: Nil) { packages => packages("scala") match { case PackageImpl( + _, "scala", - List(PackageImpl("scala.collection", List(tA, tB), _, _)), + List(PackageImpl(_, "scala.collection", List(tA, tB), _, _)), _, _ ) => assert( @@ -76,7 +77,7 @@ class PackageStructure extends DottyTest { } packages("scala.collection") match { - case PackageImpl("scala.collection", List(tA, tB), _, _) => + case PackageImpl(_, "scala.collection", List(tA, tB), _, _) => assert( tA.name == "A" && tB.name == "B", s"trait A had name '${tA.name}' and trait B had name '${tB.name}'" |