☕ 🏠 - Semantic Java analysis via Eclipse JDT: compiler-accurate navigation, refactoring, find references,…
JavaLens: AI-First Code Analysis for Java
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
An MCP server providing 75 semantic analysis tools for Java, built directly on Eclipse JDT for compiler-accurate code understanding.
Built for AI Agents
JavaLens exists because **AI systems need compiler-accurate insights that reading source files cannot provide**. When an AI uses grep or Read to find usages of a method, it cannot distinguish:
- A method call from a method with the same name in an unrelated class
- A field read from a field write
- An interface implementation from an unrelated class
- A cast to a type from other references to that type
This leads to incorrect refactorings, missed usages, and incomplete understanding of code behavior.
Compiler-Accurate Analysis
JavaLens provides **compiler-accurate code analysis** through Eclipse JDT—the same engine that powers Eclipse IDE. Unlike text search, JDT understands:
- Type resolution across inheritance hierarchies
- Method overloading and overriding
- Generic type arguments
- Import resolution and classpath dependencies
- Java source from version 1.1 through **Java 25** (markdown Javadoc, module imports, compact source files, flexible constructor bodies)
- **Lombok**-generated members — a bundled agent makes @Data accessors and the like resolve, so code using them is not flagged as undefined
**Example:** Finding all places where UserService.save() is called:
| Approach | Result |
|----------|--------|
| grep "save(" | Returns 47 matches including orderService.save(), saveButton, comments |
| find_references | Returns exactly 12 calls to UserService.save() |
AI Training Bias Warning
> ⚠️ **Important for AI developers and users**
AI models may exhibit **trained bias toward native tools** (Grep, Read, LSP) over MCP server tools, even when semantic analysis provides better results. This happens because:
1. Training data contains extensive grep/text-search patterns
2. Native tools are "always available" in the model's experience
3. The model may not recognize when semantic analysis is superior
**To get the best results:**
Add guidance to your project instructions or system prompt (e.g., CLAUDE.md for Claude Code):
What is JavaLens?
JavaLens is an MCP server that gives AI assistants deep understanding of Java codebases. It provides semantic analysis, navigation, refactoring, and code intelligence tools that go beyond simple text search.
Why Not LSP?
Language Server Protocol was designed for IDE autocomplete and basic navigation—not for AI agent workflows that require deep semantic analysis.
| Capability | Native LSP | JavaLens |
|------------|------------|----------|
| Find all @Annotation usages | ❌ | ✅ |
| Find all new Type() instantiations | ❌ | ✅ |
| Find all casts to a type | ❌ | ✅ |
| Distinguish field reads from writes | ❌ | ✅ |
| Detect circular package dependencies | ❌ | ✅ |
| Calculate cyclomatic complexity | ❌ | ✅ |
| Find unused private methods | ❌ | ✅ |
| Detect possible null pointer bugs | ❌ | ✅ |
| Project-wide dead-code reachability from entry points | ❌ | ✅ |
| Find the tests that exercise a symbol, transitively | ❌ | ✅ |
JavaLens wraps **Eclipse JDT Core** directly via OSGi, providing:
- **Fine-grained reference types**: Find specifically casts, annotations, throws clauses, catch blocks, instanceof checks, method references, type arguments