Skip to content

Support -from-tasty in Dottydoc #4789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix #4752: Support multiple @usecase sections
In the documentation, it is possible to have several `@usecase`
sections, which means that each of these section should be displayed as
a separate member in the documentation. So far, Dottydoc was only
considering the first `@usecase` section and was disregarding the
others.

This commit fixes that, and generates a new member for each of the
usecases.

Fixes #4752
  • Loading branch information
Duhemm committed Sep 4, 2018
commit 10de931ab2bc43db8b2c5185bdc11d493f83e708
12 changes: 7 additions & 5 deletions doc-tool/src/dotty/tools/dottydoc/core/UsecasePhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class UsecasePhase extends DocMiniPhase {
}

override def transformDef(implicit ctx: Context) = { case df: DefImpl =>
ctx.docbase
.docstring(df.symbol)
.flatMap(_.usecases.headOption.map(_.tpdCode))
.map(defdefToDef(_, df.symbol))
.getOrElse(df) :: Nil
val defdefs =
ctx.docbase.docstring(df.symbol)
.map(_.usecases.map(_.tpdCode))
.getOrElse(Nil)

if (defdefs.isEmpty) df :: Nil
else defdefs.map(defdefToDef(_, df.symbol))
}
}
28 changes: 28 additions & 0 deletions doc-tool/test/UsecaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,34 @@ abstract class UsecaseBase extends DottyDocTest {
}
}

@Test def multipleUseCases: Unit = {
val source = new SourceFile(
name = "MultipleUseCases.scala",
"""
|package scala
|
|trait Test {
| /** A first method
| * @usecase def foo(x: Int): Int
| * @usecase def foo(x: Double): Double
| */
| def foo(x: String): Unit
|}
""".stripMargin
)

val className = "scala.Test"

check(className :: Nil, source :: Nil) { (ctx, packages) =>
packages("scala") match {
case PackageImpl(_, _, _, List(trt: Trait), _, _, _, _) =>
val List(foo0: Def, foo1: Def) = trt.members
assertEquals(TypeReference("Int", NoLink("Int", "scala.Int"), Nil), foo0.returnValue)
assertEquals(TypeReference("Double", NoLink("Double", "scala.Double"), Nil), foo1.returnValue)
}
}
}

@Test def checkIterator =
checkFiles("../scala2-library/src/library/scala/collection/Iterator.scala" :: Nil) { case _ =>
// success if typer throws no errors! :)
Expand Down