Author Topic: $LinkClass to use camelBack  (Read 616 times)

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
$LinkClass to use camelBack
« on: March 13, 2008, 02:09:46 am »
Will somebody please give a definitive answer to achieving code generation of attributes that uses camel back notation (lower case first letter, rest same as class name). Please paste the code/text that should be placed in the 'Code Template Editor' for 'linked attribute'.

These are the posts that discuss this as a solution, but leave out the most important part: the actual way to do it!

http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1154732052/0#0

http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1194615140/0#0

http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1146123279/1#1

http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1105205474/0#0


Thanks in advance.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: $LinkClass to use camelBack
« Reply #1 on: March 13, 2008, 02:24:04 am »
Look up Convert Names in EA Help.

EDIT: But then read on, Simon's suggestion below is much better. Convert Names is not good in a round-trip scenario.
« Last Edit: March 13, 2008, 09:47:02 pm by Midnight »
No, you can't have it!

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: $LinkClass to use camelBack
« Reply #2 on: March 13, 2008, 02:32:48 am »
From the help file on Convert Names:
Quote
Different target platforms use different naming conventions. As a result you might not want to copy the names of your elements directly into the transformed models. To facilitate this requirement, Enterprise Architect's transformation templates provide a CONVERT_NAME function macro.

Another way in which you might want to transform a name is to remove a prefix from the original name, with the REMOVE_PREFIX macro.

This is looks useful if I wanted to transform my existing project to another language.
Again, I would like the $LinkClass in the attribute "Default name for associated attrib:" in Tools->Options->Source Code Engineering-> Attributes/Operations to default to "myClassName" instead of "MyClassName".

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: $LinkClass to use camelBack
« Reply #3 on: March 13, 2008, 07:03:23 am »
Which options have you set on that dialog?
No, you can't have it!

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6215
  • Karma: +49/-5
    • View Profile
Re: $LinkClass to use camelBack
« Reply #4 on: March 13, 2008, 12:52:58 pm »
You can't get all the way.  Midnight's comment will cause EA to generate the name in the right format, but during synchronisation it won't recognise that it was generated from that association (because the name is different than the option suggests).

Here's how you can modify the template anyway.  Replace
Code: [Select]
%REPLACE(genOptDefaultAssocAttName,"$LinkClass",linkAttName)%;with
Code: [Select]
$className==%CONVERT_NAME(linkAttName, "pascal case", "camel case")%
%REPLACE(genOptDefaultAssocAttName,"$LinkClass",$className)%;
But what I would really recommend is just setting the name of the role on the association, and therefore avoiding any issues.
Simon

support@sparxsystems.com

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: $LinkClass to use camelBack
« Reply #5 on: March 13, 2008, 09:45:33 pm »
Quote
You can't get all the way.  Midnight's comment will cause EA to generate the name in the right format, but during synchronisation it won't recognise that it was generated from that association (because the name is different than the option suggests).
...
Ouch!

I should have thought of that. Don't go with my idea, as this will bite you for sure. [Unless you get your entire project right the first time, and don't ever need another iteration. But then why are you building the model?]

Quote
...
But what I would really recommend is just setting the name of the role on the association, and therefore avoiding any issues.
Go with what Simon says. This makes a lot of sense. You'll have to play with the options a bit, but once you teach your fingers how to set them (the options) right just leave them in place and you'll be fine.

David

PS: I don't know for sure, but my guess is that you cannot set the role automatically on a code import. But you should be able to do it with a transformation.
No, you can't have it!

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: $LinkClass to use camelBack
« Reply #6 on: March 14, 2008, 02:36:51 am »
Thanks. My macro is now correct. Looks like I'll be adding this macro language to my list of things to learn.

One problem exists, still.

In the Tools->options->Source code..->Attribute...=>"Default name for associated attrib:":

Removing the "m_" or changing it to an arbitrary string "ggg" has no effect on the resulting preffix after code generation/sync. It ALWAYS makes a preffix "m_", although what follows now is my classname in camel back (thanks Simon M).

This same question was posed on the end of this thread, but not answered:
http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1080087168/3#3

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: $LinkClass to use camelBack
« Reply #7 on: March 14, 2008, 03:12:07 am »
Oops.. did not realize that the settings are cascading. There is a generation configuration on the EA level and then model. ('Generate' on individual element, then click advanced, then make settings changes, these overwrite the one's from the EA tools on toolbar.)
« Last Edit: March 14, 2008, 03:16:49 am by puromtec »