Author Topic: Suggest template modification for C# or Java  (Read 3333 times)

orientphoebus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Suggest template modification for C# or Java
« on: December 02, 2005, 01:36:30 pm »
In order to deal with 1..* relationships. I modified these templates:
They are for "Forword Engineering". Not found the way for "Reverse Engineering" yet. Please help if anyone know how to do it.:

Attribuite Declaration:
Quote
$typeName=%attType%
%if attType==""%
$typeName=%genOptCSDefaultAttributeType%
%endIf%
$arrayTypeName=$typeName+"[]"
$genericCollectionTypeName="<"+$typeName+">"
$attrComment=%XML_COMMENT(genOptWrapComment)%
$attrCommentLength=%LENGTH($attrComment)%

$ttt
%if attTag:"Attribute" != ""%
%REPLACE(attTag:"Attribute", ";", "\n")%
%endIf%

%if classStereotype == "enumeration"%
%PI=""%
%attName%
%attInitial ? " = " value%
%endTemplate%

%if attCollection == "T" and attContainerType != "" and attContainerType != "Array" and attContainerType != "[]"%
%if $attrCommentLength == "0" %
/// <summary>
/// Collection of $typeName
/// </summary>
%endIf%
%endIf%

%PI=" "%
%CONVERT_SCOPE(attScope)%
%attStatic=="T" ? "static" : ""%
%attConst=="T" ? "readonly" : ""%
%if attCollection == "T" and attContainerType != ""%
%if attContainerType == "Array" or attContainerType == "[]"%
$arrayTypeName
%else%
%REPLACE(attContainerType,"<>",$genericCollectionTypeName)%
%endIf%
%else%
$typeName
%endIf%
%PI=""%
%attName%
%attInitial ? " = " value%

%if attStereotype == "property"%

{\n\t//read property\n\tget{;}\n\t//write property\n\tset{;}\n}
%endTemplate%

;


Linked Attribute Declaration:
Quote
$type=%linkAttName%
$linkName="<"+%linkAttName%+">"
%if linkAttCollectionClass != "" and linkCard != "" and linkCard != "0" and linkCard != "0..1" and linkCard != "1"%
%if linkAttCollectionClass == "Array" or linkAttCollectionClass == "[]" %
$type+="[]"
%else%
$type=%REPLACE(linkAttCollectionClass,"<>",$linkName)%
%endIf%
%endIf%

%PI=" "%
%CONVERT_SCOPE(linkAttAccess)%
%linkAttTargetScope=="classifier" ? "static" : ""%
$type
%PI=""%

%if linkAttRole != ""%



Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8066
  • Karma: +118/-20
    • View Profile
Re: Suggest template modification for C# or Java
« Reply #1 on: December 04, 2005, 09:37:40 pm »
You can't currently update the Reverse engineering.  It's a lot more complex than templates.

Your attribute declaration template is interesting, but move the part that generates a comment into the Attribute Notes template.  Otherwise you'll have synchronisation issues.

Throw away your linked attribute template though.  Look at http://sparxsystems.com.au/EAUserGuide/index.html?settingcollectionclasses.htm and set your collection class to #TYPE#[] or MyCollectionClass<#TYPE#>.  That's what the linkAttCollectionClass is there for.

orientphoebus

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Suggest template modification for C# or Java
« Reply #2 on: December 12, 2005, 08:01:47 am »
Thanks for letting me know the #TYPE#, but I have more comments on related topic:

0. Trivial suggest: The Note explain about using #TYPE# is really too easy to skip when reading the help doc, maybe you should Bold the paragraph, in stead of Italic it.

1. #TYPE# is not working if I set this way:
1) set the attribute's Type to the collection's item type.
2) In the Attribute properties dialog, "Detail" tab, check "Attribute is a Collection", type in "IList<#TYPE#>" or "#TYPE#[]" in "Container Type:" Combo box.
The above method will generate code like:
Quote
private Class2 IList<#TYPE#> m_class2;

