import java.io.*;
import java.util.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;
// import org.apache.bcel.*;

/**
 * Read a class file (specified on command line), and report the average length of its methods (in bytes).
 * Note that method length is measured in total number of bytes (including arguments), not just
 * number of instructions.
 *
 * <pre>java freq classfilename</pre>
 */
public class example{

  public static void main(String[] argv) throws IOException {

    JavaClass java_class = new ClassParser(argv[0]).parse();  // May throw IOException
    Method[] methods = java_class.getMethods();
    int size = 0;
    for (int j = 0; j < methods.length; j++) {
	Code code = methods[j].getCode();
        if (code != null) {
	    byte bs[] = code.getCode();  // unfortunate overloading of methods names!
	    size += bs.length;
	}
    }
    System.out.println("Average method size = " + size/methods.length);
  }
}    
