
基于对象类型的API补全方法
*
唐泽,李传艺,葛季栋,骆斌
(计算机软件新技术国家重点实验室(南京大学),江苏南京210023)
通信作者:李传艺,E-mail:lcy@nju.edu.cn
摘 要:近年来,随着软件技术在各行各业、不同领域的应用不断扩展与深入,同时伴随着软件架构、服务计算等
技术的不断发展,软件行业涌现出了功能丰富且规模庞大的第三方API或库,软件开发者在实现软件功能的时候
也越来越依赖这些API.但学习这些API的使用是非常困难且耗时的,主要有两方面的原因:1)相关文档的缺失和
错误;2)相关API用法的示例代码较少.因此,研究自动的API补全方法以帮助开发人员在开发过程中正确且快速
的使用API,具有很大的应用价值.然而,现有API自动补全方案多数将待补全代码段看作纯文本,忽略了API所
属对象类型对预测API的影响.为此,探究了对象类型对补全API的作用,并且在对象状态图的启发下,设计了一
种使用API所属对象的类型作为特征的补全方法.具体而言,首先从API调用序列中先抽取同一对象类型的子序
列,利用深度学习模型编码出每个对象的状态,再利用对象状态生成整个方法块的状态表示进行补全.为了验证提
出的补全方法,在6个流行Java项目上进行了验证.实验结果证明,提出的考虑对象类型的API补全方法在预测
准确率上明显高于基线模型.
关键词:API补全;对象类型;插件
中图法分类号:TP311
中文引用格式:唐泽,李传艺,葛季栋,骆斌.基于对象类型的API补全方法.软件学报,2022,33(5):1736–1757.http://www.jos.org.
cn/1000-9825/6559.htm
英文引用格式:TangZ,LiCY,GeJD,LuoB.MethodofAPICompletionBasedonObjectType.RuanJianXueBao/Journalof
Software,2022,33(5):1736–1757(inChinese).http://www.jos.org.cn/1000-9825/6559.htm
Method of API Completion Based on Object Type
TANGZe,LIChuan-Yi,GEJi-Dong,LUOBin
(StateKeyLaboratoryforNovelSoftwareTechnology(NanjingUniversity),Nanjing210023,China)
Abstract:In recent years, with the continuous expansion and deepening of the application of software technology in various industries and
fields, as well as the development of software architecture, services computing, etc., the software industry has emerged with feature-rich
and large-scale third-party APIs or Libraries. Software developers are increasingly relying on these APIs when implementing software
functions. However, learning the usage of these APIs is very difficult and time-consuming. There are two main reasons: 1) missing or
wrong documents; 2) few sample codes for API usage. Therefore, designing automatic API completion methods to help developers use the
API correctly and quickly has great application value. However, most of the existing API automatic completion methods regard the code
segments to be completed as plain text, ignore the impact of the object types of APIs. Therefore, this study explores the role of the object
types in completing APIs. Besides, inspired by the object state diagram, an concrete API completion method is designed and implemented
that uses the types of the objects as a novel feature. Specifically, the subsequence of the same object type is first extracted from the API
call sequence and a deep learning model is used to encode the state of each object. Then, the objects’ states is used to generate a state
*
基金项目:国家自然科学基金(61802167,61972197,61802095);江苏省自然科学基金(BK20201250);华为-南京大学下一代程序设计创
新实验室合作协议子项目
本文由“领域软件工程”专题特约编辑汤恩义副教授、江贺教授、陈俊洁副教授、李必信教授以及唐滨副教授推荐.
收稿时间:2021-08-11;修改时间:2021-10-09;采用时间:2022-01-10;jos在线出版时间:2022-01-28
软件学报ISSN1000-9825,CODENRUXUEW E-mail:jos@iscas.ac.cn
Journal of Software,2022,33(5):1736−1757[doi:10.13328/j.cnki.jos.006559] http://www.jos.org.cn
©中国科学院软件研究所版权所有. Tel:+86-10-62562563
评论