Book a Demo

Author Topic: Code Gen Templates questions...  (Read 3479 times)

GothDog

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Code Gen Templates questions...
« on: September 29, 2004, 10:52:19 am »
Hi -

I've been working on adding custom language generation for an XML-based language.  In the course of doing so, I've run into a couple of problems that I don't know how to get around.  Any insight would be greatly appreciated.

1) Ports: I read the previous post regarding lack of support for Ports in code templates.  Any ETA on when this will happen?

2) I would like all my classes to wind up in the same file.  Currently EA appears to be generating empty files for each class, even though there is no File template that matches the stereotypes of those classes.  (And I've not yet figured out how to make those classes show up in my main file.)

3) I'm having problems figuring out how and when a template based on LinkedAttribute actually gets called.  I have a class with an attribute which has an association to another class using that attribute as the target role of the association.  The attribute template gets called, but not the LinkedAttribute template.  Do I need to explicitly invoke the LinkedAttribute template (ie, via %list = etc..)?

4) When processing a link, how do I reference the macro for the class at the opposite end of the link?  I only see macros for the target, not the source.  And specifically, the language I'm trying to implement generation for uses nesting as a way of encoding relationships, so I need to be able to have the definition for one class be generated while I'm in the middle of generating an attribute and its links for another class, so I wind up with:

<myclass>
     <SomeAttr>
          <A relationship>
                 <AnotherClass>
                 </AnotherClass>
           </A relationship>
      </SomeAttr>
</myclass>

Any thoughts on how this is done?

Thanks in advance for any help you may have,

  --- GothDog ---

benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: Code Gen Templates questions...
« Reply #1 on: October 11, 2004, 08:03:06 pm »
Hi GothDog,

Sounds like you're treading some unchartered territory for the code template, which is good to see. Some responses below:

Quote
1) Ports: I read the previous post regarding lack of support for Ports in code templates.  Any ETA on when this will happen?

I won't nail a time frame, but we're aware of the limitation and will address it ASAP. Out of curiosity is this the thread you referred to ?
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.cgi?board=Automation;action=display;num=1094146636

It might contain some pointers on how you could call an addin (from the code templates) to generate the code for ports/parts.

Quote
2) I would like all my classes to wind up in the same file.  Currently EA appears to be generating empty files for each class, even though there is no File template that matches the stereotypes of those classes.  (And I've not yet figured out how to make those classes show up in my main file.)

1. Open the properties dockable window (Alt+1)
2. Fill in the filename field for each class.
3. Right-click package - choose Code Engineering | Generate Source Code
4. Select your particular classes (already targeting the same file path) and generate!

Simon wrote a related post recently (http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.cgi?board=general;action=display;num=1097491332), though you probably won't be able to use the "Synchronize" option. (We have been working on a generalized and customizable reverse engineering framework however, so this possibility is not far away either.)

Quote
3) I'm having problems figuring out how and when a template based on LinkedAttribute actually gets called.  I have a class with an attribute which has an association to another class using that attribute as the target role of the association.  The attribute template gets called, but not the LinkedAttribute template.  Do I need to explicitly invoke the LinkedAttribute template (ie, via %list = etc..)?

No, EA generates linked and non-linked attributes for a class in one go using the %list=Attribute .... %
If the attributes is via a connector it uses the LinkedAttribute template, otherwise it uses the Attribute template. Note: if both a direct class attribute and an association role are defined with the same name, the Attribute template is used.

Quote
4) When processing a link, how do I reference the macro for the class at the opposite end of the link?  I only see macros for the target, not the source.  And specifically, the language I'm trying to implement generation for uses nesting as a way of encoding relationships, so I need to be able to have the definition for one class be generated while I'm in the middle of generating an attribute and its links for another class, so I wind up with:
 
<myclass>
 <SomeAttr>
      <A relationship>
   <AnotherClass>
   </AnotherClass>
  </A relationship>
  </SomeAttr>
</myclass>
 
Any thoughts on how this is done?

Yes you definitely need the help of an add-in here ... because the templates don't have a facility for directly navigating to a related class and accessing it's properties.

So checkout my earlier posts on calling add-ins from templates. (eg http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.cgi?board=Automation;action=display;num=1094146636)You'll probably want to pass into your add-in functions things like packageGUID/classGUID. Load the package by guid, iterate to find the relevant class and you're away. If you've got any troubles with communication between the code-template/add-in, let me know.

A final note: the code templates are really geared toward generating code for conventional programming languages like java etc. This is not to say what you propose is impossible, but depending on the complexity of the XML, it may be better to use the add-in to do the lot. If you want to provide further details on what you're trying to achieve- we're always keen to hear how users need to work with EA. Then where practical we can provide generic enhancements that facilitate what you are doing :)

Regards,
Ben


mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Code Gen Templates questions...
« Reply #2 on: October 12, 2004, 02:38:38 am »
Which makes me wonder how difficult it might be to implement a Shlaer-Mellor OOA/OOD (Kennedy-Carter) type of model-to-code process in EA ...

Just daydreaming !