I think the above method is suppose to let us override the collection setting for specific attribute instead of using the Class level or the Global level settings. Am I using it right or it acctually means something else?

2. Collection setting in Class level won't work after sync the code:
1) First create 2 classes in class diagram, link them with "association" relationship, set the target is 1..*, generate the code. With Global setting using IList<#TYPE#>, we can get code like
Quote
private IList<Class2> m_class2;

2)Second, sync the code with the diagram, we can see the type of the attribute m_class2 is "IList<Class2>". (I hope the reverse engineering can set the type to Class2 still and set the detail to "Attribute is a Collection" checked and set the "Container Type:" to  IList<#TYPE#>)
After that, I want to change the attribute's type to Class2[], the only way I can do is modify the Type box to type in "Class2[]", that's really not smart. I hope I can set the class's collection to "#TYPE#[]" and it will automatically go through the attributes and find all the collection ones with no specific "Container Type" and overwrite them.

3. If what I understand the "Container Type:" correctly, it would be better to provide dropdown list which get the options from Class level and Global setting of the "collection class". Cause currently, the Combo box is always empty when you open the drop down.

4. This is a minor one. In "Code Generation Templates...", when I "Get Default Tempalte" and save, the left side "Templates" box "Modified" column is still marking that template "Yes", it shall change back to "No", otherwise it's hard to trace what changed.

5. For above 1~3 suggestion, if Sparx cannot modify EA to provide them very soon, my 1st script will still be usefull, although 2nd can be dumped anyways. It might be good to change my logic to use #TYPE# instead of hard-coding to find <> or [].
About, the generating comments part I tried several ways to sync with the code, it seems working fine. The purpose is just for if the field or property has no comments at all, it will generate one simple one, at leaset can tell something. If the commens is modifed by developer, sure it will lose when sync back, but it won't hurt anything. And if, just if, we can override the reverse part in add-ins, we can lay down a rule for our group to always keep that line. It's a customer self defined stuff for sure, if Sparx integrate this approach into your production, the comment part is not proper to be put as a standard logic.

6. For reverse engineering, an easy approach will be allowing user to override the function in add-ins, by doing these:
1) Provide event handlers for "pre" and "post" jobs of Reverse Engineering. Acctually, if these "pre" and "post" jobs are available for any existing menu tasks would provide user great flexibility and less coding when developing their add-ins.
2) Provide a data structure (or probably just open us the one Sparx is using internally) for accessing source code fields, properties or operations. Especially if it can be something like Java or .Net's Reflection classes and operations, it would be nice.
The above aproch step 2) might be hard to provide, if there is too much legacy design in existing EA Reverse Engineering. But I suppose step 1) should be relatively easy, and it will help the end user of the add-ins. Cause for now, I can build an add-in to provide menu items, but end users must remember to run them before or after existing menu functions.

Thanks
« Last Edit: December 12, 2005, 08:03:32 am by orientphoebus »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8066
  • Karma: +118/-20
    • View Profile
Re: Suggest template modification for C# or Java
« Reply #3 on: December 14, 2005, 03:19:13 pm »
1. The #TYPE# construct is only used from associations.  Not from attributes.  Changing that requires backwards compatibility issues we aren't wanting to create at the moment.  But that doesn't stop you from using it like that if you want to modify the templates.

2. No you're right, EA currently only supports collection classes for generation, not reverse engineering.  This is something we plan to address in the future.

3. The container type field is only free text at the moment and the default templates.  Basically at the moment it's only used for an array specifier.

4. This is the intended behaviour.  You got the text of the default template and saved it.  The modified column is reflecting that you have a saved copy of the template besides the default.  Try using the delete button instead.

5. I agree, your template changes are useful.  But there are a lot of people who are happy with how it works that they will cause problems for. That's why it's probably better to keep it as your custom templates.

Regarding the synch, as soon as the attribute comment is in the code, but still an empty note in the model it will duplicate the comment every time.

6. These notifications would be nice, but I don't think we can provide them at this time.