aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/src
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-01-16 20:29:25 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-31 14:32:37 +0100
commit9a581bc15aa300f665428c804611453609955f60 (patch)
tree122c3ae291a6d277e02a4545852a798deecf7181 /doc-tool/src
parent72720f0780e95b6b341f46679d20b56fcef8b85a (diff)
downloaddotty-9a581bc15aa300f665428c804611453609955f60.tar.gz
dotty-9a581bc15aa300f665428c804611453609955f60.tar.bz2
dotty-9a581bc15aa300f665428c804611453609955f60.zip
Improve member lookup
Diffstat (limited to 'doc-tool/src')
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/model/factories.scala111
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala7
-rw-r--r--doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala16
3 files changed, 75 insertions, 59 deletions
diff --git a/doc-tool/src/dotty/tools/dottydoc/model/factories.scala b/doc-tool/src/dotty/tools/dottydoc/model/factories.scala
index e47c683f3..8f1fad4a7 100644
--- a/doc-tool/src/dotty/tools/dottydoc/model/factories.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/model/factories.scala
@@ -46,77 +46,82 @@ object factories {
}
def expandTpe(t: Type, params: List[Reference] = Nil): Reference = t match {
- case tl: PolyType =>
- //FIXME: should be handled correctly
- // example, in `Option`:
- //
- // {{{
- // def companion: GenericCompanion[collection.Iterable]
- // }}}
- //
- // Becomes: def companion: [+X0] -> collection.Iterable[X0]
- typeRef(tl.show + " (not handled)")
- case AppliedType(tycon, args) =>
+ case AppliedType(tycon, args) => {
val cls = tycon.typeSymbol
- if (tycon.isRepeatedParam)
- expandTpe(args.head)
- else if (defn.isFunctionClass(cls))
+
+ if (defn.isFunctionClass(cls))
FunctionReference(args.init.map(expandTpe(_, Nil)), expandTpe(args.last))
else if (defn.isTupleClass(cls))
TupleReference(args.map(expandTpe(_, Nil)))
else {
- val query = tycon.show
- val name = query.split("\\.").last
+ val query = cls.showFullName
+ val name = cls.name.show
typeRef(name, query, params = args.map(expandTpe(_, Nil)))
}
+ }
- case ref @ RefinedType(parent, rn, info) =>
- expandTpe(parent) //FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar
- case ref @ HKApply(tycon, args) =>
- expandTpe(tycon, args.map(expandTpe(_, params)))
- case TypeRef(_, n) =>
- val name = n.decode.toString.split("\\$").last
- typeRef(name, params = params)
- case ta: TypeAlias =>
- expandTpe(ta.alias.widenDealias)
- case OrType(left, right) =>
- OrTypeReference(expandTpe(left), expandTpe(right))
- case AndType(left, right) =>
- AndTypeReference(expandTpe(left), expandTpe(right))
- case tb @ TypeBounds(lo, hi) =>
+ case t: TypeRef => {
+ val cls = t.typeSymbol
+ typeRef(cls.name.show.split("\\$\\$").last, query = cls.showFullName, params = params)
+ }
+
+ case TypeBounds(lo, hi) =>
BoundsReference(expandTpe(lo), expandTpe(hi))
- case AnnotatedType(tpe, _) =>
- expandTpe(tpe)
+
+ case t: PolyParam =>
+ typeRef(t.paramName.show, params = params)
+
case ExprType(tpe) =>
expandTpe(tpe)
- case c: ConstantType =>
- ConstantReference(c.show)
- case tt: ThisType =>
- expandTpe(tt.underlying)
- case ci: ClassInfo =>
- val query = path(ci.typeSymbol).mkString(".")
- typeRef(ci.cls.name.show, query = query)
- case mt: MethodType =>
- expandTpe(mt.resultType)
- case pp: PolyParam =>
- val paramName = pp.paramName.show
- val name =
- if (paramName.contains('$'))
- paramName.split("\\$\\$").last
- else paramName
-
- typeRef(name)
- case tr: TermRef =>
+
+ case t: ThisType =>
+ expandTpe(t.underlying)
+
+ case AnnotatedType(t, _) =>
+ expandTpe(t)
+
+ case t: MethodType =>
+ expandTpe(t.finalResultType)
+
+ case t: TermRef => {
/** A `TermRef` appears in the return type in e.g:
* ```
* def id[T](t: T): t.type = t
* ```
*/
- val name = tr.show
+ val name = t.show
if (!name.endsWith(".type"))
- ctx.warning(s"unhandled return type found: $tr")
+ ctx.warning(s"unhandled return type found: $t")
+
+ typeRef(name, query = t.typeSymbol.showFullName, params = params)
+ }
+
+ case ci: ClassInfo =>
+ typeRef(ci.cls.name.show, query = ci.typeSymbol.showFullName)
+
+ case tl: PolyType => {
+ // FIXME: should be handled correctly
+ // example, in `Option`:
+ //
+ // ```scala
+ // def companion: GenericCompanion[collection.Iterable]
+ // ```
+ //
+ // Becomes: def companion: [+X0] -> collection.Iterable[X0]
+ typeRef(tl.show + " (not handled)")
+ }
- typeRef(name, params = params)
+ case OrType(left, right) =>
+ OrTypeReference(expandTpe(left), expandTpe(right))
+
+ case AndType(left, right) =>
+ AndTypeReference(expandTpe(left), expandTpe(right))
+
+ case c: ConstantType =>
+ ConstantReference(c.show)
+
+ case ref @ RefinedType(parent, rn, info) =>
+ expandTpe(parent) //FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar
}
expandTpe(t)
diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala
index 72fd8c2a5..92fd95d09 100644
--- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala
@@ -135,7 +135,7 @@ case class Site(val root: JFile, val documentation: Map[String, Package]) extend
/** Generate HTML for the API documentation */
def generateApiDocs(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type =
createOutput(outDir) {
- def genDoc(e: model.Entity) = {
+ def genDoc(e: model.Entity): Unit = {
// Suffix is index.html for packages and therefore the additional depth
// is increased by 1
val (suffix, offset) =
@@ -150,11 +150,14 @@ case class Site(val root: JFile, val documentation: Map[String, Package]) extend
val source = new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8))
Files.copy(source, target, REPLACE_EXISTING)
+
+ // Generate docs for nested objects/classes:
+ e.children.foreach(genDoc)
}
documentation.values.foreach { pkg =>
genDoc(pkg)
- pkg.members.filterNot(_.kind == "package").map(genDoc)
+ pkg.members.filterNot(_.kind == "package").foreach(genDoc)
}
}
diff --git a/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala b/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala
index 52b18f70c..ad73ad008 100644
--- a/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala
+++ b/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala
@@ -7,7 +7,6 @@ import dotc.core.Contexts.Context
import dotc.core.Flags
import dotc.core.Names._
import dotc.core.Symbols._
-import dotc.core.Types._
import dotc.core.Names._
import dotc.util.Positions._
import model.internal._
@@ -31,7 +30,13 @@ trait MemberLookup {
.collect { case x if x.name == searchStr => x }
.sortBy(_.path.last)
.headOption
- .fold(notFound)(e => LinkToEntity(e))
+ .fold(notFound) {
+ case e: TypeAlias =>
+ // TODO: will explode once type aliases are fixed
+ if (e.alias.isDefined) ???
+ else notFound
+ case e => LinkToEntity(e)
+ }
/** Looks for an entity down in the structure, if the search list is Nil,
* the search stops
@@ -44,7 +49,10 @@ trait MemberLookup {
case x :: xs =>
ent
.members
- .collect { case e: Entity with Members if e.name == x => e }
+ .collect {
+ case e: Entity with Members if e.name == x => e
+ case e: Entity with Members if e.name == x.init && x.last == '$' => e
+ }
.headOption
.fold(notFound)(e => downwardLookup(e, xs))
}
@@ -54,7 +62,7 @@ trait MemberLookup {
*/
def globalLookup: LinkTo = {
def longestMatch(list: List[String]): List[String] =
- if (list == Nil) Nil
+ if (list eq Nil) Nil
else
packages
.get(list.mkString("."))