Code_order_respect_toolCode order respect tool
Introduction
Although the Ada code is generated fully automatically, we allow you to organize the content of the source modules in order to respect your own code writing rules .
So this tool respects:
- Location of declarations for operations, attributes, types, etc, in the specification file and the body file.
- Order of declarations in structures (members), etc…
- Newlines count between declarations.
This tool can be used with basic round-tripping in operation’s body.
This tool doesn’t reverse code to rhapsody model, also doesn’t allow renaming arguments of methods (spec & body), changing method names, and types or attributes names.
All changes of the elements order in the source file are kept in it, and they are not sent back to the model. The mechanism of code order respect consists in merging a generated file with a source file. The order of elements in the source file is preserved, and new elements are added in the source file.
Activation and usage
To activate this tool:
- Open Rhapsody Developer for Ada application.
- Open a project.
- Select a Component element and double-click.
- Select Properties tab and expand subject Ada_CG , choose Component metaclass and find property RespectCodeLayout .
- Change this property to value Ordering .
Note: this tool can be activated only:
- If current language is Ada .
- Generated file extension is ada , ads and adb .
Frequent errors
Syntax error in Ada file
If a syntax error is inserted into source file, the code order respect tool cannot parse the file, and will not merge it with generated code from model. A message appears to show where the error is. User must fixe the error into the file before continuing.
An error message like the following one, should appear
Generating D:\Rhapsody\F_CodeRespect\DefaultComponent\DefaultConfig\Default\class_Ada_Task.adb. Ada syntax error: Encountered " "end" "end "" at line 82, column 9. Ada syntax error: Encountered " "end" "end "" at line 82, column 9.
Syntax error due to model
If Ada code generator generates a file with some syntax error, then the code order respect tool cannot parse the file. In this case, the source file is saved in another file, and the generated file is edited. A message of code generator shows where the error is. User must fixe the error into the model. When generated code is clean, the merge becomes possible, and the saved source file can be merged with generated file.
An error message like the following one, should appear
Generating D:\Rhapsody\F_CodeRespect\DefaultComponent\DefaultConfig\Default\class_Ada_Task.adb. Ada syntax error: Encountered " "end" "end "" at line 83, column 9. Your original file is saved as: D:\Rhapsody\F_CodeRespect\DefaultComponent\DefaultConfig\Default\class_Ada_Task.adb.ordered Please update the model and then check the generated file: D:\Rhapsody\F_CodeRespect\DefaultComponent\DefaultConfig\Default\class_Ada_Task.adb When no errors remain, your original file is restored and contains all updates.
Adding a new element
A new element is added at the end of the section (public or private). But this is not necessary the desired location. User will need to move it where he wants. In some case code generator creates some auto generated code. This code may need to be moved.
- When adding a statechart, the class wide declaration, statechart‘s constants and reactive_part package must be placed at the top of the spec before class record declaration
- When adding a state, the implementation of functions <state>_entry(), <state>_exit() and <state>_process_event() must be moved to the top of body.
- In animated mode, it is recommended to first generate code without code respect order, and to move user code afterwards.