package fr.lifl.stc.stan.tools; import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.Method; //import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.ExternalMethodsAttribute; import org.apache.bcel.classfile.ExternalFieldsAttribute; import org.apache.bcel.classfile.ProofAttribute; import org.apache.bcel.classfile.LinkAttribute; public class ProofStats { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JavaClass []classes = new JavaClass[args.length]; int extMeth = 0; int extField = 0; int proof = 0; int noClasses = 0; int noMeth = 0; int sign = 0; int maxProof = 0; String maxProofMethod = ""; for (int i = 0; i < args.length; i++) { try { System.out.println("class "+i+": "+args[i]); classes[i] = (new ClassParser(args[i])).parse(); noClasses ++; JavaClass _class = classes[i]; Attribute[] orig = _class.getAttributes(); int j = 0; while (j < orig.length) { if (orig[j] instanceof ExternalMethodsAttribute) { ExternalMethodsAttribute linkAttr = (ExternalMethodsAttribute)orig[j]; extMeth += linkAttr.getLength(); } if (orig[j] instanceof ExternalFieldsAttribute) { ExternalFieldsAttribute linkAttr = (ExternalFieldsAttribute)orig[j]; extField += linkAttr.getLength(); } j++; } Method [] methods = _class.getMethods(); for (int k = 0; k < methods.length; k++) { noMeth++; //HTMLOutput.newMethod(methods[i].getName(), methods[i].getSignature()); orig = methods[k].getAttributes(); j = 0; while (j < orig.length) { if (orig[j] instanceof ProofAttribute) { //ProofAttribute linkAttr = (ProofAttribute)orig[j]; proof += orig[j].getLength(); if(orig[j].getLength() > maxProof){ maxProof = orig[j].getLength(); maxProofMethod = _class.getClassName()+"."+methods[k].getName(); } } if (orig[j] instanceof LinkAttribute) { //ProofAttribute linkAttr = (ProofAttribute)orig[j]; sign += orig[j].getLength(); } j++; } } } catch(java.io.IOException e){ e.printStackTrace(); } } System.out.println("No of classes = "+noClasses); System.out.println("No of methods = "+noMeth); System.out.println("Length of external methods = "+extMeth+" average = "+(extMeth/noClasses)); System.out.println("Length of external fields = "+extField+" average = "+(extField/noClasses)); System.out.println("Length of proof = "+proof+" average (per class) = "+(proof/noClasses)); System.out.println("Length of dico = "+sign+" average (per class) = "+(sign/noClasses)); System.out.println("Max proof = "+ maxProof+" in "+maxProofMethod); } }