java

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: MIT Imports: 6 Imported by: 0

README ยถ

Java Code Analyzer

Comprehensive code analyzer for extracting symbols, structure, and relationships from Java files. Indexes code for semantic search in Qdrant.

Status: โœ… PRODUCTION READY


๐ŸŽฏ What This Analyzer Does

The Java analyzer parses .java files and extracts:

  1. Symbols - classes, interfaces, methods, fields, constructors, enums, annotations
  2. Relationships - inheritance, interface implementation, dependencies, method calls
  3. Metadata - access modifiers, generics, annotations, documentation
  4. Documentation - JavaDoc comments for all symbols

Information is converted to CodeChunks which are then indexed in Qdrant for semantic search.


๐Ÿ“Š Data Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   .java Files   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  Java Analyzer   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   CodeChunks    โ”‚
โ”‚  (source code)  โ”‚     โ”‚  (regex parsing) โ”‚     โ”‚  (structured)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                          โ”‚
                                                          โ–ผ
                                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                                 โ”‚     Qdrant      โ”‚
                                                 โ”‚  (vector store) โ”‚
                                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ” What We Index

1. Classes (type: "class")
/**
 * Represents a user in the system.
 * Handles authentication and profile management.
 */
public abstract class User extends BaseEntity implements Comparable<User> {
    private String username;
    protected String email;
    
    public User(String username) {
        this.username = username;
    }
}

Extracted information:

Field Value Description
name "User" Class name
fully_qualified "com.example.User" Fully qualified name
kind "class" Type of declaration
access_modifier "public" Access level
is_abstract true If it's abstract
is_final false If it's final
superclass "BaseEntity" Parent class
interfaces ["Comparable<User>"] Implemented interfaces
description "Represents a user..." JavaDoc documentation
2. Interfaces (type: "interface")
/**
 * Contract for repository operations.
 */
public interface Repository<T> {
    /**
     * Finds an entity by ID.
     * @param id the entity ID
     * @return the found entity or null
     */
    T findById(Long id);
    
    /**
     * Saves an entity.
     * @param entity the entity to save
     * @return the saved entity
     */
    T save(T entity);
}

Extracted information:

Field Value Description
name "Repository" Interface name
kind "interface" Type of declaration
access_modifier "public" Access level
extends [] Superinterfaces
type_parameters ["T"] Generic type parameters
3. Methods (type: "method")
/**
 * Authenticates a user with the given credentials.
 * @param username the username
 * @param password the password
 * @return the authenticated user
 * @throws AuthenticationException if credentials are invalid
 */
public synchronized static User authenticate(String username, String password) 
        throws AuthenticationException {
    // implementation
}

Extracted information:

Field Value Description
name "authenticate" Method name
signature "public synchronized static User authenticate(...)" Complete signature
return_type "User" Return type
access_modifier "public" Access level
is_static true If it's static
is_abstract false If it's abstract
is_synchronized true If it's synchronized
parameters [{name: "username", type: "String"}, ...] Method parameters
throws_exceptions ["AuthenticationException"] Checked exceptions
4. Constructors (type: "constructor")
/**
 * Creates a new User with the given username.
 * @param username the username
 * @throws IllegalArgumentException if username is empty
 */
public User(String username) throws IllegalArgumentException {
    this.username = username;
}

Extracted information:

Field Value Description
name "User" Constructor name (same as class)
signature "public User(String username)" Complete signature
access_modifier "public" Access level
parameters [{name: "username", type: "String"}] Constructor parameters
throws_exceptions ["IllegalArgumentException"] Checked exceptions
5. Fields (type: "field")
/**
 * The user's unique identifier.
 */
private final String username;

/**
 * User's email address.
 */
protected volatile String email;

/**
 * Default user instance.
 */
public static final User DEFAULT = new User("default");

Extracted information:

Field Value Description
name "username" Field name
type "String" Field type
access_modifier "private" Access level
is_static false If it's static
is_final true If it's final
is_volatile false If it's volatile
is_transient false If it's transient
6. Enums (type: "enum")
/**
 * Represents user roles in the system.
 */
public enum Role {
    /** Administrator role with full permissions */
    ADMIN("admin", 10),
    
