feat: add Java language support to call graph analyzer#144
Conversation
📝 WalkthroughWalkthroughAdds Java as a supported language by implementing a tree-sitter-based ChangesJava Language Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/analysis/analyzers/java.ts`:
- Around line 19-33: The static import handling in resolveModule is treating the
member name as part of the module path, so imports like com.example.Util.log are
being resolved as a non-existent Util/log.java instead of Util.java. Update the
resolution logic in resolveModule to detect static imports and strip the final
member segment before building relPath, while keeping the existing wildcard
import behavior unchanged; use the resolveModule helper in java.ts as the fix
location.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8d87884f-f78f-401e-9592-a26fedbd2f54
⛔ Files ignored due to path filters (1)
public/wasm/tree-sitter-java.wasmis excluded by!**/*.wasm
📒 Files selected for processing (5)
src/app/api/analyze/route.tssrc/components/ui/CodeWorkspace.tsxsrc/lib/analysis/analyzers/analyzers.test.tssrc/lib/analysis/analyzers/java.tssrc/lib/analysis/registry.ts
| function resolveModule( | ||
| fromFile: string, | ||
| specifier: string, | ||
| paths: Set<string>, | ||
| ): string | null { | ||
| if (specifier.endsWith(".*")) { | ||
| return null; | ||
| } | ||
| const relPath = specifier.replace(/\./g, "/") + ".java"; | ||
| for (const p of paths) { | ||
| if (p.endsWith(relPath)) { | ||
| return p; | ||
| } | ||
| } | ||
| return null; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== files ==\n'
git ls-files src/lib/analysis/analyzers/java.ts src/lib/analysis/analyzers/shared.ts
printf '\n== outline: java.ts ==\n'
ast-grep outline src/lib/analysis/analyzers/java.ts --view expanded || true
printf '\n== outline: shared.ts ==\n'
ast-grep outline src/lib/analysis/analyzers/shared.ts --view expanded || true
printf '\n== relevant snippets ==\n'
sed -n '1,220p' src/lib/analysis/analyzers/java.ts
printf '\n---- shared.ts ----\n'
sed -n '1,260p' src/lib/analysis/analyzers/shared.ts
printf '\n== search for java tree-sitter queries / constructor handling ==\n'
rg -n "constructor_declaration|object_creation|method_invocation|import_static|static_import|superclass|resolveModule|callQuery|funcDefQuery" src/lib/analysis/analyzers src/lib -g '!**/dist/**' -g '!**/build/**'Repository: DataDave-Dev/weftmap
Length of output: 16095
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '260,420p' src/lib/analysis/analyzers/shared.tsRepository: DataDave-Dev/weftmap
Length of output: 2136
Strip the member segment for static imports. In src/lib/analysis/analyzers/java.ts:19-33, import static com.example.Util.log; is resolved as com/example/Util/log.java, so the graph misses the actual Util.java import and log() only resolves when it is otherwise unique.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/lib/analysis/analyzers/java.ts` around lines 19 - 33, The static import
handling in resolveModule is treating the member name as part of the module
path, so imports like com.example.Util.log are being resolved as a non-existent
Util/log.java instead of Util.java. Update the resolution logic in resolveModule
to detect static imports and strip the final member segment before building
relPath, while keeping the existing wildcard import behavior unchanged; use the
resolveModule helper in java.ts as the fix location.
Pull Request: Implement Java Language Support
Context and Motivation
This PR extends the platform's multi-language parsing capability by introducing full support for Java. The implementation fits into the existing pluggable language architecture, enabling users to analyze Java codebases to generate interactive class hierarchy and method call graphs.
Technical Architecture and Implementation
1. Abstract Syntax Tree (AST) Parsing
tree-sitter-java.wasm) to generate concrete syntax trees for Java source files.method_declarationandconstructor_declarationnodes to identify executable entry points.method_invocationidentifier nodes.2. Dotted Package and Class Resolution
resolveModule) specifically tailored to Java's package structure (e.g. mappingimport com.example.service.MyService;to/com/example/service/MyService.java).3. Inheritance Mapping
superclassnodes, permitting mapping of class inheritance structures (extendsrelations).Verification and Testing
Automated Unit Testing
Added a new test suite covering the Java parser logic. It verifies:
All 81 project unit tests pass cleanly:
$ pnpm typecheck $ pnpm testManual Verification
Summary by CodeRabbit
New Features
Bug Fixes