一句话:提出 MNire,用机器学习从方法体、接口和类名生成候选方法名,以检查名称与实现是否一致。
方法或 API 名称具有误导性会让开发者误解功能与用法,导致 API 误用和缺陷。MNire 用机器学习检查方法名与实现是否一致:先生成候选名,再与原名比较,足够相似即认为一致。其依据来自大规模方法名实证研究:方法名的许多 token 可从方法体、接口(参数与返回类型)和所在类名三个上下文中找到;即使未直接出现,也可利用上下文因高共现概率进行预测。核心思想是把名称生成视为对这三类上下文中程序实体名称 token 的抽象摘要。
Misleading names of the methods in a project or the APIs in a software library confuse developers about program functionality and API usages, leading to API misuses and defects. In this paper, we introduce MNire, a machine learning approach to check the consistency between the name of a given method and its implementation. MNire first generates a candidate name and compares the current name against it. If the two names are sufficiently similar, we consider the method as consistent. To generate the method name, we draw our ideas and intuition from an empirical study on the nature of method names in a large dataset. Our key finding is that high proportions of the tokens of method names can be found in the three contexts of a given method including its body, the interface (the method's parameter types and return type), and the enclosing class' name. Even when such tokens are not there, MNire uses the contexts to predict the tokens due to the high likelihoods of their co-occurrences. Our unique idea is to treat the name generation as an abstract summarization on the tokens collected from the names of the program entities in the three above contexts.
DOI 原文 ·
@inproceedings{paperbot5668,
title = {Suggesting natural method names to check name consistencies},
author = {Son Nguyen and Hung Phan and Trinh Le and Tien N. Nguyen},
booktitle = {ICSE},
year = {2020},
doi = {10.1145/3377811.3380926}
}