Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

scala - How to generate type hierarchy diagrams with Scaladoc?

I want that Scaladoc generates a type hierarchy diagram for the following code snippet:

trait A
trait B extends A

But when I execute scaladoc <file>.scala there is no type hierarchy shown - neither in A nor in B. How can I generate such diagrams?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, one needs Scaladoc2 for this, which is part of Scala 2.10.

If 2.10 is installed, one also needs to pass the -diagrams option to Scaladoc in order to generate the diagrams. But if you do so it can be that the following error message occurs:

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...

The error occurs because Scaladoc does not generate the diagrams by itself but tries to call Graphviz, to do this job. When we add the -diagrams-debug flag we well get among other things the exact error message:

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

To solve the problem one needs to install the program dot, which is part of Graphviz. After doing so one should be able to execute scaladoc -diagrams <file>.scala successfully and see as a result the tag "Type Hierarchy" above the member search bar in the generated documentation.

Executing scaladoc -help shows further information for the diagrams option:

  -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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...