Graph-based Pattern-oriented, Context-sensitive Code Completion

Anh Tuan Nguyen, Tung Thanh Nguyen, Hoan Anh Nguyen, Ahmed Tamrawi, Hung Viet Nguyen, Jafar Al-Kofahi,
Tien N. Nguyen

Video Demo Downloads



Code completion, which is a crucial built-in support in many integrated development environments (IDEs), is useful for developers during their daily programming activities. Such a tool helps them to auto-complete detailed code during an editing session and enable them to focus more on their high-level algorithmic solutions. Aiming to improve developers' productivity in coding, a code completion tool should be able to predict developers' intention and to automatically fill in as much code as possible, while ensuring that the new code is consistent with the current code under editing. However, most of code completion tools are limited to filling in at the level of single method call or single object initialization. For example, Eclipse's code completion provides an alphabetical-order list of available methods for a variable under editing. To predict user's intention for better auto-completion, several approaches have been proposed to rank the recommended list of method calls. However, the volume of auto-completed code is limited to a single method call for a variable. To address that, other tools provide code templates for common programming constructs, e.g. for/while loops with iterator objects. Unfortunately, as a template is filled in, no context of currently edited code is considered..

GraPacc is designed with the goal of providing higher volume of code yet correctly considering the context of the code under editing. It is a novel code completion tool that is based on the frequent usages of APIs. When working with a library, developers often repeat the correct ways of using APIs, which are called API usage patterns. Each pattern is a valid combination of the usages of variables, method calls, control structures and the orders among them. The patterns can be re-used in different tasks, therefore, it will be helpful if a code completion tool can take advantage of usage patterns to auto-complete more code for developers.

Based on that principle, GraPacc first uses GrouMiner to mine and to build a database of frequent API usage patterns from the source code of any given opensource projects. GraPacc also allows users to define and to upload their own usage patterns. During an editing session, GraPacc extracts the context-sensitive features from the current code, e.g. the API elements on focus and the current editing cursor, and their relations to other code elements in order to rank the relevant API usage patterns and then to auto-complete the current code with proper elements for the chosen pattern.

The evaluation results show that, GraPacc can achieve up to 95% precision, 92% recall, and 93% f-score in code completion for automatic accuracy measurement. The result also shows that, with GraPacc, human subjects were more productive because GraPacc can help completing more code during programming. Their resulting code with GraPacc had higher quality and was less buggy.

 Sensitivity analysis (accuracy of tool with various values of its parameters δ, α, β, γ) can be found here.

 Video demo can be viewed here.

 GraPacc plugin can be downloaded here.