Generating Code
See Also
The IDE's UML Modeling feature enables you to develop software incrementally, starting either from a new design or from an existing body of code. You can quickly generate source code for your UML model's classes and interfaces using a pop-up menu in the Projects window or in the Diagram editor.
To generate code:
- In the Projects window or in the Diagram editor, right-click the UML element or elements for which you want to generate code.
- In the Projects window, this code generation function is supported for entire UML projects and for individual diagram elements.
- From the pop-up menu, choose Generate Code.
- In the Generate Code dialog, specify the following settings:
- Target Project. Select the target project to which the generated code will be associated.
- Source Root. Specify which package folder location to store the generated source files.
- Backup Existing Source Files. If selected, the code generation process creates backup copies of the existing version of source files that are about to be generated. If not selected, backups are not created and changes are merged into the affected existing source files only.
An existing source file will be saved to a similarly named file with a number and a tilde (~) symbol appended to its file name. For example, a source file named sample.java
will be saved to a file named sample.java1~. On the next backup request, sample.java will be saved to sample.java2~, and so on. The most recent backup file is the file with the highest sequential number at the end of its filename.
- These backup files are not displayed in the IDE's Projects window, but are accessible outside of the IDE.
- The IDE maintains an internal history of recent changes to source files, which can be retrieved using the IDE's Local History tools.
- Generate Markers for Source File Merging. If selected, specifies that code be annotated with special code generation merge markers so that further code generation for the sources can be intelligently merged with existing code. Keep this option enabled until you are confident that you are finished modeling and you would like to generate the sources without the markers, if desired.
Attributes and operations that do not have any markers are ignored by the generate code process.
- Add Merge Markers to Existing Source Elements. If selected, merge markers are created in the existing source files which have attributes and operations that are
not yet annotated with the code generation marker. Once this option is selected, the marked elements can be overwritten immediately in the next invocation of the code generation process
- Prompt Before Generating Code. If selected, the Generate Code dialog is prompted every time the Generate Code action is invoked. This is the default action and provides you with the chance to change the generate code options (backup, merge markers or active templates) or to cancel out of the action before any sources are updated. Some may prefer to set the options once and never be prompted again. Disabling this option will prevent the dialog from displaying with each Generate Code execution.
- Templates Displays a list of available domain template categories. Under each category is a list of the
domain templates in summarized form (name, description, element type
and stereotype) with a check box that allows you to activate the domain
template. When activated, the domain template will be used for matching
elements in the project when the Generate Code action is invoked. At least one domain template must be activated for the generate code process to be executed. Hide Templates hides the list of available templates. Show Templates displays that list.
- Click OK.
The source code is generated for the selected element or elements.
- See Also
- Source Code Synchronization
- Configuring Domain Templates Options
- UML Categories in the Options Window
- Setting General Code Engineering Preferences
- Setting Java Code Engineering Preferences
Legal Notices