【问题标题】:How to generate type hierarchy diagrams with Scaladoc?如何使用 Scaladoc 生成类型层次图?
【发布时间】:2012-11-06 07:02:05
【问题描述】:

我希望 Scaladoc 为以下代码 sn-p 生成类型层次图:

trait A
trait B extends A

但是当我执行scaladoc <file>.scala 时,没有显示类型层次结构——AB 都没有。如何生成这样的图表?

【问题讨论】:

    标签: scala scaladoc


    【解决方案1】:

    首先,为此需要 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 并在生成的文档中看到成员搜索栏上方的标签“Type Hierarchy”。

    执行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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多