aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/src/dotty/tools/dottydoc/model
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:28:39 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-21 15:51:57 +0200
commit0b69be68d3100103ebfd636bbc36f9cdcbd6fb28 (patch)
tree2b7a1db4beda3963cdddfd4ce86d9d8d9108f5a0 /dottydoc/src/dotty/tools/dottydoc/model
parentd8c02ec2f8ef225fde2be5324bbf46958132d865 (diff)
downloaddotty-0b69be68d3100103ebfd636bbc36f9cdcbd6fb28.tar.gz
dotty-0b69be68d3100103ebfd636bbc36f9cdcbd6fb28.tar.bz2
dotty-0b69be68d3100103ebfd636bbc36f9cdcbd6fb28.zip
Add phase to deal with constructors
Diffstat (limited to 'dottydoc/src/dotty/tools/dottydoc/model')
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/model/entities.scala9
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/model/factories.scala21
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/model/internal.scala3
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/model/json.scala8
4 files changed, 28 insertions, 13 deletions
diff --git a/dottydoc/src/dotty/tools/dottydoc/model/entities.scala b/dottydoc/src/dotty/tools/dottydoc/model/entities.scala
index 4d3a33b33..76792070c 100644
--- a/dottydoc/src/dotty/tools/dottydoc/model/entities.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/model/entities.scala
@@ -57,6 +57,10 @@ trait ParamList {
def isImplicit: Boolean
}
+trait Constructors {
+ def constructors: List[List[ParamList]]
+}
+
trait ImplicitlyAddedEntity extends Entity {
def implicitlyAddedFrom: Option[Reference]
}
@@ -67,15 +71,16 @@ trait Package extends Entity with Members {
def children: List[Entity with Members]
}
-trait Class extends Entity with Modifiers with TypeParams with SuperTypes with Members {
+trait Class extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members {
val kind = "class"
}
-trait CaseClass extends Entity with Modifiers with TypeParams with SuperTypes with Members {
+trait CaseClass extends Entity with Modifiers with TypeParams with Constructors with SuperTypes with Members {
override val kind = "case class"
}
trait Trait extends Entity with Modifiers with TypeParams with SuperTypes with Members {
+ def traitParams: List[ParamList]
override val kind = "trait"
}
diff --git a/dottydoc/src/dotty/tools/dottydoc/model/factories.scala b/dottydoc/src/dotty/tools/dottydoc/model/factories.scala
index b5cf15148..b19b836ee 100644
--- a/dottydoc/src/dotty/tools/dottydoc/model/factories.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/model/factories.scala
@@ -6,19 +6,17 @@ import references._
import dotty.tools.dotc
import dotc.core.Types._
import dotc.core.TypeApplications._
-import dotc.core.Flags
import dotc.core.Contexts.Context
-import dotc.core.Symbols.Symbol
+import dotc.core.Symbols.{ Symbol, ClassSymbol }
import dotty.tools.dotc.core.SymDenotations._
import dotty.tools.dotc.core.Names.TypeName
-import dotc.core.{ Flags => DottyFlags }
import dotc.ast.Trees._
object factories {
import dotty.tools.dotc.ast.tpd._
import dotty.tools.dottydoc.model.internal.ParamListImpl
- import DottyFlags._
+ import dotc.core.Flags._
type TypeTree = dotty.tools.dotc.ast.Trees.Tree[Type]
@@ -118,11 +116,11 @@ object factories {
pt.paramNames.map(_.show.split("\\$").last)
case ClassInfo(_, _, _, decls, _) =>
decls.iterator
- .filter(_.flags is Flags.TypeParam)
+ .filter(_.flags is TypeParam)
.map { tp =>
val prefix =
- if (tp.flags is Flags.Covariant) "+"
- else if (tp.flags is Flags.Contravariant) "-"
+ if (tp.flags is Covariant) "+"
+ else if (tp.flags is Contravariant) "-"
else ""
prefix + tp.name.show.split("\\$").last
}
@@ -131,6 +129,15 @@ object factories {
Nil
}
+ def constructors(sym: Symbol)(implicit ctx: Context): List[List[ParamList]] = sym match {
+ case sym: ClassSymbol =>
+ paramLists(sym.primaryConstructor.info) :: Nil
+ case _ => Nil
+ }
+
+ def traitParameters(sym: Symbol)(implicit ctx: Context): List[ParamList] =
+ constructors(sym).head
+
def paramLists(tpe: Type)(implicit ctx: Context): List[ParamList] = tpe match {
case pt: PolyType =>
paramLists(pt.resultType)
diff --git a/dottydoc/src/dotty/tools/dottydoc/model/internal.scala b/dottydoc/src/dotty/tools/dottydoc/model/internal.scala
index 63e97743d..6afb1ec9b 100644
--- a/dottydoc/src/dotty/tools/dottydoc/model/internal.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/model/internal.scala
@@ -26,6 +26,7 @@ object internal {
modifiers: List[String],
path: List[String],
typeParams: List[String] = Nil,
+ constructors: List[List[ParamList]] = Nil,
superTypes: List[MaterializableLink] = Nil,
var comment: Option[Comment] = None
) extends Class with Impl
@@ -36,6 +37,7 @@ object internal {
modifiers: List[String],
path: List[String],
typeParams: List[String] = Nil,
+ constructors: List[List[ParamList]] = Nil,
superTypes: List[MaterializableLink] = Nil,
var comment: Option[Comment] = None
) extends CaseClass with Impl
@@ -46,6 +48,7 @@ object internal {
modifiers: List[String],
path: List[String],
typeParams: List[String] = Nil,
+ traitParams: List[ParamList] = Nil,
superTypes: List[MaterializableLink] = Nil,
var comment: Option[Comment] = None
) extends Trait with Impl
diff --git a/dottydoc/src/dotty/tools/dottydoc/model/json.scala b/dottydoc/src/dotty/tools/dottydoc/model/json.scala
index 9bf37295c..145728f8a 100644
--- a/dottydoc/src/dotty/tools/dottydoc/model/json.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/model/json.scala
@@ -34,7 +34,7 @@ object json {
def json: String = {
val (secondTitle, secondValue, kind) = link match {
case ul: UnsetLink => ("query".json, ul.query.json, "UnsetLink".json)
- case ml: MaterializedLink => ("target", ml.target.json, "MaterializedLink".json)
+ case ml: MaterializedLink => ("target".json, ml.target.json, "MaterializedLink".json)
case nl: NoLink => ("target".json, nl.target.json, "NoLink".json)
}
s"""{"title":${link.title.json},$secondTitle:${secondValue},"kind":$kind}"""
@@ -70,11 +70,11 @@ object json {
case ent: Package =>
s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"package"}"""
case ent: Class =>
- s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"class"}"""
+ s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"constructors":${ent.constructors.map(xs => xs.map(_.json).mkString("[",",","]")).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"class"}"""
case ent: CaseClass =>
- s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"case class"}"""
+ s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"constructors":${ent.constructors.map(xs => xs.map(_.json).mkString("[",",","]")).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"case class"}"""
case ent: Trait =>
- s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"trait"}"""
+ s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"traitParams":${ent.traitParams.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"trait"}"""
case ent: Object =>
s"""{"name":${ent.name.json},"members":${ent.members.map(_.json).mkString("[",",","]")},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"superTypes":${ent.superTypes.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"object"}"""
case ent: Def =>