Page 223 - 《软件学报》2021年第8期
P. 223

软件学报 ISSN 1000-9825, CODEN RUXUEW                                       E-mail: jos@iscas.ac.cn
                 Journal of Software,2021,32(8):2505−2521 [doi: 10.13328/j.cnki.jos.006082]   http://www.jos.org.cn
                 ©中国科学院软件研究所版权所有.                                                         Tel: +86-10-62562563


                                                                     ∗
                 检测 JavaScript 类的内聚耦合 Code Smell

                      1,2
                               1
                 黄子杰 ,   陈军华 ,   高建华   1
                 1
                 (上海师范大学  计算机科学与技术系,上海  200234)
                 2
                 (华东理工大学  计算机科学与工程系,上海  200237)
                 通讯作者:  高建华, E-mail: jhgao@shnu.edu.cn

                 摘   要: 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;内聚;耦合;类
                 中图法分类号: TP311


                 中文引用格式:  黄子杰,陈军华,高建华.检测 JavaScript 类的内聚耦合 Code Smell.软件学报,2021,32(8):2505−2521.  http://
                 www.jos.org.cn/1000-9825/6082.htm
                 英文引用格式: Huang ZJ, Chen JH, Gao JH. Detecting coupling and cohesion Code Smells of JavaScript classes. Ruan Jian Xue
                 Bao/Journal of Software, 2021,32(8):2505−2521 (in Chinese). http://www.jos.org.cn/1000-9825/6082.htm
                 Detecting Coupling and Cohesion Code Smells of JavaScript Classes

                                            1
                            1,2
                 HUANG Zi-Jie ,  CHEN Jun-Hua ,  GAO Jian-Hua 1
                 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.

                   ∗  基金项目:  国家自然科学基金(61672355)
                      Foundation item: National Natural Science Foundation of China (61672355)
                      收稿时间: 2018-10-31;  修改时间: 2019-10-28, 2020-04-25;  采用时间: 2020-05-12
   218   219   220   221   222   223   224   225   226   227   228