一句话:提出 AstCC,用 AST 统计语言模型预测下一个语法单元,并给出其在修复、测试生成与模式挖掘中的应用。
IDE 中的代码补全能显著提升开发效率,但现有方法多局限于补全当前 token、下一个 token/语句或代码模式,补全粒度较粗。本文提出 AstCC:一种以 AST 为基础的统计语言模型,它从大规模代码语料中学习,推断出代表一个语法单元的下一个 AST 子树,再利用当前程序作用域中的具体变量填充该子树模板,从而实现“下一个语法单元”级别的补全。作者在真实代码上进行了实证评估:AstCC 能够在 33% 的情形下正确给出下一个语法单元,在 62% 的情形下正确答案出现在前五个候选中。论文还讨论了该方法在自动程序修复、自动测试用例生成以及句法模式挖掘等任务上的潜在应用。
Code completion is an important feature in an IDE to improve developers’ productivity. Existing code completion approaches focus on completing the current code token, next token or statement, or code pattern. We propose AstCC, a code completion approach to suggest the next syntactic unit via an AST-based statistical language model. AstCC learns from a large code corpus to derive the next AST subtree representing a syntactic unit, and then fills in the template with the concrete variables from the current program scope. Our empirical evaluation shows that AstCC can correctly suggest the next syntactic unit in 33% of the cases, and in 62% of the cases, it correctly suggests within five candidates. We will also explain the potential applications of AstCC in automated program repair, automated test case generation, and syntactic pattern mining.