diff options
Diffstat (limited to 'dottydoc/jvm/src/dotty/tools')
8 files changed, 49 insertions, 30 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala index b5cdcf645..120b743b8 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala @@ -31,6 +31,7 @@ class DottyDocCompiler extends Compiler { List(new DocASTPhase), List(DocMiniTransformations(new LinkReturnTypes, new LinkParamListTypes, + new LinkImplicitlyAddedTypes, new SortMembers)), List(new PrintPhase) ) diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocASTPhase.scala index 40e778059..d9fb3bacc 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocASTPhase.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/DocASTPhase.scala @@ -55,15 +55,30 @@ class DocASTPhase extends Phase { } def membersFromSymbol(sym: Symbol): List[Entity] = { - val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private).map { meth => - track(meth.symbol, ctx, tree.symbol) { - DefImpl(meth.symbol.name.decode.toString, Nil, path(meth.symbol), returnType(meth.info), typeParams(meth.symbol), paramLists(meth.info)) - } - }.toList + val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private) + .filterNot(_.symbol.owner.name.show == "Any") + .map { meth => + track(meth.symbol, ctx, tree.symbol) { + DefImpl( + meth.symbol.name.show, + Nil, + path(meth.symbol), + returnType(meth.info), + typeParams(meth.symbol), + paramLists(meth.info), + implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info)) + ) + } + }.toList val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value => track(value.symbol, ctx, tree.symbol) { - ValImpl(value.symbol.name.decode.toString, Nil, path(value.symbol), returnType(value.info)) + ValImpl( + value.symbol.name.show, + Nil, path(value.symbol), + returnType(value.info), + implicitlyAddedFrom = Some(returnType(value.symbol.owner.info)) + ) } } diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala index 1da03583e..cd1fef52f 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala @@ -134,7 +134,8 @@ object transform { df.returnValue, df.typeParams, df.paramLists, - df.comment + df.comment, + df.implicitlyAddedFrom ) } case vl: Val => transformEntity(vl, _.valTransformation) { vl => @@ -143,7 +144,8 @@ object transform { vl.modifiers, vl.path, vl.returnValue, - vl.comment + vl.comment, + vl.implicitlyAddedFrom ) } } diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/TypeLinkingPhases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/TypeLinkingPhases.scala index e8c8790d9..7ce6b187b 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/TypeLinkingPhases.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/TypeLinkingPhases.scala @@ -37,6 +37,18 @@ class LinkParamListTypes extends DocMiniPhase with TypeLinker { } } +class LinkImplicitlyAddedTypes extends DocMiniPhase with TypeLinker { + override def transformDef(implicit ctx: Context) = { case df: DefImpl if df.implicitlyAddedFrom.isDefined => + val implicitlyAddedFrom = linkReference(df, df.implicitlyAddedFrom.get, ctx.docbase.packages[Package].toMap) + df.copy(implicitlyAddedFrom = Some(implicitlyAddedFrom)) + } + + override def transformVal(implicit ctx: Context) = { case vl: ValImpl if vl.implicitlyAddedFrom.isDefined => + val implicitlyAddedFrom = linkReference(vl, vl.implicitlyAddedFrom.get, ctx.docbase.packages[Package].toMap) + vl.copy(implicitlyAddedFrom = Some(implicitlyAddedFrom)) + } +} + trait TypeLinker extends MemberLookup { def linkReference(ent: Entity, ref: Reference, packs: Map[String, Package]): Reference = { def linkRef(ref: Reference) = linkReference(ent, ref, packs) diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/entities.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/entities.scala index 391bd514f..16d05306e 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/entities.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/entities.scala @@ -79,12 +79,14 @@ trait Object extends Entity with Modifiers with SuperTypes with Members { } trait Def extends Entity with Modifiers with TypeParams with ReturnValue { - def paramLists: List[ParamList] val kind = "def" + def paramLists: List[ParamList] + def implicitlyAddedFrom: Option[Reference] } trait Val extends Entity with Modifiers with ReturnValue { val kind = "val" + def implicitlyAddedFrom: Option[Reference] } trait Var extends Entity with Modifiers with ReturnValue { diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/factories.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/factories.scala index f0c78fa41..4d80c08a9 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/factories.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/factories.scala @@ -29,26 +29,11 @@ object factories { def path(sym: Symbol)(implicit ctx: Context): List[String] = sym match { case sym if sym.name.decode.toString == "<root>" => Nil - case sym if sym is Flags.Module => path(sym.owner) :+ sym.name.decode.toString.dropRight(1) - case sym => path(sym.owner) :+ sym.name.decode.toString + case sym => path(sym.owner) :+ sym.name.show } private val product = """Product[1-9][0-9]*""".r - private def cleanTitle(title: String): String = title match { - // matches Entity.this.Something - case x if x matches "[^\\[]+\\.this\\..+" => x.split("\\.").last - // Matches Entity[P, ...] - case x if x matches "[^\\[]+\\[[^\\]]+\\]" => - val Array(tpe, params) = x.dropRight(1).split("\\[") - s"""$tpe[${params.split(",").map(x => cleanTitle(x.trim)).mkString(", ")}]""" - case _ => title - } - - private def cleanQuery(query: String): String = query match { - case x if x matches "[^\\[]+\\[[^\\]]+\\]" => x.takeWhile(_ != '[') - case _ => query - } def returnType(t: Type)(implicit ctx: Context): Reference = { val defn = ctx.definitions @@ -107,7 +92,7 @@ object factories { case tt: ThisType => expandTpe(tt.underlying) case ci: ClassInfo => - typeRef(ci.cls.show) + typeRef(ci.cls.name.show) case mt: MethodType => expandTpe(mt.resultType) case pt: PolyType => diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/internal.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/internal.scala index ec1adfa88..a8756c82a 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/internal.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/internal.scala @@ -65,7 +65,8 @@ object internal { var returnValue: Reference, var typeParams: List[String] = Nil, var paramLists: List[ParamList] = Nil, - var comment: Option[Comment] = None + var comment: Option[Comment] = None, + implicitlyAddedFrom: Option[Reference] = None ) extends Def with Impl final case class ValImpl( @@ -73,7 +74,8 @@ object internal { modifiers: List[String], path: List[String], var returnValue: Reference, - var comment: Option[Comment] = None + var comment: Option[Comment] = None, + implicitlyAddedFrom: Option[Reference] = None ) extends Val with Impl final case class ParamListImpl( diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala index ea9658b5d..f83f43138 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/model/json.scala @@ -76,9 +76,9 @@ object json { 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 => - s"""{"name":${ent.name.json},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"returnValue":${ent.returnValue.json},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"paramLists":${ent.paramLists.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"def"}""" + s"""{"name":${ent.name.json},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"returnValue":${ent.returnValue.json},"typeParams":${ent.typeParams.map(_.json).mkString("[",",","]")},"paramLists":${ent.paramLists.map(_.json).mkString("[",",","]")},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}${ent.implicitlyAddedFrom.fold("")(ref => s""""implicitlyAddedFrom":${ref.json},""")}"kind":"def"}""" case ent: Val => - s"""{"name":${ent.name.json},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"returnValue":${ent.returnValue.json},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}"kind":"val"}""" + s"""{"name":${ent.name.json},"modifiers":${ent.modifiers.map(_.json).mkString("[",",","]")},"path":${ent.path.map(_.json).mkString("[",",","]")},"returnValue":${ent.returnValue.json},${ent.comment.map(_.json).fold("")(cmt => s""""comment":$cmt,""")}${ent.implicitlyAddedFrom.fold("")(ref => s""""implicitlyAddedFrom":${ref.json},""")}"kind":"val"}""" } implicit class EntityJson(val ent: Entity) extends AnyVal { def json: String = entToJson(ent) } implicit class PackageJson(val pack: Package) extends AnyVal { def json: String = (pack: Entity).json } |