How do I inherit Scaladoc from Scala's standard library?

≯℡__Kan透↙ 提交于 2019-12-05 22:37:08

问题


If I understand correctly, the Scaladoc of a method should automatically inherit the Scaladoc of the parent method it overrides. This seems to hold true for a local set of classes, but not when extending from Scala's standard library (and presumably any external dependency?).

class LocalParent {
  /**
   * some documentation
   */
  def foo = ???
}

class DocumentedChild extends LocalParent

class UndocumentedChild extends Iterator[Int] {
   def hasNext = ???
   def next = ???
}

Is there a way to inherit the Scaladoc? Or am I doing something wrong?

Also, I'm using sbt doc, so not scaladoc directly.


回答1:


Here's what I use (SBT 0.13):

scalacOptions in (Compile, doc) ++=
  Seq("-diagrams",
      "-diagrams-max-classes",
      "20",
      "-external-urls:java=http://docs.oracle.com/javase/6/docs/api/," +
      "scala=http://www.scala-lang.org/api/current/")

Addendum 1:

To address the issue of subclassing standard library classes while overriding methods and wanting the overridden method's documentation comment, members can be commented with the inherit documentation tag:

/** @inheritdoc */
override def foo(bar: String): Int = bar.length

Addendum 2:

The more modern form of this functionality is documented on this SBT 0.13 documentation page.




回答2:


It's much easier nowadays. Simply add

autoAPIMappings := true

to your SBT settings. (build.sbt or project/Build.scala)

Tested with SBT version 0.13.5 and Scala 2.11.7, but it should work all the way back to 2.10.2, per the SBT documentation

That should work for any managed dependencies that specify where their documentation lives. If it's not working for some dependencies, see the other options.



来源:https://stackoverflow.com/questions/23765955/how-do-i-inherit-scaladoc-from-scalas-standard-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!