    /** User role with limited permissions */
    USER("user", 1);
    
    private final String label;
    private final int level;
    
    Role(String label, int level) {
        this.label = label;
        this.level = level;
    }
}

Extracted information:

Field Value Description
name "Role" Enum name
access_modifier "public" Access level
constants [{name: "ADMIN", ...}, {name: "USER", ...}] Enum constants
methods [{name: "Role", ...}] Enum methods
7. Annotations (type: "annotation")
/**
 * Marks a method as deprecated.
 */
@Deprecated(since = "1.2.0", forRemoval = true)
public void oldMethod() { }

Extracted information:

Field Value Description
name "Deprecated" Annotation name
elements [{name: "since", value: "1.2.0"}, ...] Annotation elements

๐Ÿ—๏ธ File Structure

java/
โ”œโ”€โ”€ types.go           # Types: ModuleInfo, ClassInfo, MethodInfo, etc.
โ”œโ”€โ”€ analyzer.go        # PathAnalyzer implementation (1800+ lines)
โ”œโ”€โ”€ analyzer_test.go   # Comprehensive test suite
โ””โ”€โ”€ README.md          # This documentation

๐Ÿ’ป Usage

Standard Analysis
import "github.com/homiodev/rag-code-mcp/internal/ragcode/analyzers/java"

// Create analyzer (excludes test files by default)
analyzer := java.NewCodeAnalyzer()

// Analyze directories/files
chunks, err := analyzer.AnalyzePaths([]string{"./src"})

for _, chunk := range chunks {
    fmt.Printf("[%s] %s.%s\n", chunk.Type, chunk.Package, chunk.Name)
    fmt.Printf("  File: %s (lines %d-%d)\n", chunk.FilePath, chunk.StartLine, chunk.EndLine)
}
With Options
// Include test files in analysis
analyzer := java.NewCodeAnalyzerWithOptions(true)

// This will analyze both src/ and src/test directories
chunks, err := analyzer.AnalyzePaths([]string{"./src"})
Analyze Single File
chunks, err := analyzer.AnalyzePaths([]string{"./src/main/java/com/example/User.java"})

๐Ÿ”Œ Integration

Language Manager

The Java analyzer is automatically selected for:

  • java - generic Java projects
  • maven - Maven projects (pom.xml)
  • gradle - Gradle projects (build.gradle)
  • spring - Spring Boot projects
Workspace Detection

Java projects are detected by:

File Description
pom.xml Apache Maven projects
build.gradle Gradle projects
settings.gradle Gradle multi-module projects
src/main/java Standard Java directory structure
.java Java source files

๐Ÿ“‹ CodeChunk Types

Type Description Example
class Class definition public class User {}
interface Interface definition public interface Repository {}
method Instance or static method public void save()
constructor Constructor public User(String name)
field Class field/member variable private String username;
enum Enum definition public enum Status {}
enum_constant Enum constant ACTIVE("active")
annotation Annotation definition @FunctionalInterface

๐Ÿท๏ธ Complete Metadata

Class Metadata
{
  "access_modifier": "public",
  "is_abstract": false,
  "is_final": false,
  "is_static": false,
  "is_sealed": false,
  "superclass": "BaseEntity",
  "interfaces": ["Comparable<User>", "Serializable"],
  "type_parameters": [{"name": "T", "bounds": ["Serializable"]}]
}
Method Metadata
{
  "access_modifier": "public",
  "is_abstract": false,
  "is_static": false,
  "is_final": false,
  "is_synchronized": false,
  "is_native": false,
  "return_type": "User",
  "throws_exceptions": ["IOException", "SQLException"],
  "parameters": [
    {"name": "id", "type": "Long"},
    {"name": "name", "type": "String"}
  ]
}
Field Metadata
{
  "type": "String",
  "access_modifier": "private",
  "is_static": false,
  "is_final": true,
  "is_volatile": false,
  "is_transient": false,
  "default_value": null
}

๐Ÿงช Testing

# Run all Java analyzer tests
go test ./internal/ragcode/analyzers/java/

# With verbose output
go test -v ./internal/ragcode/analyzers/java/

# Specific test
go test -v -run TestClassExtraction ./internal/ragcode/analyzers/java/

