0% found this document useful (0 votes)
14 views34 pages

Chapter02 - Code Engineering

The document discusses code engineering tools and practices, including reverse engineering source code, importing source code and directories, synchronizing models and code, and generating source code. It provides details on the various options and steps to perform these code engineering tasks in Enterprise Architect.

Uploaded by

Biniyam Lamesgen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views34 pages

Chapter02 - Code Engineering

The document discusses code engineering tools and practices, including reverse engineering source code, importing source code and directories, synchronizing models and code, and generating source code. It provides details on the various options and steps to perform these code engineering tasks in Enterprise Architect.

Uploaded by

Biniyam Lamesgen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Software Engineering Tools and Practices

Chapter 02
Code Engineering

1
Chapter Outline
 Introduction to Code Engineering
 Reverse Engineering
 Import Source Code
 Import Source Directory
 Import Binary Module

 Synchronization
 Code Generation

2
Code Engineering
 Code Engineering is a process that includes
 automated code generation,
 reverse engineering of source code and
 synchronization between the source code and
model.

3
Reverse Engineering
 Software Reverse Engineering is a process of
recovering the design, requirement specifications and
functions of a product from an analysis of its source code
 Existing source code structures are mapped into their
UML representations

4
Reverse Engineering Cont’d
 Reverse Engineering enables users to examine
legacy code and examine the functionality of
code libraries for reuse or to bring the UML model
up to date with the code that has been developed
as part of a process called synchronization.

5
Cont..
 Examining the code in a UML model enables user
 to identify the critical modules contained the code,
 to enable the developers to gain a better overall
understanding of the source code.

6
Cont..
 To begin the process of importing existing code
into EA,
 an existing source code must be imported into
EA , which can be a single directory or a
directory structure .
 Several options are available when performing
the reverse engineering process.

7
Reverse Engineering Cont’d
 The Source Code Engineering Options contains
several options that affect the reverse engineering
process. These include:
 If comments are reverse engineered into notes fields,
 How property methods are recognized

8
Cont..
 EA currently supports reverse engineering in the following
programming languages:
 ActionScript, Ada 2005 (Systems Engineering and Ultimate
editions), C, C#, C++, Delphi, Java, PHP, Python, SystemC
(Systems Engineering and Ultimate editions), Verilog (Systems
Engineering and Ultimate editions), VHDL (Systems Engineering
and Ultimate editions), Visual Basic, Visual Basic .NET

 EA is also able to reverse engineer certain types of binary


files: Java .jar files and .NET PE files.

9
Import Source Code
 To import source code (reverse engineer) follow
the steps below:
1. In the Project Browser, select (or add) a diagram into
which to import the Classes.
2. Right-click on the diagram background to open the
context menu and either:
 Select the language to import from the Import
from source file(s) submenu, or

10
Cont..
 Click on the Import Language drop-down arrow in
the Code Generation toolbar and select the Import
| Import xxx files menu option, where xxx
represents the language to import.
3. From the file browser that appears, select source code
files to import.

11
4. Click on the Open button to start the import process.
As the import proceeds, EA provides progress information. When all files are
imported, EA makes a second pass to resolve associations and inheritance
relationships between the imported Classes. 12
Import a Source Directory
 You can import from all source files in a complete
directory structure.
 This process enables you to import or
synchronize multiple files in a directory tree in
one pass.
 EA creates the necessary packages and
diagrams during the import process.

13
Cont..
 To import a directory structure, follow the steps
below:
1. In the Project Browser, right-click on the target
package for the import.
2. From the context menu, select the Code
Engineering | Import Source Directory menu
option. The Import Source Directory dialog displays.

14
15
Cont’d
3. Select the options you require.
4. Click on the OK button to start.

16
Import Binary Module
 Enterprise Architect enables you to reverse-engineer
certain types of binary modules.
 To import a binary module, right-click on the target
package in the Project Browser and select the Code
Engineering | Import Binary Module context menu
option.
Permitted types are as follows:
 Java Archive (.jar)

 Net PE file (.exe, .dll);

 native Windows DLL and EXE files are not

supported, only PE files containing .NET


assembly data
 Intermediate Language file (.il).

17
Synchronize Model and Code
 In addition to generating and importing code, EA provides
the option to synchronize the model and source code,
creating a model that represents the latest changes in the
source code and vice versa.
 You can use either the model as the source, or the code as the
source.
 For example: you generated some source code, but made
subsequent changes to the model. When you generate code again,
EA adds any new attributes or methods to the existing source code,
leaving intact what already exists.
 Similarly, you might have made changes to a source code file, but
the model has detailed notes and characteristics you do not want to
lose. By synchronizing from the source code into the model, you
import additional attributes and methods but do not change other
model elements.

18
Generate Source Code
 Generating source code (forward engineering) takes the
UML Class or Interface model elements and creates a
source code equivalent for future elaboration and
compilation.
 By forward engineering code from the model, the
mundane work involved with having to key in Classes and
attributes and methods is avoided, and symmetry
between model and code is ensured.

19
Generate Source Code Cont’d
 Code is generated from Class or Interface model elements,
