← Latest papers
💻 computer science

From Custom Logic to APIs: Understanding and Recommending API Replacement Refactorings

This paper presents AKIRA, a hybrid framework that combines pattern-deterministic heuristics with a refactoring-aware knowledge base to effectively identify and recommend API replacement refactorings, achieving significantly higher precision and recall than existing state-of-the-art tools.

Original authors: Bridget Nyirongo, Yanjie Jiang, Yuxia Zhang, Hui Liu

Published 2026-06-08
📖 4 min read☕ Coffee break read

Original authors: Bridget Nyirongo, Yanjie Jiang, Yuxia Zhang, Hui Liu

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a chef running a busy kitchen. Over time, you've developed a habit of chopping onions, mincing garlic, and squeezing lemons by hand for every single dish, even though you have a high-tech food processor sitting right next to you that can do it in seconds.

This is exactly what happens in software development. Programmers often write long, complicated blocks of code to do simple tasks (like checking if a number is zero or formatting a date) when a standard, pre-built "tool" (an API) already exists to do it perfectly. This is called API Replacement Refactoring. It's like swapping your hand-chopped onions for the food processor: the result tastes the same, but the kitchen is cleaner, faster, and easier to manage.

The problem? Finding these opportunities is hard. Existing tools are like a chef who only looks for specific, obvious mistakes (like forgetting to turn off the stove). They miss the subtle, complex recipes where a whole bunch of manual steps could be replaced by one simple button press.

This paper introduces a new system called AKIRA to solve this. Here is how it works, broken down simply:

1. The Investigation (The Empirical Study)

Before building a solution, the researchers went on a "fishing expedition." They looked at over 166,000 updates (commits) from six popular open-source software projects. They manually dug through 1,800 of these updates to find real-life examples where developers had successfully swapped their "hand-chopped" logic for "food processor" APIs.

They found 366 confirmed cases. They discovered that these replacements usually happen in two ways:

  • The Simple Swap: Changing a messy "if this, then that" sentence into a clean, standard command.
  • The Big Cleanup: Taking a 10-step process involving three different tools and condensing it into a single, powerful command.

They realized that old tools couldn't catch the "Big Cleanups" because they were too focused on the shape of the code rather than what the code was actually doing.

2. The Solution: AKIRA (The Hybrid Chef)

To fix this, the authors built AKIRA (Adaptive Knowledge Discovery and Retrieval). Think of AKIRA as a super-smart kitchen assistant that uses a two-tiered strategy:

  • Tier 1: The Rulebook (Deterministic Heuristics)
    This is the "fast lane." AKIRA has a list of 8 strict rules (like "If you see a loop checking for nulls, replace it with this specific tool"). This catches the easy, obvious cases instantly with high accuracy. It's like a spell-checker that catches typos immediately.

  • Tier 2: The Smart Detective (Adaptive Knowledge Discovery)
    When the Rulebook can't find a match, AKIRA switches to "Detective Mode." It doesn't just look at the code; it looks at the meaning.

    • It builds a massive Knowledge Graph (a giant map of how different tools relate to each other).
    • It uses an AI agent to read the code and understand the intent (e.g., "This code is trying to print an error message").
    • It searches its map to see if a standard tool exists that does the exact same thing, even if the code looks completely different.
    • Crucially, it adapts its sensitivity. If it's looking at test code, it's more lenient; if it's looking at critical business logic, it's stricter.

3. The Results (Did it work?)

The researchers tested AKIRA against other methods:

  • Old Tools: Only found about 20% of the opportunities (they missed most of the "Big Cleanups").
  • Generic AI (like a standard Chatbot): Found about 30-50%, but often gave bad advice or hallucinated tools.
  • AKIRA: Found 90% of the opportunities (Recall) and was 88% correct when it made a suggestion (Precision).

In a test against a different, external dataset, AKIRA improved the state-of-the-art results from 21% to 81%.

The Bottom Line

The paper concludes that you can't rely on just one method to find these refactoring opportunities. You need a hybrid approach: a strict rulebook for the easy stuff, combined with a smart, context-aware detective for the complex stuff.

By combining these two, AKIRA can automatically tell developers, "Hey, you're doing all that manual work for no reason. Just use this standard tool instead," making software cleaner, safer, and easier to maintain.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →