diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-06-13 17:34:14 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-08-19 15:37:26 +0200 |
commit | 76bbb8de91990e5bf2344fbf2f06918c860c4c0e (patch) | |
tree | 14c0b778e34955db7ef333f86fd18c9e26b02d89 /dottydoc | |
parent | 8294dd082088effda892db3e7c63379596e66a29 (diff) | |
download | dotty-76bbb8de91990e5bf2344fbf2f06918c860c4c0e.tar.gz dotty-76bbb8de91990e5bf2344fbf2f06918c860c4c0e.tar.bz2 dotty-76bbb8de91990e5bf2344fbf2f06918c860c4c0e.zip |
Add supertypes to class, cc, obj and trait
Diffstat (limited to 'dottydoc')
6 files changed, 81 insertions, 26 deletions
diff --git a/dottydoc/js/src/html/EntityLayout.scala b/dottydoc/js/src/html/EntityLayout.scala index ddd7bd2ef..3e4777714 100644 --- a/dottydoc/js/src/html/EntityLayout.scala +++ b/dottydoc/js/src/html/EntityLayout.scala @@ -6,6 +6,7 @@ import scalatags.JsDom.all._ import org.scalajs.dom import org.scalajs.dom.html.{Anchor, Div} import dotty.tools.dottydoc.model._ +import dotty.tools.dottydoc.model.comment.{ UnsetLink, Text } case class EntityLayout(entity: Entity) extends MemberLayout { def html = div( @@ -35,15 +36,26 @@ case class EntityLayout(entity: Entity) extends MemberLayout { } val typeParams = entity match { - case t: TypeParams => + case t: TypeParams if t.typeParams.nonEmpty => Some(span(cls := "entity-type-params no-left-margin", t.typeParams.mkString("[", ", ", "]"))) case _ => None } + val superTypes = entity match { + case st: SuperTypes => Some(span( + cls := "entity-super-types", + st.superTypes.collect { + case unset: UnsetLink => unset.title.asInstanceOf[Text].text + }.mkString(" extends ", " with ", "") + )) + case _ => None + } + modifiers :: Some(span(cls := "entity-kind", entity.kind)) :: Some(span(cls := "entity-name", entity.name)) :: typeParams :: + superTypes :: Nil }.flatten diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala index 64c3319c1..d60700acc 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala @@ -62,18 +62,18 @@ object Phases { case t @ TypeDef(n, rhs) if t.symbol.is(Flags.Trait) => val name = filteredName(n.toString) val newPath = prev :+ name - TraitImpl(name, collectMembers(rhs), flags(t), newPath, typeParams(t)) + TraitImpl(name, collectMembers(rhs), flags(t), newPath, typeParams(t), 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 = filteredName(n.toString.dropRight(1)) - ObjectImpl(name, collectMembers(rhs, prev :+ name), flags(o), prev :+ (name + "$")) + ObjectImpl(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 = filteredName(n.toString) val newPath = prev :+ name - (name, collectMembers(rhs), flags(c), newPath, typeParams(c), None) match { + (name, collectMembers(rhs), flags(c), newPath, typeParams(c), superTypes(c), None) match { case x if c.symbol.is(Flags.CaseClass) => CaseClassImpl.tupled(x) case x => ClassImpl.tupled(x) } diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala index 714d0ef96..c355c50cf 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala @@ -56,12 +56,19 @@ object json extends DefaultJsonProtocol { case other => other } - implicit val valFormat: JsonFormat[ValImpl] = lazyFormat(jsonFormat(ValImpl, "name", "modifiers", "path", "returnValue", "comment")) - implicit val defFormat: JsonFormat[DefImpl] = lazyFormat(jsonFormat(DefImpl, "name", "modifiers", "path", "returnValue", "typeParams", "paramLists", "comment")) - implicit val objFormat: JsonFormat[ObjectImpl] = lazyFormat(jsonFormat(ObjectImpl, "name", "members", "modifiers", "path", "comment")) - implicit val traitormat: JsonFormat[TraitImpl] = lazyFormat(jsonFormat(TraitImpl, "name", "members", "modifiers", "path", "typeParams", "comment")) - implicit val cclassFormat: JsonFormat[CaseClassImpl] = lazyFormat(jsonFormat(CaseClassImpl, "name", "members", "modifiers", "path", "typeParams", "comment")) - implicit val classFormat: JsonFormat[ClassImpl] = lazyFormat(jsonFormat(ClassImpl, "name", "members", "modifiers", "path", "typeParams", "comment")) - implicit val packageFormat: JsonFormat[PackageImpl] = lazyFormat(jsonFormat(PackageImpl, "name", "members", "path", "comment")) + implicit val valFormat: JsonFormat[ValImpl] = + lazyFormat(jsonFormat(ValImpl, "name", "modifiers", "path", "returnValue", "comment")) + implicit val defFormat: JsonFormat[DefImpl] = + lazyFormat(jsonFormat(DefImpl, "name", "modifiers", "path", "returnValue", "typeParams", "paramLists", "comment")) + implicit val objFormat: JsonFormat[ObjectImpl] = + lazyFormat(jsonFormat(ObjectImpl, "name", "members", "modifiers", "path", "superTypes", "comment")) + implicit val traitormat: JsonFormat[TraitImpl] = + lazyFormat(jsonFormat(TraitImpl, "name", "members", "modifiers", "path", "typeParams", "superTypes", "comment")) + implicit val cclassFormat: JsonFormat[CaseClassImpl] = + lazyFormat(jsonFormat(CaseClassImpl, "name", "members", "modifiers", "path", "typeParams", "superTypes", "comment")) + implicit val classFormat: JsonFormat[ClassImpl] = + lazyFormat(jsonFormat(ClassImpl, "name", "members", "modifiers", "path", "typeParams", "superTypes", "comment")) + implicit val packageFormat: JsonFormat[PackageImpl] = + lazyFormat(jsonFormat(PackageImpl, "name", "members", "path", "comment")) } diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/entities.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/entities.scala index 183a7374b..482c3b755 100644 --- a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/entities.scala +++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/entities.scala @@ -28,6 +28,10 @@ trait Entity { } } +trait SuperTypes { + def superTypes: List[MaterializableLink] +} + trait Members { def members: List[Entity] } @@ -53,19 +57,19 @@ trait Package extends Entity with Members { def children: List[Entity with Members] } -trait Class extends Entity with Modifiers with TypeParams with Members { +trait Class extends Entity with Modifiers with TypeParams with SuperTypes with Members { val kind = "class" } -trait CaseClass extends Entity with Modifiers with TypeParams with Members { +trait CaseClass extends Entity with Modifiers with TypeParams with SuperTypes with Members { override val kind = "case class" } -trait Trait extends Entity with Modifiers with TypeParams with Members { +trait Trait extends Entity with Modifiers with TypeParams with SuperTypes with Members { override val kind = "trait" } -trait Object extends Entity with Modifiers with Members { +trait Object extends Entity with Modifiers with SuperTypes with Members { override val kind = "object" } diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala index 0fc66916c..ff4cc52fe 100644 --- a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala +++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala @@ -6,6 +6,8 @@ import dotty.tools.dotc import dotc.core.Types._ import dotc.core.Contexts.Context import dotc.core.Symbols.Symbol +import dotty.tools.dotc.core.SymDenotations._ +import dotty.tools.dotc.core.Names.TypeName import dotc.core.{ Flags => DottyFlags } import dotc.ast.Trees._ @@ -22,18 +24,18 @@ object factories { .filter(_ != "<trait>") .filter(_ != "interface") - def path(t: Tree)(implicit ctx: Context): List[String] = { - def pathList(tpe: Type): List[String] = tpe match { - case t: ThisType => - pathList(t.tref) - case t: NamedType if t.prefix == NoPrefix && t.name.toString == "<root>" => - Nil - case t: NamedType if t.prefix == NoPrefix => - t.name.toString :: Nil - case t: NamedType => - pathList(t.prefix) :+ t.name.toString - } + private def pathList(tpe: Type): List[String] = tpe match { + case t: ThisType => + pathList(t.tref) + case t: NamedType if t.prefix == NoPrefix && t.name.toString == "<root>" => + Nil + case t: NamedType if t.prefix == NoPrefix => + t.name.toString :: Nil + case t: NamedType => + pathList(t.prefix) :+ t.name.toString + } + def path(t: Tree)(implicit ctx: Context): List[String] = { val ref = if (t.symbol.isTerm) t.symbol.termRef else t.symbol.typeRef @@ -70,6 +72,32 @@ object factories { typeParams(t.rhs.asInstanceOf[Template].constr) } + val product = """Product[1-9][0-9]*""".r + + def superTypes(t: Tree)(implicit ctx: Context): List[MaterializableLink] = t.symbol.denot match { + case cd: ClassDenotation => + def isJavaLangObject(prefix: Type): Boolean = + prefix match { + case TypeRef(ThisType(TypeRef(NoPrefix, outerName)), innerName) => + outerName.toString == "lang" && innerName.toString == "Object" + case _ => false + } + + def isProductWithArity(prefix: Type): Boolean = prefix match { + case TypeRef(TermRef(TermRef(NoPrefix, root), scala), prod) => + root.toString == "_root_" && + scala.toString == "scala" && + product.findFirstIn(prod.toString).isDefined + case _ => false + } + + cd.classParents.collect { + case t: TypeRef if !isJavaLangObject(t) && !isProductWithArity(t) => + UnsetLink(Text(t.name.toString), pathList(t).mkString(".")) + } + case _ => Nil + } + def paramLists(t: DefDef)(implicit ctx: Context): List[List[(String, MaterializableLink)]] = { def getParams(xs: List[ValDef]): List[(String, MaterializableLink)] = xs map { vd => (vd.name.toString, UnsetLink(Text(vd.tpt.show), vd.tpt.show)) diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/internal.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/internal.scala index f66439c86..78fbcec7e 100644 --- a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/internal.scala +++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/internal.scala @@ -25,6 +25,7 @@ object internal { modifiers: List[String], path: List[String], var typeParams: List[String] = Nil, + var superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends Class with Impl @@ -34,6 +35,7 @@ object internal { modifiers: List[String], path: List[String], var typeParams: List[String] = Nil, + var superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends CaseClass with Impl @@ -43,6 +45,7 @@ object internal { modifiers: List[String], path: List[String], var typeParams: List[String] = Nil, + var superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends Trait with Impl @@ -51,6 +54,7 @@ object internal { members: List[Entity], modifiers: List[String], path: List[String], + var superTypes: List[MaterializableLink] = Nil, var comment: Option[Comment] = None ) extends Object with Impl |