Book a Demo

Author Topic: Creating custom "Class Base" template  (Read 7111 times)

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Creating custom "Class Base" template
« on: May 30, 2007, 04:10:41 pm »
Hello -

I am trying to create some code generation templates to allow me to generate Perl module files.  I am practically done, but I haven't figured out how to get the base class name.

According to a post I read on this list, I need to add a new ClassBase template so that I can iterate over it.  I have no idea how to get the links I need from the macros listed.

Any help would be appreciated.

Thanks!
-Sara

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #1 on: May 30, 2007, 06:42:13 pm »
In the Class Inherits template list over ClassBase and ClassInterface.

Code: [Select]
%list="ClassBase" @separator=", "%
%list="ClassInterface" @separator=", "%

There are then four templates you'll need to write.

Class Base and Class Interface correspond to the parents that don't exist in the model.  They'll both need to contain %classBaseName%.

Linked Class Base and Linked Class Interface correspond to the classes and interfaces directly linked with generalization and realization connectors.  They'll both need to contain %linkParentName%.

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #2 on: May 31, 2007, 12:11:49 pm »
Thanks for your reply.  I'm still not completely understanding this, though.

I created a new template of type "LinkedClassBase" with one line of code in it:

%linkParentName%

When I refer to %LinkedClassBase% from inside the Class Declaration template, it still returns a blank string.

What am I missing?

Thanks for your help.
-Sara

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #3 on: May 31, 2007, 12:59:52 pm »
You can't call the Linked Class Base template directly from the class templates (such as Class Declaration).  You need to list over the class bases as I mentioned in my previous post.  The short answer as to why, is that there isn't a currently active Class Base, so EA requires that you list over them.  %list="ClassBase" @separator=", "% will list over both Class Bases that aren't in the model and those you have created a generalization connector to.  (And so call your LinkedClassBase template).

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #4 on: May 31, 2007, 01:23:48 pm »
I'm sorry, but I am still finding this very confusing.

1 - Does the ClassBase template have to print both %baseClassName% AND %LinkedClassBase%?

2 - Do I need to do a "List" on the LinkedClassBase template within the Class Base template?

I tried to put the following 2 lines of code in ClassBase template and then list ClassBase in my ClassDeclaration, and got nothing again.

%baseClassName%
%LinkedClassBase%

It would really help me if you would tell me the lines of code I need within the ClassBase template.  I don't have to deal with interfaces, so I'm not worrying about them right now.

Thanks for your help.
-Sara

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #5 on: May 31, 2007, 03:48:20 pm »
Class Base
Code: [Select]
%classBaseName%
Linked Class Base
Code: [Select]
%linkParentName%
Class Inherits
Code: [Select]
$COMMENT="You can either put this in the Class Inherits template, and call that from your Class Declaration template,"
$COMMENT="or put it directly into the Class Declaration Template."
$COMMENT="This list iterates over each of the class bases available (linked or not) and places the specified separator between"
$COMMENT="their contents."
$base=%list="ClassBase" @separator=","%
$COMMENT="If I remember correctly Perl doesn't have multiple inheritance.  If that's so and you're worried that you may create"
$COMMENT="multiple inheritance in your model anyway then you need this condition."
$pos = %FIND($base, ",")%
%if $pos != "-1"%
$base = %LEFT($base, $pos)%
%endIf%
$base

That only covers inheritance.  The Class Interface and Linked Class Interface relationship is exactly the same.

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #6 on: June 01, 2007, 09:17:30 am »
Thanks for your reply.

For some reason, the Class Base and Linked Class Base templates are not getting executed for me.  I finally just put one line of plain text in each one, and they are not printing out.  In my Class Declaration template I have the following:

$base=%list="ClassBase" @separator=","%
$base

My templates show up in the list as "ClassBase_CB" and "LinkedClassBase_LB", respectively.  

Any thoughts?

Thanks
-Sara

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #7 on: June 01, 2007, 10:40:05 am »
Are you still in the middle of the $if% block?

I seem to remember that the failure on this sort of thing is silent.
No, you can't have it!

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #8 on: June 01, 2007, 11:37:49 am »
Good thought, but no.  Plain text lines before and after the list statement print out OK.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #9 on: June 03, 2007, 01:11:21 pm »
Quote
My templates show up in the list as "ClassBase_CB" and "LinkedClassBase_LB", respectively.

Then that's your problem.  The list that you have doesn't call those templates.  It calls the ones that show up in the list as "Class Base" and "Linked Class Base".

Additionally, there are two underscores in the name of your custom templates "ClassBase__CB" and "LinkedClassBase__LB".  So you will need to name them correctly if you want to list over them as custom templates.

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #10 on: June 04, 2007, 12:24:32 pm »
I'm going to have to give up on this due to time constraints.

Typing in the name as it shows on the list does not help.  By the way, there is no default "ClassBase" and "LinkedClassBase" in the list.  Also, I'm not clear if I should be iterating over LinkedClassBase manually, or where I should do that.

Anyway, the line of text in my Class Base template ("ClassBase__CB") is still not printing out, whether I list "ClassBase" or "ClassBase__CB".

Unless you have any other thoughts I'll just have to edit the generated files to contain the right line of code.  Is it possible that this is a bug?  I am using version 4.50.747 on Windows XP SP2.

-Sara


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #11 on: June 04, 2007, 03:53:40 pm »
I've tested with 4.51 build 747 and it works.

The template I used was

Code: [Select]
%list="ClassBase__CB" @separator="\n" @indent="// "%
%list="LinkedClassBase__CB" @separator="\n" @indent="// "%

saragwyn

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating custom "Class Base" templat
« Reply #12 on: June 05, 2007, 01:21:31 pm »
Ok, phew!

Thanks for all your help.