Book a Demo

Author Topic: C# Indentation when generating code  (Read 8872 times)

SilverFox

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
C# Indentation when generating code
« on: July 05, 2004, 08:38:21 am »
It appears the default indenting style for C# generation is to place the opening brace on the same line as the declaration, statement, etc. Personally, I hate this style. VS.NET allows the user to specifiy which style of indenting is to be used. Is there a feature in EA that I am overlooking that will allow me to use a different indenting style?  If not, I would like to suggest that such a feature be included.

AdamHearn

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: C# Indentation when generating code
« Reply #1 on: July 05, 2004, 12:23:41 pm »
Well yes & no....

The feature you desire is provided by the Code Generation Templates. You must edit these to suit your own presentation style requirement. As with any layout, it's more likely to be done at a company level to match existing standards.

You should look at the "PI" macro. From memory, it affects 2 or 3 places however I cannot be sure as our templates are company bespoke and very neat (well they match exactly what we are obliged to produce!).

Barry_Pearce

  • EA User
  • **
  • Posts: 70
  • Karma: +0/-0
    • View Profile
Re: C# Indentation when generating code
« Reply #2 on: July 05, 2004, 02:31:01 pm »
Indeed, our standards also dictate ANSI style bracing and not K&R style.

We have changed the C++ codegen templates heavily to get the code generating to be correct and well formatted C++.

Basically you only need to add a couple of bits to the CGT to do what you want....

ClassBody - need to be altered for default constructor/destructor generation stuff.

OperationBody - Add \n before the { and that should be all you need to do :)

This may be clobbred by a trim or something...we have modified a lot - so if this doesnt work give me a shout.
« Last Edit: July 05, 2004, 02:32:04 pm by Barry_Pearce »

SilverFox

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: C# Indentation when generating code
« Reply #3 on: July 05, 2004, 02:58:03 pm »
Thanks for the suggestion(s). They sort of work for me. I'm still having trouble with generated 'properties'. I have modified the 'Attribute Declaration' template (which references property), including changing the comment text that gets generated. None of these changes are taking effect. Obviously the change for property has to occur elsewhere.

My Operation Body template now reads:
%if elemType == "Interface" or opTag:"delegate" == "true" or opAbstract == "T" or opTag:"extern" == "true"%
%PI=""%
;
%endTemplate%

\n{\n
$behaviour = %WRAP_COMMENT(opBehaviour, "40", "\t", "//")%
%if $behaviour != ""%
$behaviour\n\n
%endIf%
}

BTW: A destructor is always generated, even though I have that checkbox cleared (C# should not be using a destructor).

Do I have to reboot my machine each time I make a change to the template?  I have not been, but I also am not having much success ...

benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: C# Indentation when generating code
« Reply #4 on: July 05, 2004, 03:34:35 pm »
Hello SilverFox,

Regarding Property templates: try the Operation templates, stereotyped "Property".

Regarding Destructors: see the C# options for Finalizer and Dispose also.

Regarding Reboot : not required for template changes.

I hope that explains.

Regards,
Ben

SilverFox

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: C# Indentation when generating code
« Reply #5 on: July 05, 2004, 06:36:27 pm »
Here is the code template I currently have for 'Attribute' and 'Property' stereotype for C# generation. Note that by 'eyeball' inspection, 'Attribute' is the only template that references the word 'property':

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

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

%PI=" "%
%CONVERT_SCOPE(attScope)%
%attStatic=="T" ? "static" : ""%
%attConst=="T" ? "readonly" : ""%
%attType=="" ? "int" : value%
%if attCollection == "T" and attContainerType != ""%
%attContainerType%
%endIf%
%PI=""%
%attName%
%attInitial ? " = " value%

%if attStereotype == "property"%
\n{\n\t//read property\n\tget\n{;}\n\t//write property\n\tset\n{;}\n}
%endTemplate%

;

The additional '\n's before the '{' characters in the 'property' section are the only changes I have made.

I don't see the word 'property' anywhere in the 'Operation' templates...


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# Indentation when generating code
« Reply #6 on: July 05, 2004, 07:31:22 pm »
Hello SilverFox,

What Ben said was to look at the Operation template and there are stereotype overrides for property there.  (Specifically the Operation Declaration and Operation Body)

You need to modify the operation body template to change the brace location.  It looks like you're trying to do it from scratch in the attribute section and unless you have manually stereotyped an attribute to "property" it will never be executed.

Simon

Barry_Pearce

  • EA User
  • **
  • Posts: 70
  • Karma: +0/-0
    • View Profile
Re: C# Indentation when generating code
« Reply #7 on: July 06, 2004, 05:46:58 am »
Reboot not required,

However, if you are working on a multi-user system the changes are not automatically propogated - you will be OK but other users wont - reload currrent model wont help your colleagues as it doesnt reload the CGT (fault already logged with sparx) - you have to exit the application and reload it.

Hope this helps.