一句话:提出 CodeKernel,用对象使用图与图核聚类选择更准确的 API 用法示例。
开发者常需要了解特定 API 的用法,但从代码库自动生成示例颇具挑战。现有方法多把源码简化为方法调用序列或特征向量,只建模部分信息,导致示例不准确。本文提出 CodeKernel,将源码片段表示为对象使用图(object usage graph),以保留方法调用与对象间结构关系;随后利用图核将图嵌入连续空间并进行聚类,再通过设计的排序指标从每个簇中选取代表性图作为代码示例。实验表明,CodeKernel 在示例准确性上优于 MUSE 与 eXoaDocs;一项涉及跨国公司 25 名开发者的用户研究也证实了其选择 API 用法示例的有效性。
Developers often want to find out how to use a certain API (e.g., FileReader.read in JDK library). API usage examples are very helpful in this regard. Over the years, many automated methods have been proposed to generate code examples by clustering and summarizing relevant code snippets extracted from a code corpus. These approaches simplify source code as method invocation sequences or feature vectors. Such simplifications only model partial aspects of the code and tend to yield inaccurate examples. We propose CodeKernel, a graph kernel based approach to the selection of API usage examples. Instead of approximating source code as method invocation sequences or feature vectors, CodeKernel represents source code as object usage graphs. Then, it clusters graphs by embedding them into a continuous space using a graph kernel. Finally, it outputs code examples by selecting a representative graph from each cluster using designed ranking metrics. Our empirical evaluation shows that CodeKernel selects more accurate code examples than the related work (MUSE and eXoaDocs). A user study involving 25 developers in a multinational company also confirms the usefulness of CodeKernel in selecting API usage examples.
DOI 原文 ·
@inproceedings{paperbot5316,
title = {CodeKernel: A Graph Kernel Based Approach to the Selection of API Usage Examples},
author = {Xiaodong Gu and Hongyu Zhang and Sunghun Kim},
booktitle = {ASE},
year = {2019},
doi = {10.1109/ase.2019.00061}
}