Book a Demo

Author Topic: How can I change the code file name extension?  (Read 2928 times)

wolfgang.uhr

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
How can I change the code file name extension?
« on: May 03, 2006, 01:25:29 pm »
Hello

I have written a small class and I have switched the language to c#. Then I have generated a code file using extension .cs. Then I have changed the language to java and the other language will be accepted, but not the other extension.

What can I do there?

Best regards
wolfgang

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How can I change the code file name extension?
« Reply #1 on: May 03, 2006, 02:21:19 pm »
Wolfgang,

I'm sure I've done this succesfully - usually after I forget to set the code generation language and accidentally generate Java code.

Try generating to an entirely new directory tree, and resetting all the options explicitly. If that does not work let me know and I'll see if I can run through the steps here and get you going again.

David
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How can I change the code file name extension?
« Reply #2 on: May 03, 2006, 02:51:46 pm »
OK Wolfgang,

I just tried this without any problem. I started with a small model (3 classes with an inheritance relationship, and an interface). They were set to Java when I built the model in EA.

I changed the language of all four elements to C#. I then generated the package. As expected the resulting code files have the .cs extension.

I then went back into EA and changed all the language settings back to Java. I generated the code, into another root directory (just to keep things sane) and got Java code in .java files.

My guess is that in the Generate Code dialog, you have not changed default Synchronize setting of "Synchronize model and code." If this is so, EA may be 'remembering' where you last generated the code (in the .cs files) for these elements, so that it can 'help' you keep everything synchronized. Since you have changed the language this could be interesting, but probably not productive.

Try changing the Synchronize setting to Overwrite code. This will , I believe, tell EA to forget where it put things last and just build new files. If that does not work, then try again but set a new root directory and also set the Synchronize option to "Overwrite code." That definitely worked for me.

HTH,
David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
Re: How can I change the code file name extension?
« Reply #3 on: May 03, 2006, 03:16:27 pm »
Hi guys,

Each class in an EA model is associated with a specific language, (it can be '<none>') and possibly a single file.  (C++ implementation files are known by the same base name as the header, with the implementation extension.)

Wolfgang, what you are experiencing is because when changing the language you are not also changing the filename.  EA automatically uses the appropriate extension for the current language in the file selection dialog, even if an existing extension is set.

Midnight, when you are generating the package and selecting the new root directory you are overriding the filenames of each file being generated.  As a result they are no longer going to be associated with the original file.

You may also want to try right clicking on a package and selecting 'Code Engineering' | 'Reset Options for this package' to reset all languages at once if you aren't already doing that.

If you want to generate a class to multiple languages, try investigating the model transformations.  This will allow you to create one model and generate it out to multiple target languages.  Both C# and Java have built in transformations.

I hope this helps.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How can I change the code file name extension?
« Reply #4 on: May 03, 2006, 03:34:33 pm »
Thanks Simon,

That's much clearer. I was going from memory, and how it has always worked for me. Given the situations where I've had to generate code by hand I have always done things at the package (or package tree) level, rather than for individual elements.

After all this time I still have not used the 'Reset' funtion, although it's been there all the time in plain sight. Once I got used to setting the language and target location I was always OK. Wolfgang and the rest of the world will probably want to remember this one, since most people (or at least people other than myself) are more likely to be synchronizing code with their models. I'll have to remember it too, since soon I'll be doing this a lot.

I did not bring up the subject of transformations. That really is the way to go, but I thought Wolfgang was fairly new to EA and this could be overwhelming.

As with so many other things, this is an area where the documentation could use a once-over. However, it does point in the correct direction and I know you guys have more important fish to fry these days.
No, you can't have it!

thomaskilian

  • Guest
Re: How can I change the code file name extension?
« Reply #5 on: May 04, 2006, 10:33:30 am »
Simon, I'd like to add a question: How can I change the default extension for a language defined by my own? EA happens to use the extension for the default language.

thomaskilian

  • Guest
Re: How can I change the code file name extension?
« Reply #6 on: May 04, 2006, 10:58:53 am »
Quote
Hello

I have written a small class and I have switched the language to c#. Then I have generated a code file using extension .cs. Then I have changed the language to java and the other language will be accepted, but not the other extension.

What can I do there?

Best regards
wolfgang


Wolfgang,
you should read about MDA. If you need two implementations (e.g. in Java and another in C++) you should create the PSM from your design model using transformation templates.

wolfgang.uhr

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: How can I change the code file name extension?
« Reply #7 on: May 04, 2006, 12:48:19 pm »
Quote
If you need two implementations (e.g. in Java and another in C++) you should create the PSM from your design model using transformation templates.


Thank you, you are right, that is the next step.

Wolfgang