Note: to run use the "tee" command: make test | tee output That will put the output file into "output" -- Karl L. Java Metrics Counter Larry Dodds COM3360 Final Project Growth phases: This project grew up from several growth phases. These phases were outlined in the plan for the program. The plan states that there would be several use cases. Basically the plan was to first develop the metrics for single files. Then to read in multiple java files and continue doing metrics that required a system of classes. The plan also showed the possibility of multiple ways for the user to enter the files for analysis. Even though the project did proceed as planned, I did not have time to complete different types of input. I did not save a snapshot of each growth phase. I did, however, use RCS during development. If someone is interested in the growing pains of this project, they could "rlog" the source files (program.beh and lod.beh have RCS databases). -------------------------------------------------------------------------- Metric Implemented: -- Number of Methods (NOM) -- Class Interface Size (CIS) -- Operation Access Metric (OAM) -- Data Access Metric (DAM) -- Number of Parameters (NPM) -- Number of Attributes (NOA) -- Number of Public Attributes (NPA) -- Number of non-primitive data members (NAD) -- Number of Public Attributes (NPA) -- Depth of inheritance (DOI) -- Direct Class Coupling (DCC) -- Direct Attribute Coupling (DAC) -- System Size in Classes (SIZ) -- Number of hierarchies (NOH) -- Number of Independent Classes (NIC) -- Number of Single Inheritance (NSI) -- Number of Abstract Classess (NAC) -- Number of Leaf Classes (NLC) -- Average inheritance depth (ADI) -- Average inheritance width (AWI) -- Number of Children (NOC) -- Law of Demeter Type 1 violations (long chains) -- Law of Demeter Type 2 violations (calls to strangers) The metrics in the article that I did not implement are: -- Number of Multiple Inheritance (not used in Java) -- Number of Internal Classes (what are these?) -- Average Number of Ancestors (ancestors is the same as depth of inheritance when there is no multiple inheritance) -- Measure of functional abtraction (needed all parent classes) -- Measure of attribute abstraction (needed all parent classes -- Number of ancestors (same as DOI) -- Number of Inline Methods (not used in Java) -- Number polymorphinc methods (no "virtual" in java) -- Number of reference (not used in Java) -- Class size in bytes (needed parent classes) -- Class Entropy Complexity (unknown algorithim) -------------------------------------------------------------------------- Files turned in: - GNUmakefile: The standard makefile except for the addition of 2 beh files, an additional MY_SRC target, an increase in demjava memory, in increase in memory for the java execution, the removal of the input redirection and the removeal of the "depend" on the javac command line (really long compile times). - Program.beh: The bahavior for all metrics except for the LoD - lod.beh: What do you think - util.beh: utility behavior for collecting names of various objects. - EndsWith.java: Used to filter *.java files from the input directory - Program.cd: The standard cd file for Java except CompilationUnits (a non-parse list of CompilationUnit was added and a Children class (a listed of Idents) was added to the UnmodifiedClassDeclaration class. The children class was used to store all the names of class' children. -------------------------------------------------------------------------- Known bugs: -- DAM will be NaN if NOA is 0. -- The system cannot parse large amount of classes (>100) because of memory limitations. -- The system is fairly inefficient because the system level metrics simply call the class level metrics again while summing their output. This could be improved by saving the class output somewhere. -- A statement like "this.o.a()" will be counted as a type 1 LoD violation. It should not be unless o.a() is a violation. -- Type 2 violations are not detected in constructors. They are not defined as methods in the class dictionary. -------------------------------------------------------------------------- Future work: - Some of the known bugs could be easily fixed but I ran out of time. In order to fix the LoD violations, someone could figure out how to parse the java .class file for the parental information that is required. Solving the memory limitaiton problem could be harder. This might require persisting some object to disk. - The program output could be improved. The text is a little hard to read. - The efficiency of the program could be greatly improved. I currently run the same code multiple times when I want the same piece of information again. This is very wasteful. -------------------------------------------------------------------------- Test cases: The program is run with the standard, "make test". The can be run against any java code that is parsable according to the java.cd file. THis includes almost all of the code that is generated by demjava except the Parser and ASCII java files. When started, the program will ask for a directory to parse. The directory should contain the java files of interest. A "." will parse the java files in the current directory. I used the code in the smalltest directory for testing the LoD violations. THe code in the smalltest directory lists what should violations. I used the code in the gentest directory to test the rest of the metrics. The program will first parse each java file. It will skip any file that is not parsable. It will then generate metrics for each file independently. Then it will print out inheritance hierarchy. Finally, it will print out the system metrics.