# With coverage
go test -cover ./internal/ragcode/analyzers/java/

๐Ÿšซ Excluded Paths

The analyzer automatically skips:

  • target/ - Maven build directory
  • build/ - Gradle build directory
  • .gradle/, .maven/ - build tool caches
  • node_modules/, .git/ - unrelated dependencies
  • __pycache__/ - Python cache
  • Test.java, Tests.java - test files (by default)

โš ๏ธ Limitations

Limitation Description
Regex-based Uses regex parsing instead of full Java compiler AST (faster, lighter)
No Type Resolution Type hints are extracted as strings, not resolved to actual types
Single-file Each file is analyzed independently
No Runtime Info Doesn't execute code, only static analysis
Generics Simplified Handles basic generics but not complex nested generics
Inner Classes Basic support for inner classes

๐Ÿ”ฎ Future Improvements

  • Full AST support using Java parser library
  • Cross-file type resolution
  • Complete generics support
  • Inheritance graph analysis
  • Method call graph
  • Annotation processor detection
  • Spring-specific analysis (beans, controllers, services)
  • Lombok support (@Data, @Builder, etc.)
  • Micronaut support
  • Quarkus support

๐Ÿ“š See Also

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

This section is empty.

Types ยถ

type AnnotationElement ยถ

type AnnotationElement struct {
	Name         string `json:"name"`
	Type         string `json:"type"`
	DefaultValue string `json:"default_value,omitempty"`
}

AnnotationElement represents an annotation element

type AnnotationInfo ยถ

type AnnotationInfo struct {
	Name        string              `json:"name"`
	Elements    []AnnotationElement `json:"elements"`
	Retention   string              `json:"retention,omitempty"`
	Target      []string            `json:"target,omitempty"`
	Description string              `json:"description"`
	FilePath    string              `json:"file_path,omitempty"`
	StartLine   int                 `json:"start_line,omitempty"`
}

AnnotationInfo describes a Java annotation

type ClassInfo ยถ

type ClassInfo struct {
	Name           string            `json:"name"`
	FullyQualified string            `json:"fully_qualified"`
	Kind           string            `json:"kind"` // class, interface, record, enum
	Description    string            `json:"description"`
	AccessModifier string            `json:"access_modifier"` // public, protected, private, package-private
	IsAbstract     bool              `json:"is_abstract"`
	IsFinal        bool              `json:"is_final"`
	IsStatic       bool              `json:"is_static"`
	IsSealed       bool              `json:"is_sealed"`
	Superclass     string            `json:"superclass,omitempty"`
	Interfaces     []string          `json:"interfaces,omitempty"`
	TypeParameters []TypeParameter   `json:"type_parameters,omitempty"` // Generics
	Fields         []FieldInfo       `json:"fields"`
	Methods        []MethodInfo      `json:"methods"`
	Constructors   []ConstructorInfo `json:"constructors"`
	Annotations    []string          `json:"annotations,omitempty"`
	InnerClasses   []ClassInfo       `json:"inner_classes,omitempty"`
	FilePath       string            `json:"file_path,omitempty"`
	StartLine      int               `json:"start_line,omitempty"`
	EndLine        int               `json:"end_line,omitempty"`
	Code           string            `json:"code,omitempty"`
}

ClassInfo describes a Java class, interface, or enum

type CodeAnalyzer ยถ

type CodeAnalyzer struct {
	// contains filtered or unexported fields
}

CodeAnalyzer implements PathAnalyzer for Java source files.

func NewCodeAnalyzer ยถ

func NewCodeAnalyzer() *CodeAnalyzer

func NewCodeAnalyzerWithOptions ยถ

func NewCodeAnalyzerWithOptions(t bool) *CodeAnalyzer

func (*CodeAnalyzer) AnalyzePaths ยถ

func (a *CodeAnalyzer) AnalyzePaths(paths []string) ([]codetypes.CodeChunk, error)

type ConstructorInfo ยถ

