Book a Demo

Author Topic: Synchronize model and code vs Overwrite code  (Read 4458 times)

ESC

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Synchronize model and code vs Overwrite code
« on: May 09, 2022, 06:16:24 pm »
I am currently testing Enterprise Architect v15.2.

I created several classes in C language with attributes and operations, when I click on "Generate" to generate the Package Source Code, I have two choices for "Synchronize":
  • Synchronize model and code
  • Overwrite code

I use the "Overwrite code", it allows me to create the .c / .h files of the package, everything works well with the comments associated with the operations / attributes (I edited the Code Template Editor to match the template of our company)

But when I then do "Synchronize model and code" without modifying the files, the comment in the header associated with my first function is replaced by the class comment

Do you have any recommendations for fixing this?

Thanks

ESC

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Synchronize model and code vs Overwrite code
« Reply #1 on: May 09, 2022, 09:11:18 pm »
I think it's a synchronization bug with %classNotes% and %ClassNotes% macros

Here's how I fixed it :

For File Impl, i use %classNotes% :
Code: [Select]
/** @file %fileNameImpl%
 *
 * %classNotes%
 */

And I edit "Class Notes" to add Notes only for enumeration and structure :
Code: [Select]
%PI="\n"%
%if genOptGenComments != "T"%
%endTemplate%

%if elemType == "Enumeration" or classStereotype == "struct"%
$wrapLen = %genOptWrapComment%
%CSTYLE_COMMENT($wrapLen)%
%endIf%

So I no longer have a problem, but if I want to have access to the class notes, I have to be careful to use %classNotes% instead of %ClassNotes%

ESC

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Synchronize model and code vs Overwrite code
« Reply #2 on: May 10, 2022, 12:33:15 am »
In fact I always have an issue when I use the button "Synchronize", "Synchronize Package", "Reverse engineer". In this case I have each time the notes of my classes which are replaced by the comment of the first function, does anyone have a suggestion?

I don't know if I should use something like %synchNewClassNotesSpace% to fix this. I also have the possibility to choose to uncheck the Comments on the Reverse in the preferences of the "Source Code Engineering" but the idea was still to manage to synchronize everything.

I understood how the Code Template Editor works for generation but I still have trouble understanding how it uses the template for synchronization.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Synchronize model and code vs Overwrite code
« Reply #3 on: May 10, 2022, 08:30:07 am »
If you add extra text to a comment that EA will later reverse engineer, there's no way for EA to know you've done that. That text will be reverse engineered into the matching model element.

The only way I can think to prevent it being duplicated is using LEFT, MID, FIND commands to remove the extra text before generating it the second time.

ESC

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Synchronize model and code vs Overwrite code
« Reply #4 on: May 10, 2022, 05:56:21 pm »
Thanks Eve for your reply,

Actually I don't try to add extra comments in the code. Here are the steps I do:
1. Generate package with "Overwrite code option" to generate all *.c / *.h files from the model
2. Test with generate package with "Synchronize model and code" => Ok I have the same code / model
   => If I add a new operation on the model => the new operation is correctly added to the *.c / *.h files
   => If I add a new operation on the code => the new operation is ignored during this phase and the model is not updated
3. Synchronize package with Reverse engineer => NOK : the notes of each class are replaced in the model by the comment of the first operation (Even without any code changes since step 1)

The objective is to create the source files from the model, then continue the development on the code and resynchronize the changes in the model if necessary to generate the updated documentation. The problem is that during synchronization the notes are no longer correct and the documentation cannot be generated.

Here is an example of the structure of the .h file :
Code: [Select]
/** @file %fileName%
 *
 * Header-File with definitions for %className%
 *
 */

/**
 *  Extra comment for test
 */
/* ----------------------------------------------------------------------------
* includes
* ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
* public defines
* ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
* public macros
* ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
 * public types
 * ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
 * public functions
 * ---------------------------------------------------------------------------*/
/**
 * Comment for Function1
 */
void Function1(void);

/**
 * Comment for Function2
 */
void Function2(void);

Each time after the synchronization, the content of %classnotes% is replaced by the comment of function N°1 (the notes of function N°1 and of the other functions are always correct, only the notes of the class are replaced)

In fact, it will always consider the notes of the class by the first comment of an element of the class, for example :
Code: [Select]
/** @file %fileName%
 *
 * Header-File with definitions for %className%
 *
 */

/**
 *  Extra comment for test
 */
/* ----------------------------------------------------------------------------
* includes
* ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
* public defines
* ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
* public macros
* ---------------------------------------------------------------------------*/

/* ----------------------------------------------------------------------------
 * public types
 * ---------------------------------------------------------------------------*/
/**
 * Comment for Enum1
 */
typedef enum
{
  EnumValue0 = 0,
  EnumValue1 = 1
} Enum1;

/* ----------------------------------------------------------------------------
 * public functions
 * ---------------------------------------------------------------------------*/
/**
 * Comment for Function1
 */
void Function1(void);

/**
 * Comment for Function2
 */
void Function2(void);

In this case the note of the class will be replaced by the comment of Enum1.

This is a blocking element for the moment because it prevents us from considering the use of enterprise architect for code generation and synchronization in order to always have up-to-date documentation.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Synchronize model and code vs Overwrite code
« Reply #5 on: May 11, 2022, 09:18:12 am »
Sorry, my mistake I read your second post and assumed that every time you reverse engineered it was adding "@file %fileNameImpl%" to the start of your notes.

When reverse engineering, EA has some rules for determining which comments are associated with which model elements. Generally that means the comment immediately before the definition. It sounds like in your situation (or possibly for all C code) that doesn't work. The way EA works, the Class will start at the first member, so the comment immediately before that will be the one you've described. Which will result in the behavior you described.

ESC

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Synchronize model and code vs Overwrite code
« Reply #6 on: May 13, 2022, 11:20:40 pm »
Thanks Eve for your reply,

I did several tests from the default values of the Code Template Editor to check if it was not related to my changes.

The bug is very easy to reproduce (with default code template editor):
1. Create a C-Class with one public attributes
2. Add some notes for Class
3. Add some notes for Attributes
4. Generate the file with "Overwrite code" options
5. Synchronize package with "Reverse engineer" option
=> Class notes are replaced by attribute notes

I confirm that the problem is present for the C language but not for Java.

I am looking for a workaround to this situation, I'm wondering if I can't just ignore the contents of the class notes and use another way to set the class note (I don't necessarily want to resynchronize the contents of the classNotes)

I had already used the link with the requirement connector to be able to generate the requirements notes in the code (thanks to the help you provided on another post).

So I tried to do the same for a note but i tried with different types of note (text, note with Relationship = NoteLink, InformationItem, etc) which would be associated with the class but i can't generate the note content in code with the code template editor.

I also tried using the linked document of the class to put the note in there but also failed to generate the content of the linked document in the code.

If there isn't really a simple solution with notes in connector, I'll probably use the %classAlias% instead of the %classNotes% and ignore the content of the %classNotes%