aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-06-13 17:34:14 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:26 +0200
commit76bbb8de91990e5bf2344fbf2f06918c860c4c0e (patch)
tree14c0b778e34955db7ef333f86fd18c9e26b02d89 /dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala
parent8294dd082088effda892db3e7c63379596e66a29 (diff)
downloaddotty-76bbb8de91990e5bf2344fbf2f06918c860c4c0e.tar.gz
dotty-76bbb8de91990e5bf2344fbf2f06918c860c4c0e.tar.bz2
dotty-76bbb8de91990e5bf2344fbf2f06918c860c4c0e.zip
Add supertypes to class, cc, obj and trait
Diffstat (limited to 'dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala')
-rw-r--r--dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/factories.scala50
1 files changed, 39 insertions, 11 deletions
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))