Previous Next
sde_java_user_guide Chapter 11 - Java Round-Trip Engineering

Chapter 11 - Java Round-Trip Engineering

SDE for Eclipse facilitate the generation and reverse of Java by the Java Round-Trip Engineering.

In this chapter:

Generate Code

You can generate Java using Java round-trip Engineering in SDE for Eclipse.
Figure 11.1 - Generate code

Here, a class diagram is used as an example to illustrate the steps of generating code.

Figure 11.2 - Class diagram used as an example

You may generate Java source code from three kinds of sources: project, package and class.

Generate by Selecting Project

There are several ways of generating code from project. The first one is by clicking Update Code in the toolbar.
 Figure 11.3 - Clicking Update Code

Alternatively, you may select Update Code in Diagram Navigator, Model Tree or Class Repository.
 Figure 11.4 - Selecting Update Code

You may also right-click on the project node in Diagram Navigator, Model Tree or Class Repository, and then select Update Project to Code from the popup menu.
 Figure 11.5 - Selecting Update Project to Code

This will result in generating code from all the classes models under the project.

Generate by Selecting Package

Besides generating all the class models, you may select to generate a package of classes. There are several ways to achieve this. The first one is by right-clicking on a package in Diagram Navigator, Model Tree or Class Repository, and then by selecting Update to Code from the popup menu.
 Figure 11.6 - Selecting Update to Code

You may also right-click on a package on diagram, and select Update to Code from the popup menu.
 Figure 11.7 - Selecting Update to Code from the popup menu of a package on diagram

Both approaches will result in generating code from the selected package and the class models under it.

Generate by Selecting Class

You may also select to generate code from specific classes. The first way to achieve this is by right-clicking on a class in Diagram Navigator, Model Tree or Class Repository, and selecting Update to Code from the popup menu.
 Figure 11.8 - Selecting Update to Code

Alternatively, right-click on a class on diagram, and select Update to Code from the popup menu.
 Figure 11.9 - Selecting Update to Code

This will generate code from the selected class model.

Reverse Code

You can reverse class model using Java round-trip Engineering in SDE for Eclipse.
Figure 11.10 - Reverse code

Here, a class called Professor which created in the IDE is used as an example.
 Figure 11.11 - Java source of Professor.java

You may reverse Java source code from three kinds of sources: project, package and class.

Reverse by Selecting Project

There are several ways of reversing code from project. The first one is by clicking Update UML Model in the toolbar.
Figure 11.12 - Selecting Update UML Model

Alternatively, you may select Update UML Model in Diagram Navigator, Model Tree or Class Repository.
Figure 11.13 - Selecting Update UML Model

You may also right-click on the project node under the Package Explorer, and then select Update UML Model from the popup menu.
Figure 11.14 - Selecting Update UML Model

This will result in reversing all the classes and packages defined under the source project.

Reverse by Selecting Package

Besides generating all the class models, you may select to generate a package of classes by right-clicking on a package node under the source project, and then by selecting Update UML Model from the popup menu.
Figure 11.15 - Selecting Update UML Model

This will result in reversing the selected package, its contained classes, and its subpackages.

Reverse by Selecting Class

You may also select to reverse from specific classes. The first way to achieve this is by right-clicking on a class node under the source package, and selecting Update UML Model from the popup menu.
Figure 11.16 - Selecting Update UML Model

Alternatively, right-click on the code editor, and select Update UML Model from the popup menu.
Figure 11.17 - Selecting Update UML Model

This will reverse the selected class into UML class model.

Forming Diagram from Reversed Model

UML class models are formed by reverse engineering. They can be used to form a new class diagram. To form a class diagram from the class models:
  1. Select from Model Tree or Class Repository the class models to be included in the new diagram.
  2. Right-click on the selection
  3. Select Form Diagram > %OPTION% from the popup menu
To add class models to an existing diagram, simply drag them from Model Tree or Class Repository and drop them onto the diagram.
 Figure 11.18 - Drag and drop to add a class model to diagram

Select Code from Model

When editing a class or a class member such as attribute or operation, you can open up the corresponding piece of code. By doing so, the code editor will show up and the related portion of code will be highlighted. You can select code from model in different ways:
To select code from Model Tree, Class Repository or Diagram Navigator:
Right-click on a class, operation or attribute model under the tree and select Select in Code in the popup menu.
Figure 11.19 - Selecting code from class model

To select code from class models in diagram:
Right-click on a class, operation or attribute model in the diagram and select Select in Code in the popup menu.
Figure 11.20 - Selecting code from operation
Selection cannot be made to project and package.

Select Model from Code

During implementation, you can select a class model from the code. By doing so, the class model will be selected under the Model Tree and Class Repository. However, selection won't be made to class shape in any diagram. You can select model from code in different ways: To select code from Model Tree, Class Repository or Diagram Navigator:
Right-click on a class, operation or attribute model under the tree and select Select in Code in the popup menu.
Figure 11.21 - Selecting class model from code

