Lightweight Syntactic API Usage Analysis with UCov
Gustave Monce, Thomas Couturou, Yasmine Hamdaoui, Thomas Degueule, Jean-Rémy Falleri
TL;DR
The paper introduces syntactic usage models (SUMs) and syntactic usage footprints (SUFs) as a lightweight, formal framework to capture the full spectrum of interactions allowed by an API and those actually exercised by client code. It presents UCov, a Java-based static-analysis tool that derives SUMs from library code and SUFs from client code to compute usage-coverage metrics, enabling library maintainers to identify under-tested or undocumented interactions and to assess the impact of API changes. Through an exploratory case study of jsoup, commons-cli, and spark, the authors demonstrate how SUMs/SUFs reveal design patterns, usage profiles, and practical gaps between documented examples, tests, and real-world usage. The work highlights implications for API design, testing, and evolution, and outlines future directions for broader language support and automated regression/testing based on complete SUMs.
Abstract
Designing an effective API is essential for library developers as it is the lens through which clients will judge its usability and benefits, as well as the main friction point when the library evolves. Despite its importance, defining the boundaries of an API is a challenging task, mainly due to the diverse mechanisms provided by programming languages that have non-trivial interplays. In this paper, we present a novel conceptual framework designed to assist library maintainers in understanding the interactions allowed by their APIs via the use of syntactic usage models. These customizable models enable library maintainers to improve their design ahead of release, reducing friction during evolution. The complementary syntactic usage footprints and coverage scores, inferred from client code using the API (e.g., documentation samples, tests, third-party clients), enable developers to understand in-the-wild uses of their APIs and to reflect on the adequacy of their tests and documentation. We implement these models for Java libraries in a new tool UCov and demonstrate its capabilities on three libraries exhibiting diverse styles of interaction: jsoup, commons-cli, and spark. Our exploratory case study shows that UCov provides valuable information regarding API design and fine-grained analysis of client code to identify under-tested and under-documented library code.
