Reverse engineer UML diagrams by using IBM Rational Software Architect, Version 7.5

In IBM® Rational® Software Architect, Version 7.5, you can reverse engineer code to analyze a Java™ project by creating inheritance trees that contain details of classes and their relationships as Unified Modeling Language (UML) diagrams. This article explains the steps to use reverse engineering on a small Java project.

Si Yin (Si.Yin@nl.ibm.com), IT Consultant, IBM

Photo of Si YinSi Yin is an IT consultant at the IBM Center of Excellence in Water Management in Amsterdam, the Netherlands. He is a technical specialist for Water Management projects. Si graduated cum laude with an M.Sc. in computer science from Vrije Universiteit Amsterdam and was an Extreme Blue student in 2007.



Fenglian Xu (xufengli@uk.ibm.com), Software Developer, WebSphere Enterprise Service Bus Development team, IBM

Photo of Fenglian XuDr. Fenglian Xu is a Software Engineer on the WebSphere Service Registry and Repository Development team at the IBM Software Lab in Hursley, United Kingdom. Previously, she worked on the WebSphere Enterprise Service Bus Development team. Her expertise includes IBM middleware product integration in service-oriented architectures, and she is also an IBM developerWorks Contributing Author. She earned a B.S. in Mathematics from Xian Jiaotong University in 1989, and a Ph.D. in Computer Science from the University of Southampton in 1998. You can contact Fenglian at xufengli@uk.ibm.com


developerWorks Contributing author
        level

13 August 2009

Also available in Chinese Vietnamese Spanish

Create an inheritance tree of classes by using Software Analyzer

In object-oriented programming languages, inheritance shows the common fields and methods among inherited classes within a family and displays the specific fields and methods for each class. Developers and architects can use inheritance trees of the classes in a Java™ project to understand the relationships among the classes in the project. Suppose that you have created or loaded a Java project in IBM® Rational® Software Architect 7.5. To create an inheritance tree in the project:

  1. Open the Software Analyzer in Rational Software Architect V7.5 by selecting Run > Analysis (see Figure 1). You can use the Software Analyzer to generate reports that are based on rules that you select. Rational Software Architect V7.5 includes rules in the domains of Java Architectural Discovery, Code Review, UML Model Metrics, and UML Model. Creating an inheritance tree is a rule in the Java Architectural Discovery domain.
Figure 1. Open the Software Analyzer
Drop-down menu to open the Software Analyzer.
  1. Create a configuration:
    1. In the Name field, type a name.
    2. In the Analysis Domains and Rules area, expand the Object-oriented Patterns category and select the Inheritance Tree check box (see Figure 2).
Figure 2. Create an inheritance tree
the Software Analyzer window

Click here for a larger view of Figure 2.

  1. Click Analyze. An inheritance tree is displayed (see Figure 3). This inheritance tree shows that a Vehicle class has three children: Bicycle, Car, and PogoStick. The Car class has two children: FamilyCar and SportsCar. There is no information about class fields and methods in the inheritance tree. To explore the fields and methods of the classes, use a browse diagram.
Figure 3. The inheritance tree is generated by Software Analyzer
Screen capture of the inheritance tree, as described.

Click here for a larger view of Figure 3.


Explore the details of the inheritance tree by using a browse diagram

The inheritance tree that you created with the Software Analyzer does not contain details about the fields and methods of the classes. To find out about the details of each class within a certain scope, use a browse diagram. The scope can be a Java package, a project, a work set, or a workspace. For example, use the FamilyCar class as a starting point to explore its details with a browse diagram:

  1. To open a browse diagram, right-click on the FamilyCar.java class name and then select Visualize > Explore in Browse Diagram (Figure 4).
Figure 4. Explore the FamilyCar class in the browse diagram
An image of the steps to open a browse diagram.
  1. In the Browse Diagram window, on the relationship toolbar, click the Extends button (see Figure 5). The relationship toolbar contains five types of relationships:
    • arrow iconExtends: Explores the classes from which FamilyCar is extended
    • arrow iconDependency: Explores the classes that are used in the methods of the FamilyCar class
    • arrow iconRealization: Explores the interface that is implemented by FamilyCar
    • arrow iconAssociation: Explores the classes that are related to FamilyCar
    • magnifying glass iconDeclares: Explores declared packages in the FamilyCar class
    • Degree of separation: Explores the level of extension that the relationship applies
