National Key Research and Development Program of China (2016YFB1000801)
God class refers to a class that carries heavy tasks and responsibilities. The common feature of god class is that it contains a large number of attributes and methods, and has multiple dependencies with other classes in the system. God Class is a typical code smell, which has a negative impact on the development and maintenance of the software. In recent years, many studies have been devoted to discovering or refactoring the god class; however, the detection ability of existing methods is not strong, and the detection precision is not high enough. This paper proposes a god class detection approach based on graph model and isolation forest algorithm, which can be divided into two stages:the stage of the graph structure information analysis and the stage of intra-class measurement evaluation. In the stage of the graph structure information analysis, the inter-class method call graph and the intra-class structure graph are established respectively, and the isolation forest algorithm is used to reduce the detection range of god class. In the stage of the intra-class measurement evaluation, the impact of the scale and architecture of the project is taken into account, and the average value of the god class related measurement indicators in the project is used as the benchmark. We design an experiment to determine the scale factors, and use the product of the average value and the scale factors as the threshold for the detection to obetain the god class detection result. The experimental results on the code smell standard data set show that the method proposed in this article improves the precision and F1 value by 25.82% and 33.39% respectively compared with the existing god class detection methods, while maintaining a high level of recall at the same time.