| 摘要: |
| Code Smell是软件程序中存在不良设计和不良实现的征兆.正确地检测和识别Code Smell可以指导软件重构,提高软件的可用性和可靠性.通过Code Smell的度量指标,可以量化软件的设计问题.JavaScript已成为最常用的编程语言之一,类是JavaScript的设计模式,优秀类的设计体现为高内聚和低耦合.现有关于JavaScript内聚耦合的Code Smell研究均在微观的层面,即函数和语句上进行.它们可以提供程序实现的重构建议,但无法分析内聚耦合相关的软件系统设计问题.针对FE、DC和Blob这3种类的内聚耦合Code Smell,提出一种JavaScript类的内聚耦合Code Smell检测方法JS4C.该方法基于静态分析,同时适用于客户端和服务端程序.它通过遍历软件系统中所有的类,利用源程序的文本相似度特征和结构特征,识别Code Smell并检测其强度.在结构特征检测中,JS4C使用了经扩展的对象类型推断及非严格的耦合分散度度量法NSCDISP,有效地降低了解释型语言的静态分析过程中,类型信息缺失对检测产生的影响.实验通过对6个开源项目的分析表明,JS4C对内聚耦合设计问题有良好的检测效果. |
| 关键词: Code Smell JavaScript 内聚 耦合 类 |
| DOI:10.13328/j.cnki.jos.006082 |
| 分类号:TP311 |
| 基金项目:国家自然科学基金(61672355) |
|
| Detecting Coupling and Cohesion Code Smells of JavaScript Classes |
|
HUANG Zi-Jie1,2, CHEN Jun-Hua1, GAO Jian-Hua1
|
|
1.Department of Computer Science and Technology, Shanghai Normal University, Shanghai 200234, China;2.Department of Computer Science and Engineering, East China University of Science and Technology, Shanghai 200237, China
|
| Abstract: |
| Code Smells are symptoms of poor design and implementation choices. Detect and identify Code Smell precisely provide guidance on software refactoring, and lead to improvement of software usability and reliability. Design problems of software systems could be quantified through Code Smell metrics. JavaScript has become one of the most widely used programming languages, class is a design pattern of JavaScript, loose coupling and strong cohesion are characteristics of a well-designed class. Prior works measured coupling and cohesion Code Smells of JS programs in lower levels, i.e., function-wide and statement-wide, which were capable for providing refactoring suggestions about basic implementations, but not enough to identify design problems. This paper proposed JS4C, a method to detect coupling and cohesion Code Smells of JS classes including FE, DC and Blob. This method is an approach of static analysis works on both server and client-side applications, it iterates over every class in software system and takes advantage of source code textual patterns. While JS4C detects Code Smells, it also determines intensity for each of them. Missing type information in static analysis is reinforced by extended object type inference and non-strict coupling dispersion (NSCDISP) metric during structural analysis. Experiments made on 6 open-sourced projects indicate that JS4C can correctly detect coupling and cohesion design problems. |
| Key words: Code Smell JavaScript cohesion coupling class |