FACER: An API usage-based code-example recommender for opportunistic reuse

Shamsa Abid, Shafay Shamail, Hamid Abdul Basit, Sarah Nadi

Research output: Contribution to journalArticlepeer-review


To save time, developers often search for code examples that implement their desired software features. Existing code search techniques typically focus on finding code snippets for a single given query, which means that developers need to perform a separate search for each desired functionality. In this paper, we propose FACER (F eature-driven A PI usage-based C ode E xamples R ecommender), a technique that avoids repeated searches through opportunistic reuse. Specifically, given the selected code snippet that matches the initial search query, FACER finds and suggests related code snippets that represent features that the developer may want to implement next. FACER first constructs a code fact repository by parsing the source code of open-source Java projects to obtain methods’ textual information, call graphs, and Application Programming Interface (API) usages. It then detects unique features by clustering methods based on similar API usages, where each cluster represents a feature or functionality. Finally, it detects frequently co-occurring features across projects using frequent pattern mining and recommends related methods from the mined patterns. To evaluate FACER, we run it on 120 Java Android apps from GitHub. We first manually validate that the detected method clusters represent methods with similar functionality. We then perform an automated evaluation to determine the best parameters (e.g., similarity threshold) for FACER. We recruit 10 professional developers along with 39 experienced students to judge FACER’s recommendation of related methods. Our results show that, on average, FACER’s recommendations are 80% precise. We also survey a total of 20 professional Android and Java developers to understand their code search and reuse experiences, and also to obtain their feedback on the usability and usefulness of FACER. The survey results show that 95% of our surveyed professional developers find the idea of related method recommendations useful during code reuse.

Original languageEnglish (US)
Article number110
JournalEmpirical Software Engineering
Issue number6
StatePublished - Nov 2021


  • API usage
  • Code clones
  • Code recommendation
  • Code search engine
  • Software features

ASJC Scopus subject areas

  • Software


Dive into the research topics of 'FACER: An API usage-based code-example recommender for opportunistic reuse'. Together they form a unique fingerprint.

Cite this