scala - 如何使用 Scaladoc 生成类型层次结构图?

标签 scala scaladoc

我希望 Scaladoc 为以下代码片段生成类型层次结构图:

trait A
trait B extends A

但是当我执行 scaladoc <file>.scala没有显示类型层次结构——也没有在 A 中也不在 B .我怎样才能生成这样的图表?

最佳答案

首先,为此需要 Scaladoc2,它是 Scala 2.10 的一部分。

如果安装了2.10,还需要通过-diagrams Scaladoc 选项以生成图表。但如果这样做,可能会出现以下错误消息:

Graphviz dot encountered an error when generating the diagram for:
_root_
These are usually spurious errors, but if you notice a persistant error on
a diagram, please use the -diagrams-debug flag and report a bug with the output.
Graphviz will be restarted...

发生错误的原因是 Scaladoc 不会自行生成图表,而是尝试调用 Graphviz ,做这个工作。当我们添加 -diagrams-debug标记我们很好地得到了确切的错误消息:

The following is the log of the failure:
  Main thread in _root_: Exception: java.io.IOException: Cannot run program "dot": java.io.IOException: error=2, No such file or directory

要解决这个问题需要安装程序dot ,这是 Graphviz 的一部分。这样做之后应该可以执行 scaladoc -diagrams <file>.scala成功并在生成的文档中看到成员搜索栏上方的标签“类型层次结构”。

正在执行 scaladoc -help显示图表选项的更多信息:

  -diagrams                                   Create inheritance diagrams for classes, traits and packages.
  -diagrams-dot-path <path>                   The path to the dot executable used to generate the inheritance diagrams. Eg: /usr/bin/dot
  -diagrams-dot-restart <n>                   The number of times to restart a malfunctioning dot process before disabling diagrams (default: 5)
  -diagrams-dot-timeout <n>                   The timeout before the graphviz dot util is forcefully closed, in seconds (default: 10)
  -diagrams-max-classes <n>                   The maximum number of superclasses or subclasses to show in a diagram
  -diagrams-max-implicits <n>                 The maximum number of implicitly converted classes to show in a diagram

关于scala - 如何使用 Scaladoc 生成类型层次结构图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13435474/

相关文章:

scala - 如何避免在循环中分配的 var

java - 使用 Java API 对数据集中所有列进行数据操作

sbt - 我可以将 sbt 的 `apiMappings` 设置用于托管依赖项吗?

Scaladoc 无法为方法和类签名中的内部类生成链接

scala - 配置 scaladoc 以包含扩展方法

scala - 寻找 Scaladoc 帮助,reduceLeft

scala - scalacheck 中生成器的大小

Scala的带对象+的中缀表示法,为什么不可能呢?

scala - 为什么使用 Collection.empty[T] 而不是 new Collection[T]()

scala - 为根包生成 scaladoc