Skip to content

feat: add Java language support to call graph analyzer#144

Merged
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:feat/add-java-language-support
Jun 29, 2026
Merged

feat: add Java language support to call graph analyzer#144
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:feat/add-java-language-support

Conversation

@YasserYG8

@YasserYG8 YasserYG8 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

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

  • Leverages a new WebAssembly grammar parser (tree-sitter-java.wasm) to generate concrete syntax trees for Java source files.
  • Targets method_declaration and constructor_declaration nodes to identify executable entry points.
  • Identifies call targets by query-capturing method_invocation identifier nodes.

2. Dotted Package and Class Resolution

  • Implemented a dotted module path resolver (resolveModule) specifically tailored to Java's package structure (e.g. mapping import com.example.service.MyService; to /com/example/service/MyService.java).
  • Leverages cross-file query tracking to associate caller and callee nodes across independent Java source files.

3. Inheritance Mapping

  • Configured class base detection to extract parent identifiers from Java superclass nodes, permitting mapping of class inheritance structures (extends relations).

Verification and Testing

Automated Unit Testing

Added a new test suite covering the Java parser logic. It verifies:

  • Class node identification.
  • Resolution of extends-inheritance relationships.
  • Intra-file and cross-file method call resolution.

All 81 project unit tests pass cleanly:

$ pnpm typecheck
$ pnpm test

Manual Verification

  • Verified successful Java analysis through the frontend workspace using the newly added default Java demo template.

Summary by CodeRabbit

  • New Features

    • Added Java support throughout the app, including language selection, sample code, and project uploads.
    • Java files can now be analyzed and displayed in the same diagram flow as other supported languages.
    • Java analysis now captures class inheritance and function call relationships across files.
  • Bug Fixes

    • Improved language handling so Java is recognized correctly from file extensions and analysis routing.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Java as a supported language by implementing a tree-sitter-based javaAnalyzer with helpers for class inheritance and module resolution, registering it in the analyzer registry, extending the API route's extension map, and updating the CodeWorkspace UI to include Java in language selection, file filtering, and sample snippets.

Changes

Java Language Support

Layer / File(s) Summary
Java analyzer implementation and tests
src/lib/analysis/analyzers/java.ts, src/lib/analysis/analyzers/analyzers.test.ts
Adds classBases and resolveModule helpers, constructs a LangSpec with tree-sitter queries for functions, constructors, calls, imports, and class declarations, exports javaAnalyzer, and tests class nodes, extends edges, and cross-file call graph edges.
Registry and API route wiring
src/lib/analysis/registry.ts, src/app/api/analyze/route.ts
Registers javaAnalyzer in the analyzers array and adds java to the EXT map in the API route.
CodeWorkspace UI Java support
src/components/ui/CodeWorkspace.tsx
Adds java to LANGUAGES, EXT, PROJECT_EXTS, and SAMPLES so users can select Java, upload .java files, and see a Java code template.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • DataDave-Dev/weftmap#1: Establishes the /api/analyze route and CodeWorkspace multi-language architecture that this PR extends with Java support.

Poem

🐇 Hippity-hop, a new language appears,
.java files now have nothing to fear!
Tree-sitter parses each class and call,
extends and main — it handles them all.
The registry grows, the workspace too,
Java's in weftmap — hip hip, woohoo! ☕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR describes the change well, but it does not follow the required template sections or include the Type and Checklist items. Rewrite the description using the repo template: add 'Qué hace', select the change type, and complete the checklist, including the Java test item.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: adding Java language support to the call graph analyzer.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0eadbe6 and d913eed.

⛔ Files ignored due to path filters (1)
  • public/wasm/tree-sitter-java.wasm is excluded by !**/*.wasm
📒 Files selected for processing (5)
  • src/app/api/analyze/route.ts
  • src/components/ui/CodeWorkspace.tsx
  • src/lib/analysis/analyzers/analyzers.test.ts
  • src/lib/analysis/analyzers/java.ts
  • src/lib/analysis/registry.ts

Comment on lines +19 to +33
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.ts

Repository: 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.

@DataDave-Dev DataDave-Dev merged commit 52d35fb into DataDave-Dev:main Jun 29, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants