How to Reverse Engineer UML from Java?

Instant reverse is a process to produce UML class model from a given input of source code. With instant reverse, you can reverse a snap shot of your code-base to UML classes and form class diagram in further. By bringing code content into visual UML model, this helps programmers or software engineers to review an implementation, identify potential bugs or deficiency and look for possible improvements. Apart from this, developers may reverse a code library as UML classes, and construct model with them, like to reverse a generic collection framework and develop your own framework by extending the generic one. In this chapter, we will go through the instant reverse of Java.

Reverse engineering UML classes from source files

  1. Select Tools > Code > Instant Reverse... from the toolbar.
  2. In the Instant Reverse window, select Java as the Language.
  3. Add the file or folder path of source by clicking on the appropriate Add button at the right hand side of the window. There are four kinds of supported sources: Jar file, class folder, a zip of source or a folder of source files.
    The Instant Reverse window
    The Instant Reverse window
    NOTE: You can reverse multiple source paths by adding them one after the other.
    You can add different kinds of source. For example, you can reverse a jar as well as a folder of source file at the same time.
  4. By default an on-demand reverse engineering will be carried out, which means to form indexes to the added path(s) instead of actually reversing them. For details about on demand reverse engineering, refer to the section below. If you want to carry out actual reverse engineering, uncheck Reverse source on demand.
  5. Click OK to start reversing.
  6. Upon finishing, the class repository will be popped up, listing the reversed classes (or indexes of classes if you are running an on-demand reverse engineering).
    NOTE: By cancelling from forming diagram, it just means you do not want to form diagram with the reversed classes for the time being.
    You can still look for the classes in Model Explorer or Class Repository, and possibly form diagram later on manually.

Overview of Instant Reverse

Overview of instant reverse window
Overview of instant reverse window
No. Name Description
1 Language The programming language for reversing.
2 Source paths A list of source paths to be reversed.
3 Add Jars
Add a path of Jar file for reversing.
4 Add class folder Add a path of Java class folder for reversing.
5 Add zips Add a path of a zipped source folder for reversing.
6 Add source folder Add a path of Java source folder for reversing.
7 Set model Set the model for placing the reversed UML classes into.
8 Remove Remove selected source path(s) from the list of source paths.
9 Up Move selected source path(s) upward in the path list. It just affects the order of reversing, and have no impact on the reversed UML classes.
10 Down Move selected source path(s) downward in the path list. It just affects the order of reversing, and have no impact on the reversed UML classes.
11 Reverse source on demand By checking, this means to form indexes to the source path(s) instead of actually reversing them. For details about on demand reverse engineering, refer to the section below.
12 Reverse to diagram Analyze the sources and form class diagram/package diagram when reverse.
13 OK Click to start reversing.
14 Cancel Click to cancel reversing and exit.
15 Help Click to read Help contents for instant reverse.
Description of instant reverse window

On-demand reverse engineering

Consider if you have a zip file that contains million of Java source file, like the file src.zip of Java Development Kit (JDK), and now you want to make the class java.util.Collection appear as UML class so that you can extend it when developing your own collection framework. Now, if you try to reverse the zip file it will take you a long time to complete the reverse due to the amount of classes (and relationships) is just too many. With on-demand reverse engineering, you will reverse the sources as indexes, and obtain an index tree in class repository. No actual UML classes will be reversed until you trigger the reverse manually. This reduces the processing time significantly.

To perform on-demand reverse engineering, make sure the option Reverse source on demand is checked in the Instant Reverse window.

The option Reverse source on demand that appear in reverse window
The option Reverse source on demand that appear in reverse window

When finished instant reverse, you can lookup the index tree in class repository. Then, right click on the class you want to reverse and select Reverse Resources to where Resources are the classes you have selected, and select either New Class Diagram or Class Repository from popup menu. Both options will result in reversing the selection to UML classes, while the option New Class Diagram will create a class diagram and place the classes in it.


Reversing a java source file from index tree
NOTE: On-demand reverse engineering is only available for Java

Forming class diagram from reversed classes

By the end of an instant reverse operation, you will be asked whether or not to form a class diagram with reversed UML classes. By selecting classes and configuring the way to present them, and confirm, a diagram will then be form.

The Instant Reverse Form Diagram window
The Instant Reverse Form Diagram window
NOTE: If you do not want Visual Paradigm to ask you for forming diagram next time you perform instant reverse, uncheck Show this window after instant reverse.
NOTE: The Form Diagram window will only pop up when you were reversing source with on-demand turned off. If you have performed an on-demand reverse engineering, you need to form diagram manually. For details, read the previous section.

Below is a description of this window, base on the tabs.

Select Class

The classes listing in the tree are those reversed from your code-base. You must select at least one class in order to form a class diagram. Notice that forming diagram can be a costly operation if you have selected too many classes in forming diagram.

Form Diagram Options

Option Description
Show superclasses
Show the generalization relationships between the selected elements and their super classes (ancestors) in the new diagram.
Show subclasses
Show the generalization relationships between the selected elements and their subclasses (descendants) in the new diagram.
Show suppliers (interface)
Show the realization relationships between the selected elements and their suppliers (interfaces) in the new diagram.
Show clients Show the realization relationships between the selected elements and their clients (classes that implements them) in the new diagram.
Show navigable classes Show the association relationships between the selected elements and their navigable classes (targets) in new diagram.
Show non-navigable classes Show the association relationships between the selected elements and their non-navigable classes (sources) in the new diagram.
Show containers Show the containment relationships between the selected elements and their containers (e.g. packages) in the new diagram.
Show residents

Show the containment relationships between the selected elements and their containers (e.g. packages) in the new diagram.

Single level only - Show one level residents only in the new diagram.

All levels in single diagram - Show all level residents in the new diagram.

All levels in sub diagrams - Show all level residents in the new diagrams (multiple single level diagrams).
Show as containment relationships

Show the containment relationships as connectors in the new diagram.

Notes: The containment relationships between classes are shown as connectors.


Description of form diagram options

Presentation Options

Option Description
Attribute options

Show all - Show all attributes of classes in the new diagram.

Public only - Show all public attributes of classes only in the new diagram.

Hide all - Hide all attributes of classes in the new diagram.

Initial values - Show initial values of attributes of classes in the new diagram.

Operation options

Show all - Show all operations of classes in the new diagram.

Public only - Show all public operations of classes only in the new diagram.

Hide all - Hide all operations of classes in the new diagram.

Initial values - Show initial values of operations of classes in the new diagram.
Type options

Fully-qualified - Show fully-qualified name of types.

Name only - Show name of types.

Relative - Show name of types relative to this class.


Description of presentation options

Reverse engineer package diagram from source files

By reverse engineering package diagram from source files, UML packages and the relationships in between will be produced.

  1. Select Tools > Code > Instant Reverse... from the toolbar.
  2. In the Instant Reverse window, select Java as the Language.
  3. Specify the path of the source file or the folder that contains those files.
    The instant reverse window
    The instant reverse window
  4. Select Package Diagram for Reverse To:.
  5. Click OK to start reversing.

Related Resources

The following resources may help you to learn more about the topic discussed in this page.

 
Chapter 1. Instant Reverse Table of Contents 2. Reverse engineering of C++ header files

We use cookies to offer you a better experience. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.OK