Oak Java Parser
High-performance incremental Java parser for the oak ecosystem with flexible configuration, optimized for static analysis and code generation.
🎯 Overview
Oak Java is a robust parser for Java, designed to handle complete Java syntax including modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for static analysis and code generation.
✨ Features
- Complete Java Syntax: Supports all Java features including modern specifications
- Full AST Generation: Generates comprehensive Abstract Syntax Trees
- Lexer Support: Built-in tokenization with proper span information
- Error Recovery: Graceful handling of syntax errors with detailed diagnostics
🚀 Quick Start
Basic example:
use ;
use ;
📋 Parsing Examples
Method Parsing
use ;
use ;
let mut session = default;
let parser = new;
let source = new;
let result = parser.parse;
println!;
Class Parsing
use ;
use ;
let mut session = default;
let parser = new;
let source = new;
let result = parser.parse;
println!;
🔧 Advanced Features
Token-Level Parsing
use ;
use ;
let mut session = default;
let parser = new;
let source = new;
let result = parser.parse;
println!("Token parsing completed.");
### Error Handling
```rust
use oak_java::{Parser, JavaLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
// Invalid Java code example
public class BrokenClass {
public static void main(String[] args {
System.out.println("Hello")
// Missing closing braces
}
"#);
let result = parser.parse(&source);
if let Some(errors) = result.result.err() {
println!("Parse errors found: {:?}", errors);
} else {
println!("Parsed successfully.");
}
🏗️ AST Structure
The parser generates a comprehensive AST with the following main structures:
- JavaProgram: Root container for Java programs
- Class: Java class definitions
- Method: Java methods and constructors
- Statement: Various statement types including control flow
- Expression: Various expression types including operators
- Type: Java type system constructs
📊 Performance
- Streaming: Parse large Java files without loading entirely into memory
- Incremental: Re-parse only changed sections
- Memory Efficient: Smart AST node allocation
- Fast Recovery: Quick error recovery for better IDE integration
🔗 Integration
Oak Java integrates seamlessly with:
- Static Analysis: Code quality and security analysis
- Code Generation: Generating code from Java AST
- IDE Support: Language server protocol compatibility
- Refactoring: Automated code refactoring
- Documentation: Generating documentation from Java code
📚 Examples
Check out the examples directory for comprehensive examples:
- Complete Java program parsing
- Method and class analysis
- Code transformation
- Integration with development workflows
🤝 Contributing
Contributions are welcome!
Please feel free to submit pull requests at the project repository or open issues.