Book a Demo

Author Topic: Searching for operations  (Read 4162 times)

RealAlex

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Searching for operations
« on: September 26, 2008, 12:31:55 am »
Hello,

I have a couple of class operations which I think are unused, Is it possible to search for references to that operation in sequence diagrams?

I've been looking to the database and automation and haven't been able to find anything. Is there an easy way to do this?

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Searching for operations
« Reply #1 on: October 02, 2008, 01:17:03 pm »
The following is a piece of code I've been playing with. I've cleaned it up a bit. The code will take any diagram but only processes Sequence diagrams.

It does the following
   Finds all classes on the Sequence diagram and for each class

      determines the method signature for all methods (messages) that
      are defined in the class. These are placed in a Map

      finds all declared messages that terminate at this class. Each
      message is looked up in the Map to see if it is defined on the class



Code: [Select]
  public void dumpDiagram(Diagram diagram) {
      if (diagram != null) {
         System.out.println(diagram.GetName() + "|" + diagram.GetType());
         if ("Sequence".equals(diagram.GetType())) {

            System.out.println("ExtendedStyle " + diagram.GetExtendedStyle());
            System.out.println("Style extended " + diagram.GetStyleEx());

            System.out.println("DiagramObjects");
            Collection<DiagramObject> diagramObjects = diagram
               .GetDiagramObjects();
            for (DiagramObject d : diagramObjects) {
               Element e = repository.GetElementByID(d.GetElementID());
               System.out
                  .println("----------------------------------------------------------");
               System.out.println(e.GetName() + "|" + e.GetType() + " "
                  + e.GetElementID());
               if ("Class".equals(e.GetType())) {
                  HashMap<String, String> methodMap = new HashMap<String, String>();

                  System.out.println("-------------------------------------");
                  System.out.println("Methods");
                  Collection<Method> methods = e.GetMethods();
                  for (Method m : methods) {
                     // Build the method signature
                     // Currently corresponds to ExtemdedStyle.OpParams = 1
                     // OpParams =
                     // 0 None
                     // 1 Show Type
                     // 2 Show All
                     // 3 Show Name only
                     StringBuilder sb = new StringBuilder(m.GetName());
                     sb.append("(");
                     Collection<Parameter> parameters = m.GetParameters();
                     boolean first = true;
                     for (Parameter p : parameters) {
                        if (!first) {
                           sb.append(", ");
                        }
                        sb.append(p.GetType());
                        first = false;
                     }
                     sb.append(")");
                     System.out.println("   " + sb);
                     methodMap.put(sb.toString(), " Not referenced");
                  }

                  System.out.println("-------------------------------------");
                  System.out.println("Connectors");
                  Collection<Connector> connectors = e.GetConnectors();
                  for (Connector c : connectors) {

                     if ("Sequence".equals(c.GetType())) {
                        if (c.GetSupplierID() == e.GetElementID()) {
                           if (methodMap.containsKey(c.GetName())) {
                              methodMap.put(c.GetName(), "");
                           } else {
                              methodMap.put(c.GetName(), " Not defined");
                           }
                           System.out.println("   " + c.GetType() + "|"
                              + c.GetName() + " " + c.GetClientID() + " "
                              + c.GetSupplierID());
                        }
                     }
                  }
                  System.out.println("-------------------------------------");
                  System.out.println("Usage");
                  Iterator<String> it = methodMap.keySet().iterator();
                  while (it.hasNext()) {
                     String s = it.next();
                     System.out.println("   Method " + s + (methodMap.get(s)));
                  }
               }
            }
         }
      }
   }

I know its a fairly big piece of code, but figuring out how to describe the process in plain language was getting silly.

Hope this helps.

Jim

RealAlex

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Searching for operations
« Reply #2 on: October 14, 2008, 05:52:02 pm »
Thanks, I will give it a try  8-)