Figure 5. A browse diagram of the FamilyCar class with one degree of separation
An image of the class in a browse diagram
  1. Next to the relationship toolbar is a degree of separation, which indicates the number of relationship levels from the FamilyCar class that are shown in the diagram. In Figure 5, the value of 1 (one) indicates that the diagram shows the FamilyCar class only. When you apply the value of 2, the diagram shows the FamilyCar, Car, and Vehicle classes (see Figure 6).
Figure 6. The FamilyCar class in a browse diagram with 2 degrees of separation
An image of the browse diagram, as described.

The browse diagram of the inheritance tree is a temporary diagram that you cannot save. Typically, you use browse diagrams to explore a given class or to document the design of a project.


Generate an inheritance tree by using a topic diagram

The previous example showed how to use a browse diagram to visualize the inheritance tree of a class. In certain circumstances, you might want to create a diagram which consistently represents all of the inherited classes of the FamilyCar class during the development of the program. In this case, you can use a topic diagram to represent the inheritance tree of a given class. Unlike a browse diagram, you can save a topic diagram in a model file for a reuse.

To create an inheritance tree of a class in a topic diagram:

  1. Open a topic diagram of a given class, such as FamilyCar, by right-clicking the FamilyCar.java class and then selecting Visualize > Add to New Diagram File > Topic Diagram (see Figure 7).
Figure 7. Open the FamilyCar class in a topic diagram
Drop-down menu selections to open a topic diagram
  1. Generate a topic diagram:
    1. Select a topic, such as Inherited Java Classes (N levels)
    2. Specify the related elements to be shown. In this example, the Extend relation is selected with indefinite expansion on both incoming and outgoing directions to represent the whole inheritance tree.
    3. Click Finish. The result is shown on the right of Figure 8.

To respond to changes in Java source code, update the diagram by right-clicking the topic diagram workspace and clicking Refresh.

Figure 8. Create an inheritance tree by using a topic diagram
3 screen captures show creating inheritance tree

Click here for a larger view of Figure 8.

Integrate a generated class diagram into a model file by using Harvest

In Rational Software Architect, you can transform a model file into Java code. You might create a model file by creating a new class with some attributes and methods; you might also want to integrate existing Java classes from a project into the model file. To use the Harvest function in Rational Software Architect to copy a generated class diagram into your model file:

  1. Create a blank model file by clicking File > New item. A new wizard window opens (see Figure 9).
Figure 9. Open the Model wizard
The New window in Rational Software Architect
  1. Click Next and follow the workflow in Figure 10, which shows a freedom diagram.
Figure 10: Create a model file
3 screen caputres: how to create a model file

Click here for a larger view of Figure 10.

  1. Copy the class diagrams into the new model file by using the Harvest function:
    1. Select all of the classes in the diagram (see Figure 11).
    2. Right-click the diagram, and then click Harvest.
Figure 11. Harvest the selected classes in the browse diagram
Harvest feature selected in drop-down menu
  1. Paste the classes into the new model file (Figure 11 shows the result).

In Figure 11, neither the Vehicle nor Car classes show fields and methods information. To make the fields and methods visible, select one or more classes in the diagram, right-click the class or classes, and click Filters > Show/Hide Compartment > All Compartments (see Figure 12). To view the final results of enabling the compartments, see Figure 13.

Figure 12. Show all of the compartments of the Vehicle class
Drop-down menus to select compartments of a class

Click here for a larger view of Figure 12.

Figure 13. The compartments of the Vehicle class
All of the compartments of the class are visible.

Summary

To analyze and expand Java projects, you can use the tools in Rational Software Architect, Version 7.5 for these actions:

  • To generate an inheritance tree for all of the classes in a project, use the Software Analyzer.
  • To visualize the details of a class that is part of an inheritance tree, use a browse diagram.
  • To use a fixed query to monitor code changes, use a topic diagram.
  • To paste a class from an inheritance tree into a model file, use the Harvest function.

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=419386
ArticleTitle=Reverse engineer UML diagrams by using IBM Rational Software Architect, Version 7.5
publish-date=08132009