Book a Demo

Author Topic: Renaming via Transform  (Read 2880 times)

Max H

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
    • SafeCode Consulting
Renaming via Transform
« on: May 07, 2020, 03:01:38 am »
When I rename a class during transform, I would like the references to that class to be renamed, as well.  For example -- if I have an interface in my pim named "ActiveUser" and I transform to C#, I would like to follow the C# interface convention and rename it "IActiveUser".  This is simple enough.   The problem I have is that I would also like to transform all methods that take "ActiveUser" as a parameter, or classes that use it as an attribute type to also reference "IActiveUser" in their transformed incarnations.  I have not figured out how to make this part work.  Is there a macro for this?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Renaming via Transform
« Reply #1 on: May 07, 2020, 12:08:38 pm »
It's not trivial using only the transform templates. The problem is that when processing a parameter, you have the types guid but not its type, stereotype etc. You effectively don't have the information you need to make the decision.

What I would do, is write a small javascript add-in in your model to get that information for you.

I believe the signals package for Javascript add-ins includes a sample signal defining the signature required so a code generation template call. You'll need to duplicate that and add a reception for the name to your add-in.

In each of your templates, pass in the guid you want to get the type/name for into EXEC_ADD_IN.

The function can then use the rest of EA's API to calculate what you need and return the value. If you use Repository.GetElementByGuid every call you're probably going to be unhappy with the performance. If you add custom lists to your the start of your template you could use a second signal to initially make a list of elements that you're going to need, then query in bulk using Repository.GetElementSet, Repository.GetElementsByQuery, or Repository.SQLQuery.