Skip to content

codemetrics4j/codemetrics4j

Repository files navigation

codemetrics4j

Build Status GitHub issues Latest release Github All Releases

codemetrics4j (formerly JaSoMe) is a Java source code analyzer that calculates insightful quality metrics without requiring project compilation. This means you can analyze code even when dependencies are missing or code generation steps are incomplete.

Key Features:

  • Compilation-free analysis: Get metrics directly from your .java files, streamlining the analysis process.
  • File-level metrics: Provides granular metrics for classes and methods within each file.
  • Package-level insights: Receive aggregated metrics at the package level.
  • XML Output: Results are delivered in a structured XML format for easy integration.

Note

This project was originally forked from https://github.com/rodhilton/jasome. Due to the original repository being unmaintained, I've published my fork under the name codemetrics4j. This ensures easy access to the version containing the latest features and bug fixes. The previous version can still be found at https://github.com/kdunee/jasome.

Getting Started

Download the latest distribution and unzip, change into directory, then run:

bin/codemetrics4j <directory to analyze>

codemetrics4j will gather metrics and output them to the console. You can save the XML to a file using the --output <file> option.

Java compatibility

This project requires Java 17 or later to function correctly. Please ensure you have a compatible Java Runtime Environment (JRE) or Java Development Kit (JDK) installed.

Metrics

codemetrics4j is currently tracking the following metrics:

Metric Description Method Class Package Project
Raw Total Lines of Code (RTLOC) Actual lines of code, including comments ☑️
Total Lines of Code (TLOC) Lines of code, excluding comments/whitespace ☑️ ☑️ ☑️ ☑️
Number of Attributes (NF) Count of fields/attributes ☑️
Number of Static Attributes (NSF) Count of static attributes ☑️
Number of Public Attributes (NPF) Count of public attributes ☑️
Number of Methods (NM) Count of methods ☑️
Number of Static Methods (NSM) Count of static methods ☑️
Number of Public Methods (NPM) Count of public methods ☑️
Number of Classes (NOC) Count of classes in a package ☑️
Number of Parameters (NOP) Count of method parameters ☑️
Depth of Inheritance Tree (DIT) Maximum depth of a class's inheritance ☑️
Number of Overridden Methods (NORM) Methods a class overrides/implements ☑️
Number of Inherited Methods (NMI) Methods inherited from parent classes ☑️
Number of Methods Added to Inheritance (NMA) New methods defined in the class ☑️
Specialization Index (SIX) Measure of class specialization ☑️
Number of Methods Inherited Total (Mit) Total methods inherited ☑️
Number of Methods Inherited (Mi) Methods inherited but not overridden ☑️
Number of Methods Defined (Md) Methods defined within class ☑️
Number of Methods Overidden (Mo) Methods overriding inherited ones ☑️
Number of Methods (All) (Ma) All methods accessible on a class ☑️
Method Inheritance Factor (MIF) Ratio of inherited vs. total methods ☑️
Number of Public Methods Defined (PMd) Count of public defined methods ☑️
Number of Public Methods Inherited (PMi) Count of public inherited methods ☑️
Public Methods Ratio (PMR) Ratio of public methods ☑️
Number of Hidden Methods Defined (HMd) Count of non-public defined methods ☑️
Number of Hidden Methods Inherited (HMi) Count of non-public inherited methods ☑️
Method Hiding Factor (MHF) Ratio of hidden vs. defined methods ☑️
Number of Methods Inherited Ratio (NMIR) Ratio of inherited methods from total ☑️
Coupling Factor (CF) Measure of class's external dependencies ☑️
Polymorphism Factor (PF) Measure of method overriding ☑️
Number of Attributes Inherited Total (Ait) Total attributes inherited ☑️
Number of Attributes Inherited (Ai) Attributes inherited but not overridden ☑️
Number of Attributes Defined (Ad) Attributes defined in class ☑️
Number of Attributes Overidden (Ao) Attributes overriding inherited ones ☑️
Number of Attributes (All) (Aa) All attributes accessible on a class ☑️
Attribute Inheritance Factor (AIF) Ratio of inherited vs. total attributes ☑️
Number of Public Attributes Defined (Av) Count of public defined attributes ☑️
Number of Hidden Attributes Defined (Ah) Count of non-public defined attributes ☑️
Method Hiding Factor (AHF) Ratio of hidden vs. defined attributes ☑️
McCabe Cyclomatic Complexity (VG) Number of unique paths through code ☑️
Weighted Methods per Class (WMC) Sum of method complexities ☑️
Lack of Cohesion Methods (LCOM) Measure of class cohesiveness ☑️
Number of Interfaces (NOI) Count of interfaces/abstract classes ☑️
Afferent Coupling (Ca) Number of external classes depending on it ☑️
Efferent Coupling (Ce) Number of external classes it depends on ☑️
Instability (I) How likely a package is to change ☑️
Abstractness (A) Ratio of abstract classes in a package ☑️
Normalized Distance from Main Sequence (DMS) How far a package is from ideal ☑️
Nested Block Depth (NBD) Maximum nesting depth within a method ☑️
Number of Children (NOCh) Count of direct subclasses ☑️
Number of Parents (NOPa) Count of classes this class extends ☑️
Number of Descendants (NOD) Count of classes deriving from this class ☑️
Number of Ancestors (NOA) Count of classes this class derives from ☑️
Number of Links (NOL) Number of relations to other classes ☑️
Number of Dependants (NODa) Number of classes depending on this class ☑️
Number of Dependencies (NODe) Number of classes this class depends on ☑️
Class Category Relational Cohesion (CCRC) Measure of intra-package class cohesion ☑️
Number of Comparisons (NCOMP) Count of comparisons in a method ☑️
Number of Control Variables (NVAR) Count of control variables in a method ☑️
McClure’s Complexity Metric (MCLC) NCOMP + NVAR ☑️
Fan-out (Fout) Count of immediately subordinate methods ☑️
Fan-in (Fin) Count of methods invoking this method ☑️
Structural Complexity (Si) Fout^2 ☑️
Input/Output Variables (IOVars) NOP + 1 (0 for void return type) ☑️
Data Complexity (Di) IOVars / (Fout + 1) ☑️
System Complexity (Ci) Si + Di ☑️
Katz Centrality (KATZ) Katz centrality of a method ☑️
Class Total System Complexity (ClTCi) Sum of Ci for all methods in class ☑️
Class Relative System Complexity (ClRCi) Average Ci for all methods in class ☑️
Package Total System Complexity (PkgTCi) Sum of Ci across all classes in package ☑️
Package Relative System Complexity (PkgRCi) Average Ci across all classes in package ☑️

About

codemetrics4j (formerly JaSoMe) is a Java source code analyzer that calculates insightful quality metrics without requiring project compilation

Topics

Resources

License

Stars

Watchers

Forks

Contributors