Sign inSign up

sodlinken/jcodeindexer

By sodlinken

Updated 29 days ago

Java AST-level code indexer with SQLite storage, exposed as an MCP server for AI coding assistants.

Image
Languages & frameworks
Machine learning & AI
Developer tools
0

1.8K

sodlinken/jcodeindexer repository overview

Java Code Indexer

JVM AST-level code indexer (Java/Kotlin/Scala) with SQLite storage, exposed as an MCP server for AI coding assistants.

中文 | English

Java Code Indexer


Why

AI coding assistants exploring unfamiliar JVM projects today:

TaskWithout Java Code IndexerWith Java Code Indexer
Find where UserService is definedgrep across 100+ files (~15k tokens)find_symbol("UserService") (~200 tokens)
Understand all callers of saveOrder()Read files one by one (~8k tokens)get_call_graph("saveOrder", "callers") (~500 tokens)
Find a config value in YAML/propertiesfind + cat multiple config files (~5k tokens)search_config("spring.datasource.url") (~200 tokens)
Locate all dependenciesOpen pom.xml + transitive (~3k tokens)find_dependencies("spring-boot-starter") (~300 tokens)
Find all @RestController classesSearch through entire codebase (~8k tokens)find_by_annotation("RestController") (~200 tokens)
Understand interface implementationsRead multiple files (~5k tokens)find_implementations("UserService") (~300 tokens)
Find which controller handles /api/users/{id}Search through all controllers (~5k tokens)find_route("GET", "/api/users/123") (~200 tokens)
Understand Bean injection relationshipsRead multiple @Autowired fields (~3k tokens)get_bean_dependencies("OrderService") (~300 tokens)
Find related test classesSearch test directories (~2k tokens)find_related_tests("UserService") (~200 tokens)

Features

Multi-Language Support
LanguageStatusParser
Java✅ Full supportJavaParser AST
Kotlin✅ Full supportKotlinParserAdapter (regex)
Scala✅ Full supportScalaParserAdapter (regex)
Annotation Recognition

Supports 30+ annotations across major frameworks:

FrameworkAnnotations
Spring Boot@RestController, @Service, @Repository, @Component
Spring MVC@RequestMapping, @GetMapping, @PostMapping, @DeleteMapping
JPA@Entity, @Table, @Column, @Id, @GeneratedValue
Lombok@Data, @Builder, @Getter, @Setter, @NoArgsConstructor
Validation@NotNull, @Size, @Min, @Max, @Email
MyBatis@Mapper, @Select, @Insert, @Update, @Delete
Swagger@Api, @ApiOperation, @ApiParam
Security@EnableWebSecurity, @PreAuthorize, @Secured
Cache@EnableCaching, @Cacheable, @CacheEvict, @CachePut
Async@EnableAsync, @Async
Scheduling@EnableScheduling, @Scheduled
Spring Ecosystem Support (v1.6.0+)
FeatureDescription
API Route MappingAutomatically extract @RequestMapping/@GetMapping etc., build URL → Controller method mapping
Type HierarchyQuery complete class inheritance chains (parent/child relationships)
Bean DependenciesExtract @Autowired/@Inject injection relationships
Test Coverage MappingAuto-associate test classes with source classes (e.g., UserServiceTestUserService)

Installation

Requires Java 21+ (JRE or JDK). Docker and Native Image options bundle the runtime.

Option 1: Download from GitHub Releases (recommended)

# Fat JAR (all platforms)
curl -LO https://github.com/Lincoln-cn/JCodeIndexer/releases/latest/download/java-code-indexer-1.5.1.jar

# Native Image (Linux)
curl -LO https://github.com/Lincoln-cn/JCodeIndexer/releases/latest/download/java-code-indexer-1.5.1-linux-amd64.tar.gz

# Native Image (macOS)
curl -LO https://github.com/Lincoln-cn/JCodeIndexer/releases/latest/download/java-code-indexer-1.5.1-darwin-arm64.tar.gz

# Native Image (Windows)
curl -LO https://github.com/Lincoln-cn/JCodeIndexer/releases/latest/download/java-code-indexer-1.5.1-windows-amd64.zip

Option 2: Build from source (requires Java 21+ and Maven 3.8+)

git clone https://github.com/Lincoln-cn/JCodeIndexer.git
cd JCodeIndexer
mvn package -q -DskipTests
# output: target/java-code-indexer-*-shaded.jar

Option 3: Docker

