Mobile Development 21 min read

Design and Implementation of an Android Code Impact Analysis Tool Using Git Diff and ASM

This article presents a comprehensive approach to building an Android code impact analysis tool that leverages Git diff to locate modified lines, employs ASM-based class and method visitors to construct upward and downward call chains, extracts Javadoc and custom tags, and visualizes the results for developers and testers.

JD Retail Technology
JD Retail Technology
JD Retail Technology
Design and Implementation of an Android Code Impact Analysis Tool Using Git Diff and ASM

Background : Frequent code changes in large Android projects cause unpredictable side effects, making it difficult for developers and testers to assess impact and write precise test cases.

Solution Research : Two options were evaluated – IntelliJ IDEA's Call Hierarchy (upward only) and the open‑source static analysis framework WALA/SOOT. Neither fully met requirements, so a custom tool was planned.

Plan : The tool should automatically detect changed source lines via git diff , map them to classes and methods, generate both upward and downward call chains, and provide annotations for business logic.

Implementation Steps :

1. Identify modified file paths and line numbers using git diff --unified=0 --diff-filter=d HEAD~1 HEAD .

2. Locate the exact method containing each changed line by parsing compiled .class files with ASM.

3. Generate upward call chains by recursively tracing callers of the affected methods.

4. Generate downward call chains by scanning method bytecode, filtering out system APIs, and tracing callee methods.

5. Extract Javadoc comments and custom tags (e.g., @LogicIntroduce ) to provide business‑logic explanations.

6. Assemble the collected data, upload to a server, and render call‑chain diagrams.

Key Code Snippets :

String[] lines = out.toString().split("\\r?\\n");
Pattern pattern = Pattern.compile("^diff --git a/\\S+ b/(\\S+)");
Pattern pattern = Pattern.compile("^@@ -[0-9]+(,[0-9]+)? \\+([0-9]+)(,[0-9]+)? @@");
int changeLineStart = Integer.parseInt(m.group(2));
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { ... }
@Override
public void visitLineNumber(int line, Label start) { this.lineNumber = line; super.visitLineNumber(line, start); }
@Override
public void visitEnd() { ... }
public static final String[] SYSTEM_PACKAGES = {"java/*", "javax/*", "android/*", "androidx/*", "retrofit2/*", "com/airbnb/*", "org/apache/*"};
public static class JDDoclet { public static boolean start(RootDoc root) { JDJavaDocReader.root = root; return true; } }
public synchronized static RootDoc readDocs(String source, String classpath, String sourcepath) { ... }
/**
 * 打印方法(谁调用就会被打印),会打印两次
 * @LogicIntroduce 这个是自定义Tag  getPrintMethod方法
 */
public static void getPrintMethod() { System.out.println("我被调用了"); getPrintMethod2(); }

Tag Extraction : Custom tags like @LogicIntroduce are parsed from Javadoc to associate business descriptions with methods, enabling non‑developers to understand the impact of code changes.

Testing & Recommendation : The tool was validated on sample modifications, producing class/method impact lists and visual call‑chain diagrams. It is currently trialed in the recommendation team, with plans to improve scalability, node highlighting, and documentation completeness.

Conclusion : By integrating Git diff, ASM bytecode analysis, and Javadoc parsing, the solution provides automated, fine‑grained impact analysis for Android codebases, helping developers reduce risk and testers create more accurate test cases.

Androidcode analysisgitGradleASMcall chainJavadoc
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.