计算机工程与应用 ›› 2020, Vol. 56 ›› Issue (10): 246-253.DOI: 10.3778/j.issn.1002-8331.1901-0222

• 工程与应用 • 上一篇    下一篇

挖掘软件源代码的代码注释自动生成方法

白杨,张丽萍   

  1. 内蒙古师范大学 计算机科学技术学院,呼和浩特 010022
  • 出版日期:2020-05-15 发布日期:2020-05-13

Mining Source Code for Automatic Comment Generation Method

BAI Yang, ZHANG Liping   

  1. College of Computer Science and Technology, Inner Mongolia Normal University, Hohhot 010022, China
  • Online:2020-05-15 Published:2020-05-13

摘要:

针对大多数软件代码注释数量少、质量低的问题,提出了一种自动生成代码注释的方法。利用Nicad检测出克隆代码,提取出这些代码以及相应的注释,对代码和注释分别进行精简优化,将注释与代码匹配映射,为代码自动生成注释。对5款软件中的代码注释进行手动验证并评估注释结果,实验结果发现28%的代码注释是良好的,同时将注释报告给5位专家,专家评估结果为两款软件的代码注释为良好。实验结果及用户调研表明,该方法对于自动生成代码注释是可行、有效的。

关键词: 克隆代码, 克隆检测, 代码注释, 注释优化, 自动生成注释

Abstract:

Low number of comments and low quality for most software code comments, a method for automatically generating code comments is proposed. Firstly, the clone code is detected by Nicad, and the code and corresponding comments are extracted, then the code and comments are separately optimized and streamlined. Finally, the comment is matched to the code mapping to generate a comment for the code. The code comments in five projects are manually verified in the experiment, and then results are evaluated as well. The experiment finds that 28% code comments are good. And the comments are reported to five experts with the feedback that the comments of two projects have favorable performance. Experimental results and user surveys show the feasibility and effectiveness of this method for automatically generating code comments.

Key words: clone code, clone detection, code comment, comment optimizing, automatically generating comment