Exemple #1
0
 /** Convert to a CovReport-like signature - <classname>.<method>(). */
 protected String getMethodSignature(ClassFile clazz, MethodInfo method) {
   StringBuffer buf = new StringBuffer(clazz.getFullName());
   buf.append(".");
   buf.append(method.getName());
   buf.append("()");
   return buf.toString();
 }
Exemple #2
0
 /** create an empty class element with its default cov.data (0) */
 protected Element createClassElement(ClassFile classFile) {
   // create the class element
   Element classElem = report.createElement("class");
   classElem.setAttribute("name", classFile.getName());
   // source file possibly does not exist in the bytecode
   if (null != classFile.getSourceFile()) {
     classElem.setAttribute("source", classFile.getSourceFile());
   }
   // create the cov.data elem
   Element classData = report.createElement("cov.data");
   classElem.appendChild(classData);
   // create the class cov.data element
   classData.setAttribute("calls", "0");
   classData.setAttribute("hit_methods", "0");
   classData.setAttribute("total_methods", "0");
   classData.setAttribute("hit_lines", "0");
   classData.setAttribute("total_lines", "0");
   return classElem;
 }
Exemple #3
0
 protected Vector getFilteredMethods(ClassFile classFile) {
   MethodInfo[] methodlist = classFile.getMethods();
   Vector methods = new Vector(methodlist.length);
   for (int i = 0; i < methodlist.length; i++) {
     MethodInfo method = methodlist[i];
     String signature = getMethodSignature(classFile, method);
     if (filters.accept(signature)) {
       methods.addElement(method);
       log("keeping " + signature);
     } else {
       //              log("discarding " + signature);
     }
   }
   return methods;
 }
Exemple #4
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);
     }
   }
 }
Exemple #5
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);
  }