docker pull sodlinken/jcodeindexer:latest

Quickstart

# 1. Index your JVM project (Java/Kotlin/Scala)
java -jar java-code-indexer-1.5.1.jar --project-root /path/to/your/project --index

# 2. Start the MCP server (stdio, for Claude Code / Qwen Code / Cursor)
java -jar java-code-indexer-1.5.1.jar --project-root /path/to/your/project

That's it. Your AI assistant can now query your codebase structure instead of reading files.


CLI Reference

java -jar java-code-indexer-VERSION.jar [options]

Options:
  --project-root <path>   JVM project root directory (default: current dir)
  --data-dir <path>       Index data directory (default: .jindexer)
  --init                  Initialize database schema only
  --index                 Run indexer (extract symbols/references/calls)
  --status                Show index statistics
  --search <query>        Search directly (no MCP server needed)
  --export <file>         Export index data to JSON file
  --version               Show version number
  --help, -h              Show help

No flags → start MCP server over stdio.

MCP Tools (26 tools)

When running as an MCP server, Java Code Indexer exposes these tools:

ToolDescription
find_symbolFind symbols (class/method/field) by name, * wildcard supported
find_referencesFind all reference locations for a symbol
get_call_graphMethod call graph — callers, callees, or both
search_codeSearch symbol names and code content (FTS5 full-text)
get_file_infoFile details: symbols, code chunks, call relationships
search_configSearch config files (YAML / Properties / .env)
find_dependenciesSearch project dependencies (Maven / Gradle)
healthServer health check with status and statistics
list_projectsList indexed projects (multi-project mode only)
search_all_projectsSearch across all projects (multi-project mode)
find_implementationsFind all classes implementing an interface
find_overridesFind all method overrides in subclasses
find_usagesFind all usages of a field/variable
find_annotationsFind all annotations on a symbol
find_by_annotationFind symbols with a specific annotation
find_api_routesFind API route mappings (URL → Controller method)
find_routeFind Controller method by HTTP method + URL path
get_type_hierarchyGet complete class inheritance hierarchy
get_bean_dependenciesFind Bean's dependencies (what it depends on)
get_bean_dependentsFind Beans that depend on this Bean
find_related_testsFind test classes related to source code
reindexManually trigger incremental re-indexing
index_statusView index status and watcher state
search_symbolsEnhanced symbol search with kind/annotation filters
get_code_metricsGet code metrics (lines, methods, complexity)

Configuration

Create .jindexer/config.yaml in your project root (optional):

# Data directory
data_dir: .jindexer

# Indexing settings
indexing:
  threads: 4                    # Indexing thread count
  extract_javadoc: false        # Extract Javadoc comments
  follow_symlinks: false        # Follow symbolic links
  max_file_size_kb: 512         # Max file size (KB)

# Storage
storage:
  db_name: index.db             # Database file name

# Logging
log:
  level: INFO                   # Log level (DEBUG/INFO/WARN/ERROR)
  verbose: false                # Verbose output

# File watching (auto-reindex on file changes)
watch:
  enabled: true                 # Enable background file watcher
  interval: 5                   # Check interval (seconds)
  exclude:                      # Directories to exclude
    - "**/target/**"
    - "**/build/**"
    - "**/node_modules/**"
    - "**/.git/**"

# Multi-project mode
projects:
  - name: backend
    root: /path/to/backend
  - name: frontend
    root: /path/to/frontend
Environment Variables
VariableDescriptionDefault
INDEXER_THREADSIndexing thread count4
INDEXER_LOG_LEVELLog levelINFO

Priority: CLI flags → environment variables → config file → defaults.


AI Assistant Integration

Claude Code / Cursor / Qwen Code

Add to your MCP configuration:

{
  "mcpServers": {
    "java-code-indexer": {
      "command": "java",
      "args": ["-jar", "/path/to/java-code-indexer-1.5.1.jar", "--project-root", "/path/to/project"]
    }
  }
}
Docker Integration
{
  "mcpServers": {
    "java-code-indexer": {
      "command": "docker",
      "args": ["run", "--rm", "-i", "-v", "/path/to/project:/project", "sodlinken/jcodeindexer:latest", "--project-root", "/project"]
    }
  }
}

How It Works