so you must create the required Class and Interface
elements to generate from.
 Add attributes (which become variables) and operations (which
become methods).
 Before you generate code, you should ensure the default
settings for code generation match your requirements.
 The default generation settings are located in the Source Code
Engineering page of the Options dialog (select the Tools | Options
| Source Code Engineering menu option).
 Set up the defaults to match your required language and
preferences.
 Preferences that you can define include default constructors and
destructors, methods for interfaces and the Unicode options for
created languages.
 Languages such as Java support namespaces and can be
configured to specify a namespace root. 20
Generate Source Code Cont’d
 The Code Template Framework (CTF) enables you to
customize the way EA generates source code and also
enables generation of languages that are not specifically
supported by EA.
 Before generating code, you should also familiarize yourself
with the way EA handles local path names.
 Local path names enable you to substitute tags for directory names
(for example %SRC% = C: \Source).
 When you have completed the design of your Classes, you
can generate source code.

21
Generate Source Code Cont’d
Tasks: When you generate code, you perform one or
more of the following tasks:
 Generate a Single Class
 Generate a Group of Classes
 Generate a Package
 Update Package Contents

22
Generate a Single Class
1. Open the diagram containing the Class or Interface for which to
generate code.
2. Right-click on the required Class or Interface to display the context
menu and select the Generate Code menu option, or press [F11].
The Generate Code dialog displays, which enables you to control
how and where your source code is generated.

23
Generate a Single Class
3. On the Path field, click on [ ... ] (Browse) and select a path name for your
source code to be generated to.
4. In the Target Language field, click on the drop-down arrow and select the
language to generate; this becomes the permanent option for that Class, so
change it back if you are only doing one pass in another language.
5. Click on the Advanced button. The Object Options dialog displays.

24
Generate a Single Class
6. Set any custom options (for this Class alone), then click
on the Close button to return to the Generate Code
dialog.
7. In the Import(s) / Header(s) fields, type any import
statements, #includes or other header information.(Note
that in the case of Visual Basic this information is ignored;
in the case of Java the two import text boxes are merged;
and in the case of C++ the first import text area is placed
in the header file and the second in the body (.cpp) file.)

25
Cont..
6. Click on the Generate button to create the source code.
7. When complete, click on the View button to see what has
been generated. Note that you should set up your default
viewer/editor for each language type first (see the Source
Code Viewer topic in Using Enterprise Architect - UML
Modeling Tool). You can also set up the default editor on
the DDL page of the Options dialog (Tools | Options |
Source Code Engineering | Code Editors).

26
Generate a Group of Classes
To Generate Multiple Classes
1. Select a group of Classes and/or interfaces in a diagram.
2. Right-click on an element in the group to display the
context menu.
3. Select the Code Generation | Generate Selected
elements menu option. The Save As dialog displays, on
which you specify the file path and name for each code
file. Enter this information and click on the Save button.
4. The Batch Generation dialog displays, showing the
status of the process as it executes (the process might
be too fast to see this dialog).

27
Generate a Package
To generate a package, follow the steps below:
1. In the Project Browser, right-click on the package to
generate code for. The context menu displays.
2. Select the Code Engineering | Generate Source Code
menu option. The Generate Package Source Code
dialog displays.

28
Generate a Package
3. In the Synchronize field, click on the drop-down arrow
and select the appropriate synchronize option:
 Synchronize model and code: Classes with existing files are
forward synchronized with that file; Classes with no existing file
are generated to the displayed target file
 Overwrite code: All selected target files are overwritten (forward
generated)
 Do not generate: Only selected Classes that do not have an
existing file are generated; all other Classes are ignored.
4. Highlight the Classes to generate. Leave unselected any
to not generate. If you want to display the information in
a more readable layout, you can resize the dialog and its
columns.

29
Cont..
5. To make EA automatically generate directories and
filenames based on the package hierarchy, select the Auto
Generate Files checkbox. This then enables the Root
Directory field, in which you select a root directory under
which the source directories are to be generated. By default,
the Auto Generate Files feature ignores any file paths that
are already associated with a Class. You can change this
behavior by also selecting the Retain Existing File Paths
checkbox.
6. To include all sub-packages in the output, select the
Include Child Packages checkbox.
7. Click on the Generate button to start generating code

30
Update Package Contents
 Enterprise Architect enables you to synchronize a
directory tree. Follow the steps below:
1. In the Project Browser, right-click on the root package of
the tree to synchronize. The context menu displays.
2. Select the Code Engineering | Synchronize Package
With Code menu option. The Synchronize Package
Contents dialog displays.

31
Update Package Contents Cont’d
3. In the Update Type panel, select the radio button to
Forward Engineer or Reverse Engineer the package
Classes.
4. To include child packages in the synchronization, select
the Include child packages in generation checkbox.
5. Click on the OK button to start.

Enterprise Architect uses the directory names specified


when the project source was first imported/generated and
updates either the model or the source code depending on
the option chosen.

32
Self-Review Questions
1. What is Code Engineering?
2. Explain Reverse Engineering
3. Write short notes on the following code generation
methods
 Generate a Single Class

 Generate a Group of Classes

 Generate a Package

 Update Package Contents

33
Reading Assignment
 Sequence Diagram

34

You might also like