Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Maggie on April 20, 2012, 01:15:43 am

Title: find base classes
Post by: Maggie on April 20, 2012, 01:15:43 am
Hi
Within my addin I am trying to find all the base classes for a given class.

so far I have
Code: [Select]
           foreach (EA.Connector connector in element.Connectors)
            {
                 if (connector.Type == "Generalization")
                {
                    EA.Element clientElement = Repository.GetElementByID(connector.ClientID);
                }
            }
This gives me a list of all Generalization connectors, including classes that derive from the target class.
What I need is only the classes from which the target class in derived.

I would be grateful if someone could give me some pointers

Thanks

Maggie
Title: Re: find base classes
Post by: g.makulik on April 20, 2012, 01:49:05 am
Hi,

Check SupplierEnd, ClientEnd properties of the connectors (not sure which one actually) to filter out those connected on the 'right' end.

HTH
Günther
Title: Re: find base classes
Post by: stao on April 20, 2012, 03:12:00 am
you can se this method.

Code: [Select]
public static ArrayList getBaseClasses(EA.Element classToGet, ArrayList returnList)
{
      EA.Element actClass = classToGet;
      returnList.Add(actClass);
      foreach (EA.Element actBaseClass in actClass.BaseClasses)
      {
          returnList = getBaseClasses(actBaseClass, returnList);
      }
      return returnList;
}

to use this method:

Code: [Select]
ArrayList classAndParents = getBaseClasses(classToFindParents, new ArrayList());
Title: Re: find base classes
Post by: Maggie on April 20, 2012, 04:46:52 pm
Thanks!
Title: Re: find base classes
Post by: Geert Bellekens on April 23, 2012, 09:33:09 pm
My implementation is at https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/ElementWrapper.cs basically the same:
Code: [Select]
   /// EA provides a shortcut tot the superclasses through its
    /// element.BaseClasses
    /// Normally we would get those via the element.generalizations.general
    public HashSet<UML.Classes.Kernel.Class> superClasses {
      get {
        return new HashSet<UML.Classes.Kernel.Class>
          (this.model.factory.createElements(this.wrappedElement.BaseClasses)
          .Cast<UML.Classes.Kernel.Class>());
      }
      set { throw new NotImplementedException(); }
    }