Book a Demo

Author Topic: No overwrite while generating sourcecode  (Read 4730 times)

casper

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
No overwrite while generating sourcecode
« on: November 15, 2005, 07:57:21 am »
Yesterday I modified the C# code generation template to my needs. I modified alot of templates so I can't recall all my changes. The problem is that when I generate source code, everything is fine. But after that when I generate sourcecode again, the new content doesn't get overwriten. I dont even get the messagebox that asks the question whether to overwrite. The fact is that the old content get's merged with the new content. THis starts at the namespace level. Since there's only one file header (with the comments). After some research I figured out that packageIsFirstNonEmpty is set to not T when I generate for a second time.
But still I'm just lost, I didn't change that much to mess it up that big.

My modified namespace declaration code:
Code: [Select]

$COMMENT="WARNING: THIS IS AN ADVANCED TEMPLATE"
$COMMENT="DO NOT MODIFY UNLESS YOU ARE AN"
$COMMENT="ADVANCED USER!"
%if packagePath == "" or genOptCSGenNamespace != "T" or packageHasGenClasses != "T"%
%endTemplate%

$name = %packagePath%
%if packageIsFirstNonEmpty != "T"%
$name = %packageName%
%endIf%
namespace %CONVERT_NAME($name, "Spaced", "Pascal Case")%


My first generation result:
Code: [Select]

///////////////////////////////////////////////////////////
//  Monkey.cs
//  Implementation of the Class Monkey
//  Generated by Enterprise Architect
//  Created on:      15-nov-2005 16:53:54
///////////////////////////////////////////////////////////




using System;


namespace DomeinModel.PIM.Opslag {
     public class Monkey {

           private string Name;
           private int Tails;



           public Monkey(){

           }

           ~Monkey(){

           }

     }//end Monkey

}//end namespace Opslag



My second generation result:
Code: [Select]

///////////////////////////////////////////////////////////
//  Monkey.cs
//  Implementation of the Class Monkey
//  Generated by Enterprise Architect
//  Created on:      15-nov-2005 16:51:31
///////////////////////////////////////////////////////////




using System;


namespace DomeinModel.PIM.Opslag {
     public class Monkey {

           private string Name;
           private int Tails;



           public Monkey(){

           }

           ~Monkey(){

           }

     }//end Monkey

}//end namespace Opslag


namespace DomeinModel {
     namespace PIM {
           namespace Opslag {
                 public class Monkey {

                       private string Name;
                       private int Tails;



                       public Monkey(){

                       }

                       ~Monkey(){

                       }

                 }//end Monkey

           }//end namespace Opslag

     }//end namespace PIM

}//end namespace Domein Model//end namespace Opslag



« Last Edit: November 15, 2005, 07:59:19 am by Casper »

thomaskilian

  • Guest
Re: No overwrite while generating sourcecode
« Reply #1 on: November 16, 2005, 02:20:19 am »
Check the Advanced button when generating. There's a radio button on top of the opening window.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: No overwrite while generating sourcecode
« Reply #2 on: November 20, 2005, 04:15:29 pm »
I think what is happening here is the one of your packages (Domain Model) has spaces in the name.  EA tries to find a namespace "Domain Model" and can't.  So it generates the corresponding code for it.

The CONVERT_NAME and related functions are all there for transformation templates, not code templates.  In code generation the name needs to match between the model and code.  If you want to do something like this you'll have to write a transformation to convert the names for you.