コード例 #1
0
 /**
  * Eliminate cycles of method calls so that the related method tree is a tree, not a cycle (or
  * directed graph). If method A calls method B, B calls C, and C calls A, eliminate the final call
  * to prevent cycling.
  *
  * @param contents
  */
 public static void eliminateCycles(List<ClassContentsEntry> contents) {
   for (ClassContentsEntry entry : contents) {
     if (entry instanceof RelatableEntry) {
       MethodEntry current = (MethodEntry) entry;
       List<MethodEntry> set = new LinkedList<MethodEntry>();
       set.add(current);
       test(current, set);
     }
   }
 }
コード例 #2
0
 private static void test(MethodEntry current, List<MethodEntry> set) {
   Iterator<MethodEntry> it = current.myCalledMethods.iterator();
   while (it.hasNext()) {
     MethodEntry callee = it.next();
     if (set.contains(callee)) {
       callee.myCalledByMethods.remove(current);
       if (callee.myCalledByMethods.size() == 0) {
         callee.myRelatedMethod = false;
       }
       it.remove();
     } else {
       set.add(callee);
       test(callee, set);
     }
   }
 }