┌──────────────┐     MCP (stdio)     ┌──────────────────────┐
│  AI Assistant │ ◄─────────────────► │  Java Code Indexer   │
│  (Qwen/Claude)│    JSON-RPC         │                      │
└──────────────┘                     │  ┌────────────────┐  │
                                     │  │ Parsers:       │  │
                                     │  │  JavaParser    │  │
                                     │  │  KotlinParser  │  │
                                     │  │  ScalaParser   │  │
                                     │  └───────┬────────┘  │
                                     │          ▼            │
                                     │  ┌────────────────┐  │
                                     │  │  SQLite (WAL)  │  │
                                     │  │  symbols       │  │
                                     │  │  references    │  │
                                     │  │  call_graphs   │  │
                                     │  │  annotations   │  │
                                     │  │  configs       │  │
                                     │  │  dependencies  │  │
                                     │  └────────────────┘  │
                                     └──────────────────────┘
Indexing Strategy
  1. Walk JVM source files (Java/Kotlin/Scala) via filesystem traversal
  2. SHA-1 content hash skips unchanged files (incremental)
  3. Parsers extract symbols, references, call relationships, and annotations
  4. POM/Gradle parsers extract dependency information
  5. Config parsers extract YAML/Properties/.env entries
  6. All data upserted into embedded SQLite (WAL mode)
  7. FTS5 full-text search indexes auto-synced via triggers
Database Schema

Eleven core tables:

  • symbols — classes, methods, fields with location and signatures
  • references — symbol usage locations across the codebase
  • calls — method call relationships (caller → callee)
  • annotations — symbol annotations with attributes
  • chunks — code slices at class/method granularity
  • file_meta — SHA-1 hashes for incremental indexing
  • config_entries — YAML/Properties/.env key-value pairs
  • dependencies — Maven/Gradle dependency declarations
  • api_routes — Spring Boot API route mappings (URL → Controller)
  • bean_dependencies — Spring Bean injection relationships
  • test_mappings — Test class to source class associations

Plus FTS5 full-text search tables (symbols_fts, chunks_fts) with auto-sync triggers.


Architecture

src/main/java/com/sodlinken/jindexer/
├── cli/          # CLI entry point
├── mcp/          # MCP server (JSON-RPC over stdio)
├── config/       # YAML config loader
├── storage/      # SQLite schema & StorageService (including FTS5)
├── indexer/      # Incremental indexing engine
├── parser/       # Java, Kotlin, Scala, POM, Gradle, Config parsers
├── chunker/      # Code chunking (class/method slices)
├── search/       # Structured search (FTS5 full-text)
├── model/        # Data models (Symbol, Call, Chunk, Annotation, etc.)
└── util/         # SHA-1 hashing utility

Distribution

GitHub Release

Release workflow is automated via GitHub Actions:

ArtifactDescription
java-code-indexer-VERSION.jarFat JAR, requires Java 21+
java-code-indexer-VERSION-linux-amd64.tar.gzLinux amd64 Native Image
java-code-indexer-VERSION-darwin-arm64.tar.gzmacOS arm64 Native Image
java-code-indexer-VERSION-windows-amd64.zipWindows amd64 Native Image
docker-image-VERSION.tar.gzDocker offline image
checksums-VERSION.sha256SHA-256 checksums

Development

# Clone and build
git clone https://github.com/Lincoln-cn/JCodeIndexer.git
cd JCodeIndexer
mvn package -q -DskipTests

# Run tests
mvn test

# Index this project itself
java -jar target/java-code-indexer-*-shaded.jar --project-root . --index

# Start MCP server
java -jar target/java-code-indexer-*-shaded.jar --project-root .
Release Workflow

GitHub Actions automated release process:

  1. Push v* tag or manual trigger
  2. Build Fat JAR
  3. Build Native Image (Linux amd64, macOS arm64, Windows amd64)
  4. Build Docker image
  5. Create GitHub Release and upload artifacts
# Create release tag
git tag v1.5.1
git push origin v1.5.1

Testing

# Run all tests (384+ tests)
mvn test

# Run specific test class
mvn test -Dtest=JavaParserAdapterTest

# Run performance benchmarks
mvn test -Dtest=PerformanceBenchmarkTest

What It Is NOT

  • Not a code execution sandbox
  • Not a test runner or linter
  • Not a replacement for LSP/IDE features
  • Not AI-generated summaries (symbol extraction is deterministic)

License

Apache License 2.0

Tag summary

Content type

Image

Digest

sha256:ccb9264e9

Size

93.8 MB

Last updated

29 days ago

docker pull sodlinken/jcodeindexer