一句话:通过挖掘 Stack Overflow 上的 API 误用场景、错误代码与补丁,生成报告帮助理解官方 API 使用指令并调试误用错误。
官方 API 文档中的自然语言使用指令描述契约、约束和指南,但开发者常因缺乏具体使用上下文、与协作 API 的间接关系以及相似 API 易混淆而难以理解。本文调查 Stack Overflow 上的 API 误用场景,提出文本挖掘方法发现众包误用场景,并从中抽取错误代码示例、补丁、相关 API 和易混淆 API,构建揭秘报告。作者在 Android API 文档和 Stack Overflow 讨论上应用该方法,为 3138 个类和 7471 个方法的 23,969 条使用指令抽取 159,116 个误用场景并生成报告。人工检查确认报告信息准确率高;14 名开发者对 8 个 API 误用相关错误场景的用户研究表明,相比只阅读原始指令,揭秘报告能更快、更准确地帮助理解和调试程序错误。
API usage directives in official API documentation describe the contracts, constraints and guidelines for using APIs in natural language. Through the investigation of API misuse scenarios on Stack Overflow, we identify three barriers that hinder the understanding of the API usage directives, i.e., lack of specific usage context, indirect relationships to cooperative APIs, and confusing APIs with subtle differences. To overcome these barriers, we develop a text mining approach to discover the crowdsourced API misuse scenarios on Stack Overflow and extract from these scenarios erroneous code examples and patches, as well as related API and confusing APIs to construct demystification reports to help developers understand the official API usage directives described in natural language. We apply our approach to API usage directives in official Android API documentation and android-tagged discussion threads on Stack Overflow. We extract 159,116 API misuse scenarios for 23,969 API usage directives of 3138 classes and 7471 methods, from which we generate the demystification reports. Our manual examination confirms that the extracted information in the generated demystification reports are of high accuracy. By a user study of 14 developers on 8 API-misuse related error scenarios, we show that our demystification reports help developer understand and debug API-misuse related program errors faster and more accurately, compared with reading only plain API usage-directive sentences.
DOI 原文 ·
@inproceedings{paperbot5602,
title = {Demystify official API usage directives with crowdsourced API misuse scenarios, erroneous code examples and patches},
author = {Xiaoxue Ren and Jiamou Sun and Zhenchang Xing and Xin Xia and Jianling Sun},
booktitle = {ICSE},
year = {2020},
doi = {10.1145/3377811.3380430}
}