Author Topic: CodeGen - Knowing if per Class or per Package  (Read 2861 times)

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
CodeGen - Knowing if per Class or per Package
« on: August 21, 2013, 10:11:32 pm »
Hi all,

Code generation (EA10) can generate one file per class, or one file per package (all containing classes into one file)

Now my question is: Can I from within the CodeGen template determine which approach is selected by the user?

The problem I'm trying to solve is related to imports section. The compiler won't accept not-used or repetetive identical import sections, so I define imports in a tagged value per class and per package. Thus I need to know whether to read the packageTag or classTag depending on the user's approach.

Or is there any other better way of achieving the same thing?

// Rolf
« Last Edit: August 21, 2013, 10:12:59 pm by Rolf_Lampa »
-- There's always a solution --

Helmut Ortmann

  • EA User
  • **
  • Posts: 953
  • Karma: +41/-1
    • View Profile
Re: CodeGen - Knowing if per Class or per Package
« Reply #1 on: August 22, 2013, 06:59:22 pm »
Hi Rolf,

as far as I know EA can only generate a file (C/C++ two files) for a class or an interface.

You may generate code from a package (recursive). This is only for convenience and in effect it generates for every class/interface a file with the name of the class/interface.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: CodeGen - Knowing if per Class or per Package
« Reply #2 on: August 22, 2013, 08:00:51 pm »
It's actually possible to generate several classes into one file (which I do all the time). It can be done by setting the same file name for all involved classes.

I only would like to be able to determine - from the perspective of the code template - what to put in the import section when doing the latter.
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7732
  • Karma: +103/-18
    • View Profile
Re: CodeGen - Knowing if per Class or per Package
« Reply #3 on: August 23, 2013, 05:14:56 pm »
You can use the import section / import templates to generate the imports. There is also a function macro in the language to remove duplicates.
Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: CodeGen - Knowing if per Class or per Package
« Reply #4 on: August 24, 2013, 01:39:38 am »
Quote
You can use the import section / import templates to generate the imports.

I tried this. But only the first class in a package returns its Imports when generationg for the whole package into the same output file.

Only if I generate one class at the time (1 class = 1 file) the Imports are retrived as they were defined individually per class.

This is how I did it: I in the File template I call
    %list="ImportSection" @separator="\n" @indent="\t"%

And in the ImportSection template I simpky return "%fileImports%"

What am I missing?

// Rolf
« Last Edit: August 24, 2013, 02:00:58 am by Rolf_Lampa »
-- There's always a solution --

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7732
  • Karma: +103/-18
    • View Profile
Re: CodeGen - Knowing if per Class or per Package
« Reply #5 on: August 26, 2013, 08:54:10 am »
ImportSection can't be listed. It is only a single thing.

In your file template just call
Code: [Select]
%ImportSection%
In your ImportSection template:
Code: [Select]
%list="ImportSection" @separator="\n" @indent="\t"%
Create an Import template to list over. The available fields are documented at http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/file_import_field_substitution.html


Eve

support@sparxsystems.com

RIL

  • EA User
  • **
  • Posts: 142
  • Karma: +3/-0
  • -- There's always a solution --
    • View Profile
Re: CodeGen - Knowing if per Class or per Package
« Reply #6 on: August 28, 2013, 02:39:26 am »
Thank you, I really should have come up with the idea myself and tried it. Well, now I will. :)

Thanks.

// Rolf
-- There's always a solution --