예제 #1
0
 /** Do additional work on an element to remove abstract methods that are reported by JProbe 3.0 */
 protected void removeAbstractMethods(ClassFile classFile, Element classNode) {
   MethodInfo[] methods = classFile.getMethods();
   Hashtable methodNodeList = getMethods(classNode);
   // assert xmlMethods.size() == methods.length()
   final int size = methods.length;
   for (int i = 0; i < size; i++) {
     MethodInfo method = methods[i];
     String methodSig = getMethodSignature(method);
     Element methodNode = (Element) methodNodeList.get(methodSig);
     if (methodNode != null && Utils.isAbstract(method.getAccessFlags())) {
       log("\tRemoving abstract method " + methodSig);
       classNode.removeChild(methodNode);
     }
   }
 }
예제 #2
0
  /** serialize a classfile into XML */
  protected void serializeClass(ClassFile classFile) {
    // the class already is reported so ignore it
    String fullclassname = classFile.getFullName();
    log("Looking for '" + fullclassname + "'");
    Element clazz = (Element) classMap.get(fullclassname);

    // ignore classes that are already reported, all the information is
    // already there.
    if (clazz != null) {
      log("Ignoring " + fullclassname);
      removeAbstractMethods(classFile, clazz);
      return;
    }

    // ignore interfaces files, there is no code in there to cover.
    if (Utils.isInterface(classFile.getAccess())) {
      return;
    }

    Vector methods = getFilteredMethods(classFile);
    // no need to process, there are no methods to add for this class.
    if (methods.size() == 0) {
      return;
    }

    String pkgname = classFile.getPackage();
    // System.out.println("Looking for package " + pkgname);
    Element pkgElem = (Element) pkgMap.get(pkgname);
    if (pkgElem == null) {
      pkgElem = createPackageElement(pkgname);
      report.getDocumentElement().appendChild(pkgElem);
      pkgMap.put(pkgname, pkgElem); // add the pkg to the map
    }
    // this is a brand new class, so we have to create a new node

    // create the class element
    Element classElem = createClassElement(classFile);
    pkgElem.appendChild(classElem);

    int total_lines = 0;
    int total_methods = 0;
    final int count = methods.size();
    for (int i = 0; i < count; i++) {
      // create the method element
      MethodInfo method = (MethodInfo) methods.elementAt(i);
      if (Utils.isAbstract(method.getAccessFlags())) {
        continue; // no need to report abstract methods
      }
      Element methodElem = createMethodElement(method);
      classElem.appendChild(methodElem);
      total_lines += method.getNumberOfLines();
      total_methods++;
    }
    // create the class cov.data element
    Element classData = getCovDataChild(classElem);
    classData.setAttribute("total_methods", String.valueOf(total_methods));
    classData.setAttribute("total_lines", String.valueOf(total_lines));

    // add itself to the node map
    classMap.put(fullclassname, classElem);
  }