type ConstructorInfo struct {
	Name             string                `json:"name"`
	Signature        string                `json:"signature"`
	AccessModifier   string                `json:"access_modifier"`
	Parameters       []codetypes.ParamInfo `json:"parameters"`
	ThrowsExceptions []string              `json:"throws_exceptions,omitempty"`
	Annotations      []string              `json:"annotations,omitempty"`
	Description      string                `json:"description"`
	FilePath         string                `json:"file_path,omitempty"`
	StartLine        int                   `json:"start_line,omitempty"`
	EndLine          int                   `json:"end_line,omitempty"`
	Code             string                `json:"code,omitempty"`
}

ConstructorInfo describes a class constructor

type EnumConstant ยถ

type EnumConstant struct {
	Name        string   `json:"name"`
	Value       string   `json:"value,omitempty"`
	Description string   `json:"description"`
	Annotations []string `json:"annotations,omitempty"`
}

EnumConstant represents an enum constant

type EnumInfo ยถ

type EnumInfo struct {
	Name           string         `json:"name"`
	FullyQualified string         `json:"fully_qualified"`
	Description    string         `json:"description"`
	AccessModifier string         `json:"access_modifier"`
	Constants      []EnumConstant `json:"constants"`
	Methods        []MethodInfo   `json:"methods"`
	Interfaces     []string       `json:"interfaces,omitempty"`
	Annotations    []string       `json:"annotations,omitempty"`
	FilePath       string         `json:"file_path,omitempty"`
	StartLine      int            `json:"start_line,omitempty"`
	EndLine        int            `json:"end_line,omitempty"`
	Code           string         `json:"code,omitempty"`
}

EnumInfo describes a Java enum

type FieldInfo ยถ

type FieldInfo struct {
	Name           string   `json:"name"`
	Type           string   `json:"type"`
	AccessModifier string   `json:"access_modifier"`
	IsStatic       bool     `json:"is_static"`
	IsFinal        bool     `json:"is_final"`
	IsTransient    bool     `json:"is_transient"`
	IsVolatile     bool     `json:"is_volatile"`
	DefaultValue   string   `json:"default_value,omitempty"`
	Annotations    []string `json:"annotations,omitempty"`
	Description    string   `json:"description"`
	FilePath       string   `json:"file_path,omitempty"`
	StartLine      int      `json:"start_line,omitempty"`
}

FieldInfo describes a class field/member variable

type MethodInfo ยถ

type MethodInfo struct {
	Name             string                 `json:"name"`
	Signature        string                 `json:"signature"`
	ReturnType       string                 `json:"return_type"`
	AccessModifier   string                 `json:"access_modifier"`
	IsAbstract       bool                   `json:"is_abstract"`
	IsStatic         bool                   `json:"is_static"`
	IsFinal          bool                   `json:"is_final"`
	IsSynchronized   bool                   `json:"is_synchronized"`
	IsNative         bool                   `json:"is_native"`
	Parameters       []codetypes.ParamInfo  `json:"parameters"`
	ReturnTypes      []codetypes.ReturnInfo `json:"return_types"`
	TypeParameters   []TypeParameter        `json:"type_parameters,omitempty"` // Generics
	ThrowsExceptions []string               `json:"throws_exceptions,omitempty"`
	Annotations      []string               `json:"annotations,omitempty"`
	Description      string                 `json:"description"`
	FilePath         string                 `json:"file_path,omitempty"`
	StartLine        int                    `json:"start_line,omitempty"`
	EndLine          int                    `json:"end_line,omitempty"`
	Code             string                 `json:"code,omitempty"`
}

MethodInfo describes a class method

type ModuleInfo ยถ

type ModuleInfo struct {
	Name        string           `json:"name"`
	Path        string           `json:"path"`
	Description string           `json:"description"`
	Classes     []ClassInfo      `json:"classes"`
	Interfaces  []ClassInfo      `json:"interfaces"`
	Enums       []EnumInfo       `json:"enums"`
	Annotations []AnnotationInfo `json:"annotations"`
	Imports     []string         `json:"imports"`
}

ModuleInfo contains comprehensive information about a Java module/package

type TypeParameter ยถ

type TypeParameter struct {
	Name   string   `json:"name"`
	Bounds []string `json:"bounds,omitempty"` // Upper bounds for type parameter
}

TypeParameter represents a generic type parameter (e.g., T, K extends Comparable)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL