Previous Next
vpuml_user_guide Chapter 11 - Java Round-Trip Engineering

Chapter 11 - Java Round-Trip Engineering

VP-UML 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 VP-UML.
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


To generate the code:
1. Select from main menu Tools > Java Round-trip > Generate Code... .
 Figure 11.3 - Select Generate Code...

2. The Generate Code dialog box is displayed. Configure the Source Folder by select ... or typing the path in the text box.
 Figure 11.4 - Configure the Source Folder

3. You may also configure the Advanced Options .
 Figure 11.5 - Configure the Advanced Options

4. Afterwards, select OK to generate.
 Figure 11.6 - Select OK

5. Java files are generated.
Figure 11.7 - Java files generated

Reverse Code

You can reverse class model using Java round-trip Engineering in VP-UML.
Figure 11.8 - Reverse code

Here, a Java file called Professor.java which created in source is used as an example.
 Figure 11.9 - Java source of Professor.java

To reverse Java code using Java round-trip engineering:
1. Select from main menu Tools >Java Round-trip > Reverse Code...
Figure 11.10 - Select Reverse Code...

2. Reverse Code dialog box is displayed. Configure Source Folder by select ... or type in the text box. You can check the Reverse source on demand to drag and drop from the class repository to diagram to reverse.
 Figure 11.11 - Configure Source Folder

3. Select OK to confirm.
 Figure 11.12 - Select OK to confirm

4. Open the Class Repository pane. You can see the Java file for reverse.
Figure 11.13 - Class Repository pane

5.Drag and drop the Professor.java to the project. A new class is formed.
 Figure 11.14 - Drag and drop to create a new class

Round-trip Code Engineering

Here, the Java round-trip Engineering is shown.
 Figure 11.15 - 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.16 - Statement amended

Also, an operation is added.
 Figure 11.17 - Class added
On the other hand, the signature of a class is amended in the diagram.
 Figure 11.18 - Signature amended

After all the changes have been saved, open the Generate Code dialog box to configure the source folder and options. The source folder should be the same as previous path where Java files were generated. Click OK to confirm.
 Figure 11.19 - Generate Java code

The source has been changed. Both the changes in the source and in the diagram are retained.
Figure 11.20 - Source changed

Now open the Reverse Code dialog box to configure the source folder and options. The source is reversed into diagram.
Figure 11.21 - Class changed

Advanced Options

Upon generation of Java round-trip engineering, there are advanced options for you to configure your output document with.
There are three tabs.

Code tab
 Figure 11.22 - 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 Checked the checkbox so that before updating the code, VP-UML 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.
 Figure 11.23 - Example illustrating options in Code tab about default type setting

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


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

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

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




Brace and Indentation tab
 Figure 11.28 - 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.
Figure 11.29 - Example illustrating options in Brace and Indentation tab



New Lines Tab
 Figure 11.30 - 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.

Figure 11.31 - Example illustrating options in New Lines tab

Figure 11.32 - Example illustrating option in New Lines tab

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