To select code from class models in diagram:
Right-click on a class, operation or attribute model in the diagram and select Select in Code in the popup menu.
Figure 11.22 - Selecting class model from code
Selection cannot be made to project, package, attribute and operation.

Round-trip Code Engineering

Here, the Java round-trip Engineering is shown.
 Figure 11.23 - Java round-trip Engineering

In order to demonstrate the round-trip code engineering, the source of a generated Java file is amended. First, a statement is amended in the source.
 Figure 11.24 - Statement amended
Also, an operation is added.
 Figure 11.25 - Class added
On the other hand, the signature of a class is amended in the diagram.
 Figure 11.26 - Signature amended

After all the changes have been saved, generate to code. The source has been changed. Both the changes in the source and in the diagram are retained.
Figure 11.27 - Source changed
Now reverse code. The source is reversed into diagram.
Figure 11.28 - Class changed

Advanced Options

Upon generation of Java code, there are advanced options for you to configure your output with. To open the options dialog:
  1. Select Modeling > Application Options... from to open the Options dialog box.
  2. Open the Eclipse category.
You can enable or disable changing to Modeling Perspective when starting SDE-EC by selecting the desired option from the dropdown menu Change to UML perspective when start SDE-EC.
Figure 11.29 - Change to UML perspective

There are three tabs.
Code tab
 Figure 11.30 - Code tab

Name Description
Default attribute prefix Configure the default prefix of attribute.
Default operation return type
Configure the default return type of operation.
Default parameter type
Configure the default prefix of parameter.
Remove method body after changes to abstract method
Check the check box to remove method body after change to abstract method.
Add import statement instead of using fully qualified type name
Check the check box to add import statement.
Import fully qualified type name for referenced type Check the check box to import fully qualified type name.
Auto realize interface
Check the check box to realize interface automatically.
Collection type
Select a collection type from the drop down menu.
Use generic collections Check the check box to use generic collections.
Generate annotation on Specify the code generator to generate the annotation in field-based or property-based access type.
Generate annotation in code convention Check the checkbox so that before updating the code, SDE for Eclipse will select suitable placement strategy on either field-based or property-based access type.
System default Select the system default type of text file encoding to type.
Other Select other types of text file encoding to type.
Apply Eclipse code formatting Check the check box to make the generated code follow Eclipse's code formatting. Otherwise, user can defined the code formatting on Brace and Indentation and New Lines tabs.
Table 11.1

 Figure 11.31 - Example illustrating options in Code tab about default type setting

 Figure 11.32 - Example illustrating options in Code tab about Remove method body

 Figure 11.33 - Example illustrating options in Code tab about Add import statement

 Figure 11.34 - Example illustrating options in Code tab about Auto realize interface

 Figure 11.35 - Example illustrating options in Code tab about Java Collection

Brace and Indentation tab
 Figure 11.36 - Brace and Indentation tab

Name Description
Class declaration
Select the position of Class declaration from the drop-down menu.
You can place it on the same line or the next line.
Constructor declaration
Select the position of Constructor declaration drop-down menu.
You can place it on the same line or the next line.
Method declaration
Select the position of Method declaration drop-down menu.
You can place it on the same line or the next line.
Enum declaration
Select the position of Enum declaration drop-down menu.
You can place it on the same line or the next line.
Annotation type declaration
Select the position of Annotation type declaration drop-down menu.
You can place it on the same line or the next line.
All Same Line
Select to set all the brace positions to be on the same line.
All Next Line
Select to set all the brace positions to be on the same line.
Indentation policy
Select a way of indentation.
You may choose Tabs and space to be the indentation.
Indentation size
If you select space as indentation, you can select the size of it.
Table 11.2

Figure 11.37 - Example illustrating options in Brace and Indentation tab

New Lines Tab
 Figure 11.38 - New Lines Tab

Name Description
Before package declaration
Type in the number of blank lines place before package declaration.
After package declaration
Type in the number of blank lines place after package declaration.
Before import declaration
Type in the number of blank lines place before import declaration.
After import declaration
Type in the number of blank lines place after import declaration.
Before first declaration
Type in the number of blank lines place before first declaration.
Before different kind declaration
Type in the number of blank lines place before different kind declaration.
Before field declaration
Type in the number of blank lines place before field declaration.
Before method declaration
Type in the number of blank lines place before method declaration.
Before inner type declaration
Type in the number of blank lines place before inner type declaration.
Number of lines to empty body Type in the number of blank lines place to the empty body.
Table 11.3

Figure 11.39 - Example illustrating options in New Lines tab

Figure 11.40 - Example illustrating option in New Lines tab

Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com