Learning from Examples to Find Fully Qualified Names of API Elements in Code Snippets
Developers often reuse code snippets from online forums, such as Stack Overflow, GitHub Gists to learn API usages of software frameworks or libraries. Those code snippets often have ambiguous undeclared external references. This makes it difficult to learn and use those APIs correctly. Reusing those code snippets to solve development tasks also requires resolving external references of those APIs. However, manually resolving fully qualified names (FQN) of API elements is a non-trivial task. In this paper, we propose a novel context-sensitive technique, COSTER, to resolve FQNs of API elements in those code snippets. The technique collects locally specific source code elements as well as globally related tokens as the context of FQNs, calculate association score, and build an occurrence likelihood dictionary. While inferring an API element, it collects the code context and ranks candidate FQNs from the dictionary by considering the association score of the tokens in the context, similarity between the context, and similarity between the API element. Evaluation with code examples collected from GitHub and Stack Overflow posts shows that our proposed technique improves precision and recall by 3-18% compared to existing state-of-the-art techniques. The proposed technique significantly reduces the training time compared to the StatType, a state-of-the-art technique, without sacrificing accuracy. Extensive analyses on results establish the facts of the robustness of the proposed technique.