This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Inheritance Graph Generation Script

4 replies
Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.

Hi,

I have committed a horrible hack against nature. This hack munges
ScalaDoc HTML to produce GraphViz ".dot" files that represent the
inheritance of specified classes (including traits and object classes).
This unforgivable hack is horrendously inefficient, taking, e.g., 6 CPU
seconds on a 2.6 GHz Core2 Duo to process all 52 classes residing
immediately within scala.collection.jcl (and all base classes and
traits that are transitively reachable via all the types listed in the
first "extends" clause in the ScalaDoc HTML file for the classes in
question). Naturally, all such graphs have Any as their root.

Should anyone have an interest in this abomination, I've attached a few
files, one holding the list of starting classes, the resulting .dot file
and the .png image rendered from it using this invocation of the "dot"
command:

dot \
-Tpng \
-Grankdir=BT \
-Nfontname=LucidaSans \
-Nfontsize=8 \
-o"collections-basic.png" \
"collections-basic.dot"

I did not include the image for collections-jcl, because it's about 150
KB before base64 encoding. I did include the class list and resulting
".dot" file for the top-level jcl classes.

I know the proper way to do such things is with a compiler plug-in (or
just about anything other than mangling ScalaDoc HTML!), but I don't
feel up to that just yet. This at least lets me visualize elementary
subtyping relationships for which I could not find pictures elsewhere.

Naturally, if there's interest, I'm willing to share the BASH script, as
long as everyone promises not to laugh at me to my face (or do
whatever is the email or IRC equivalent).

Randall Schulz

Narayanaswamy, Mohan
Joined: 2009-04-20,
User offline. Last seen 42 years 45 weeks ago.
RE: Inheritance Graph Generation Script

Have you manually created those dot file?

I am new to scala, still interested in your BASH script to produce such
a image's.

Mohan

-----Original Message-----
From: Randall R Schulz [mailto:rschulz@sonic.net]
Sent: 18 April 2009 09:02
To: scala-tools@listes.epfl.ch
Subject: [scala-tools] Inheritance Graph Generation Script

Hi,

I have committed a horrible hack against nature. This hack munges
ScalaDoc HTML to produce GraphViz ".dot" files that represent the
inheritance of specified classes (including traits and object classes).
This unforgivable hack is horrendously inefficient, taking, e.g., 6 CPU
seconds on a 2.6 GHz Core2 Duo to process all 52 classes residing
immediately within scala.collection.jcl (and all base classes and traits
that are transitively reachable via all the types listed in the first
"extends" clause in the ScalaDoc HTML file for the classes in question).
Naturally, all such graphs have Any as their root.

Should anyone have an interest in this abomination, I've attached a few
files, one holding the list of starting classes, the resulting .dot file
and the .png image rendered from it using this invocation of the "dot"
command:

dot \
-Tpng \
-Grankdir=BT \
-Nfontname=LucidaSans \
-Nfontsize=8 \
-o"collections-basic.png" \
"collections-basic.dot"

I did not include the image for collections-jcl, because it's about 150
KB before base64 encoding. I did include the class list and resulting
".dot" file for the top-level jcl classes.

I know the proper way to do such things is with a compiler plug-in (or
just about anything other than mangling ScalaDoc HTML!), but I don't
feel up to that just yet. This at least lets me visualize elementary
subtyping relationships for which I could not find pictures elsewhere.

Naturally, if there's interest, I'm willing to share the BASH script, as

long as everyone promises not to laugh at me to my face (or do
whatever is the email or IRC equivalent).

Randall Schulz

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Inheritance Graph Generation Script

On Sunday April 19 2009, Narayanaswamy, Mohan wrote:
> Have you manually created those dot file?

No, the script produces the .dot file by munging ScalaDoc HTML. It's
deplorable, really, but there's a predictable format and all the basic
information is contained on the line that reads "extends ...".

> I am new to scala, still interested in your BASH script to produce
> such a image's.

I discovered a significant flaw that I must fix, first. Keep in mind you
need the GraphViz software installed to turn the .dot files into
images.

> Mohan

Randall Schulz

Derek Chen-Becker
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Inheritance Graph Generation Script

Randall R Schulz wrote:
> Hi,
>
> I have committed a horrible hack against nature. This hack munges
> ScalaDoc HTML to produce GraphViz ".dot" files that represent the
> inheritance of specified classes (including traits and object classes).
> This unforgivable hack is horrendously inefficient, taking, e.g., 6 CPU

Randall, you're a (mad) genius. One of the things that I like about
doxygen output is the class inheritance and composition graphs. It seems
like it would be really helpful with Scala allowing for multiple traits.

Derek

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Inheritance Graph Generation Script

On Monday April 20 2009, Derek Chen-Becker wrote:
> Randall R Schulz wrote:
> > Hi,
> >
> > I have committed a horrible hack against nature. This hack munges
> > ScalaDoc HTML to produce GraphViz ".dot" files that represent the
> > inheritance of specified classes (including traits and object
> > classes). This unforgivable hack is horrendously inefficient,
> > taking, e.g., 6 CPU
>
> Randall, you're a (mad) genius. One of the things that I like about
> doxygen output is the class inheritance and composition graphs. It
> seems like it would be really helpful with Scala allowing for
> multiple traits.

Well, mad, anyway.

Yes, Doxygen's pictures are nice. I seem to recall hearing recently that
Doxygen is not very extensible or modular w.r.t. new languages and is
probably not a good starting point for a next-generation Scala
documentation extractor. If that's true (and probably even if it's
not), a Scala compiler plug-in seems the obvious way to get at the
information required to generate good diagrammatic representations of
Scala code.

As I was mentioning to someone else, it would also be good to depict the
linearization sequence for multiply inherited traits. And many other
refinements would be necessary for a proper tool, of course.

But I didn't even have a proper image of the most basic inheritance
relationships in the collection library. So with zero as the reference
point, this hack is better than nothing.

> Derek

Randall Schulz

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland