Project Plan for Java Metrics Counter Larry Dodds -------------------------------------------------------------------------- -------------------------------------------------------------------------- Inception phase: Complete a project that is capable of reading in Java files and outputting the metrics listed in the December 1997 Dr. Dobb's journal "Automated Metrics and Object-Oriented Development" by Jagdish Bansiya and Carl Davis. The project should also be capable of counting the number of violations of the Law of Demeter on a method body. -------------------------------------------------------------------------- -------------------------------------------------------------------------- Elaboration phase: Risks assessment: Requirements risks: - Use cases will be written to help detemine the scope of the requirements. - The use cases will be distributed to the sponsor and the actors involved in the use cases. Technological risks: - DemJava will be used as the implementation tool. It is a realtively new technology but has been well tested by several independent students. - I am using the .cd file for Java that already exists. This is a risk because the .cd file may not work in all cases. Skills risks: - I am new to Dem/Java so it will take longer to implement this project than if I were an experienced Dem/Java programer. However, using Dem/Java should provide an overall time efficiency over C++ and/or straight Java implementation. Political risks: - There are no political risks associated with this project. (other than those family risks dealing with spending too much time on the computer or not enough time on schoolwork therefore risking the tuition reimbursement) ;) Schedule risks: - I have two business trips and one vacation scheduled during the development timeframe. I am working on obtaining a laptop for development during the trip but this possibility is TBD. Because of the trips, I loose a week of development. ----------------------------------------------------------------------------- Use case analysis: Actors: - Java developer - Dem/Java developer Use cases (listed in order of priority): 1) Java developer wants metrics on a single *.java file. The metrics are as follows: -- Number of Methods (NOM) -- Class Interface Size (CIS) -- Number of Parameters (NPM) -- Number of Attributes (NOA) -- Number of Abstract (NAD) -- Number of Public Attributes (NPA) -- Data Access Metric (DAM) -- Operation Access Metric (OAM) -- Law of Demeter violations (LOD) FIXME: Do we need all the inherited class to calculated LOD? If so, this one must be added to UC 3 and we have to do something about UC2. In this case the system shall read in the .java file and calculate the metrics. 2) Dem/Java developer wants law of demeter violations on a method body. In this case the system shall provide a method that will execute on a method body. The method will need to take the adjacency of the class in which the method belongs and the arguments to method. The system will execute the method and return the number of violations of the Law of Demeter inside the method. It will do this by FIXME 3) Java developer wants metrics on a directory of *.java files. The metrics are listed as above and as follows: -- System Size on Classes (DSC) -- Number of hierarchies (NOH) -- Number of Independent Classes (NIC) -- Number of Single Inheritance (NSI) -- Number of Abstract Classess (NAC) -- Number of Leaf Classes (NLC) In this case the system shall prompt the user for the directory. The user will have to respond with the directory (the current directory is the default). The system shall parse all the *.java file in the directory and respond with the metrics in use case one for each file and then, after parsing all files, respond with the metric listed in this use case for the entire system. 4) Java developer wants metrics on *.java files in an input file. The metrics are the same as listed above. This is a variation on use case 3. In this case, the system will take a filename as an argument. The system will parse the file. The file will contain a list of the *.java files (absolute paths included). The system will read the files listed in the input file and act as described in use case 3. ----------------------------------------------------------------------------- Planning: This project will be done in four increments that are directly associated with the four use cases. Each use case increment includes design, implementation and testing. The milestones associated with the project are as follows (end dates unless otherwise specified): Planning completed: 11/15 Overall design: 11/16 Use case 1: 11/20 Use case 2: 11/20 Use case 3: 11/30 Use case 4: 12/2 Full, final testing starts: 12/2 Project due date: 12/4 (Drop-dead ship date is 12/6) This project will not calculate the following metrics as described in referenced article: -- Number of Polymorphic Methods (NOP) -- Class Size in Bytes (CSB) ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- Overall Design: The cd file is provided for this project. It is capable of parsing the Java language one compilation unit at a time. For the purposes of this cd file, a compilation unit is a java file that starts with the import statements and contains one class. The class can contain embedded classes. The visitors need for this increment will be: - Counting Visitor: Used to do simple increments - Display and PrintVisitors: Used for debug - LODCollector: Used to collect possible "legally" callable classes The strategies needed for this increment will be: - CompilationUnit->MethodDeclaration - CompilationUnit->MM_Public - CompilationUnit->FormalParameter - CompilationUnit->FieldDeclaration - CompilationUnit->MM_Abstract - CompilationUnit->FM_Public - CompilationUnit->FM_Private and FM_Protected - CompilationUnit->FormalParameter and MethodDeclaration (FIXME) The manner in which each metric will be calculated: - NOM: Count each MethodDeclaration - CIS: Count each MM_Public - NPM: Count each FormalParameter and divide by NOM - NOA: Count each FieldDeclaration - NAD: Count each MM_Abstract - NPA: Count each FM_Public - DAM: Count each FM_Private and FM_Protected and divide by NOA - OAM: Divide CIS/NOM - LOD: Go through each statement of each method looking for occurances where a method is called on a class that is not a data member of the class, a local data member of the method or an argument to the method. First I could collect the data members of the class into a container. Then I could add the arguments of the method to the container. Finally, when I find a method call inside a statement, I could compare the class being called with the classes in the container. If the class is not in the container, a violation is counted.