Class Diagram Example: Built-in Support for Views
Views are special classes that allow the generation of a custom class
diagram based on a set of diagram global options and a set of option
overrides for classes matching user specified conditions.
The @view
tag, marks a class used to describe a single class diagram.
The general syntax for defining a view is:
/**
* @view
* @opt viewOption1
* @opt viewOption2
* ...
* @match matchtype regularExpression
* @opt option1.1 [argument]
* @opt option1.2 [argument]
* ...
* @match matchtype regularExpression
* @opt option2.1 [argument]
* @opt option2.2 [argument]
* ...
*/
The @match tags allow to specify option overrides for classes that satisfy
the match condition. The match types are:
- class: matches class names using a regular expression.
- subclass: first looks for the base classes using the specified
regular expression, then matches the whole inheritance hierarchy of these
classes. The base classes are included in the match as well.
- interface: first looks for interfaces using the specified
regular expression, then matches every class that implements them,
either directly or indirectly. The interfaces are included in the match
as well.
- context: looks for classes using a regular expression,
then matches every class that's directly connected to them.
The class match type is intended to be used with a regular
expression, the others are usually performed against a class/interface
name rather than a real regular expression, but the syntax allows for
a regular expression to retain some flexibility (for example, a regular
expression can be used to match multiple classes, as in "(A|B|C)").
Refer to the Pattern
API docs for details on regular expression specifications.
Matches will be evaluted in the order of specification, each applying
its overrides to the current options. This means that options for a
specific class are built in the following order, where each item overrides
only the options specified locally, leaving the other options intact:
- Command line options
- UMLOptions options
- View options
- Match overrides, in the order they are specified, and only for
the classes that satisfy the match conditions
Each view will generate a .dot file whose name is the name of the view,
unless the "output" option is specified to override it. Along with the "-views"
parameter on the command line, this allows for multiple views to be generated
in a single doclet invocation.
View inheritance
View classes can inherit from other view classes, allowing views to
share a set of common matches. The standard java inheritance mechanism
is used to specify inheritance.
Abstract view classes won't be used to generate diagrams, the common
idiom is to declare a base abstract view to share common options and
overrides, and have concrete view classes that extend for diagram generation.
When using view inheritance the option building order is:
- Command line options
- UMLOptions options
- Base view options
- View options
- Base view match overrides
- View match overrides