protected void writeVisitedMethod()

in test-discovery/src/com/intellij/rt/coverage/data/TestDiscoveryProtocolDataListener.java [105:144]


  protected void writeVisitedMethod(Map<Integer, boolean[]> classToVisitedMethods,
                                    Map<Integer, int[]> classToMethodNames,
                                    DataOutput os) throws IOException {
    TIntIntHashMap classToUsedMethods = new TIntIntHashMap();
    for (Map.Entry<Integer, boolean[]> o : classToVisitedMethods.entrySet()) {
      boolean[] used = o.getValue();
      int usedMethodsCount = 0;

      for (boolean anUsed : used) {
        if (anUsed) ++usedMethodsCount;
      }

      if (usedMethodsCount > 0) {
        classToUsedMethods.put(o.getKey(), usedMethodsCount);
      }
    }

    final int size = classToUsedMethods.size();
    CoverageIOUtil.writeINT(os, size);
    if (size == 0) return;
    final TIntIntIterator iterator = classToUsedMethods.iterator();
    while (iterator.hasNext()) {
      iterator.advance();
      final int className = iterator.key();
      int usedMethodsCount = iterator.value();

      CoverageIOUtil.writeINT(os, className);
      CoverageIOUtil.writeINT(os, usedMethodsCount);

      final int[] methodNames = classToMethodNames.get(className);
      final boolean[] used = classToVisitedMethods.get(className);

      for (int i = 0, len = used.length; i < len; ++i) {
        // we check usedMethodCount here since used can still be updated by other threads
        if (used[i] && usedMethodsCount-- > 0) {
          CoverageIOUtil.writeINT(os, methodNames[i]);
        }
      }
    }
  }