Language Server Features
The Java LSP provides intelligent code analysis and editing capabilities:Code Completion
Smart Completions
Context-aware suggestions for classes, methods, fields, and variables with type information
Auto-Import
Automatic import statement generation when completing types from external packages
Snippet Support
Built-in code snippets for common patterns like loops, conditionals, and try-catch blocks
Parameter Hints
Method parameter information and signature help during invocation
FindCompletionsAt visitor to locate completion points in the AST and provides suggestions based on:
- Local variables and method parameters
- Class members (fields and methods)
- Imported and classpath types
- Java language keywords
java/lsp/src/main/java/com/tom/rv2ide/lsp/java/visitors/FindCompletionsAt.java
Diagnostics
Real-time error detection and reporting:- Compilation Errors: Syntax errors, type mismatches, and undeclared variables
- Semantic Analysis: Method signature conflicts, accessibility issues, and unresolved symbols
- Quick Fixes: Automated fixes for common issues like missing imports or method implementations
The diagnostic system uses incremental compilation to minimize performance impact. Only changed methods are reparsed when possible, utilizing the
PartialReparser for efficient updates.Code Navigation
- Go to Definition
- Find References
- Type Hierarchy
Jump to the declaration of any class, method, or field. The language server searches both source files and compiled classpath entries.
Code Examples
Basic Java Class
MainActivity.java
Advanced Features
- Lambdas
- Streams
- Records
Supported Language Features
Core Java Features
- Java 8-17 Syntax: Full support for modern Java language features
- Generics: Complete type parameter inference and validation
- Annotations: Processing of standard and custom annotations
- Inner Classes: Anonymous classes, local classes, and member classes
- Enums: Enumeration types with methods and constructors
Android-Specific
- Android API Completion: Context-aware suggestions for Android SDK classes
- Resource References: Integration with R class for resource access
- Manifest Awareness: Understanding of AndroidManifest.xml configurations
Code Rewrites and Refactoring
The language server provides automated code transformations:Add Import
Automatically insert import statements for unresolved types
Implement Abstract Methods
Generate stubs for inherited abstract methods
Remove Unused
Clean up unused imports, methods, and classes
Generate Constructors
Create constructors for record types and regular classes
java/lsp/src/main/java/com/tom/rv2ide/lsp/java/rewrite/):
AddImport: Insert missing import statementsImplementAbstractMethods: Implement methods from interfaces/abstract classesRemoveMethod,RemoveClass,RemoveException: Code cleanup operationsCreateMissingMethod: Generate method stubs for undefined referencesAddSuppressWarningAnnotation: Add@SuppressWarningsannotations
Snippets
Built-in code snippets accelerate development:- Control Flow
- Exception Handling
- Conditionals
java/lsp/src/main/assets/data/editor/java/ and support placeholders, tab stops, and transformations.
Compiler Configuration
Source and Target Compatibility
The Java compiler service (JavaCompilerService) can be configured through the module’s build configuration:
Classpath Management
The language server automatically manages classpaths:- Boot Classpath: Android SDK classes from
android.jar - Compile Classpath: Project dependencies and library JARs
- Source Classpath: Project source directories
The
SourceFileManager handles file resolution across source paths, ensuring efficient lookup of Java source files during compilation and navigation.Performance Optimizations
Incremental Compilation
The compiler uses several strategies to minimize compilation overhead:- Cached Compilation: Reuses previous compilation results when source files haven’t changed
- Partial Reparsing: Only recompiles modified methods within a class (when possible)
- Synchronized Tasks: Manages compilation requests to prevent redundant work
Caching
Multiple cache layers improve responsiveness:- Type Declaration Cache: Caches parsed compilation units
- Import Cache: Stores import statements per file
- Word Search Cache: Optimizes text-based symbol searches
Limitations
API Reference
Key interfaces and classes:CompilerProvider
The main interface for interacting with the Java compiler:JavaCompilerService
The main implementation ofCompilerProvider:
Related Documentation
Kotlin Support
Learn about Kotlin language features
XML Support
Explore XML editing capabilities
Code Editor
Understand editor features and shortcuts
Build System
Configure build options and dependencies