Expand description
Strongly-typed AST types for Java, auto-generated from
tree-sitter-java’s node-types.json.
This crate is generated by treesitter-types and is
automatically kept up to date when a new version of the grammar crate is released.
These types have been tested by parsing the Spring Framework source code.
See the Tree-sitter project for more information about the underlying parser framework.
§Example
use treesitter_types_java::*;
// A minimal Java hello-world program.
let src = b"\
class Hello {
public static void main(String[] args) {
System.out.println(\"Hello, World!\");
}
}
";
// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_java::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let program = Program::from_node(tree.root_node(), src).unwrap();
// The program has one top-level child: the `Hello` class.
assert_eq!(program.children.len(), 1);
// Unwrap the class declaration.
let ProgramChildren::Statement(stmt) = &program.children[0] else {
panic!("expected a statement");
};
let Statement::Declaration(decl) = stmt.as_ref() else {
panic!("expected a declaration");
};
let Declaration::ClassDeclaration(class) = decl.as_ref() else {
panic!("expected a class declaration");
};
assert_eq!(class.name.text(), "Hello");
assert!(class.superclass.is_none()); // no `extends`
assert!(class.interfaces.is_none()); // no `implements`
// The class body contains one method.
assert_eq!(class.body.children.len(), 1);Re-exports§
pub use tree_sitter_java;pub use treesitter_types::tree_sitter;
Structs§
- Annotated
Type - Annotation
- Annotation
Argument List - Annotation
Type Body - Annotation
Type Declaration - Annotation
Type Element Declaration - Argument
List - Array
Access - Array
Creation Expression - Array
Initializer - Array
Type - Assert
Statement - Assignment
Expression - Asterisk
- Binary
Expression - Binary
Integer Literal - Block
- Block
Comment - Boolean
Type - Break
Statement - Cast
Expression - Catch
Clause - Catch
Formal Parameter - Catch
Type - Character
Literal - Class
Body - Class
Declaration - Class
Literal - Compact
Constructor Declaration - Constant
Declaration - Constructor
Body - Constructor
Declaration - Continue
Statement - Decimal
Floating Point Literal - Decimal
Integer Literal - Dimensions
- Dimensions
Expr - DoStatement
- Element
Value Array Initializer - Element
Value Pair - Enhanced
ForStatement - Enum
Body - Enum
Body Declarations - Enum
Constant - Enum
Declaration - Escape
Sequence - Explicit
Constructor Invocation - Exports
Module Directive - Expression
Statement - Extends
Interfaces - False
- Field
Access - Field
Declaration - Finally
Clause - Floating
Point Type - ForStatement
- Formal
Parameter - Formal
Parameters - Generic
Type - Guard
- HexFloating
Point Literal - HexInteger
Literal - Identifier
- IfStatement
- Import
Declaration - Inferred
Parameters - Instanceof
Expression - Integral
Type - Interface
Body - Interface
Declaration - Labeled
Statement - Lambda
Expression - Line
Comment - Local
Variable Declaration - Marker
Annotation - Method
Declaration - Method
Invocation - Method
Reference - Modifiers
- Module
Body - Module
Declaration - Multiline
String Fragment - Null
Literal - Object
Creation Expression - Octal
Integer Literal - Opens
Module Directive - Package
Declaration - Parenthesized
Expression - Pattern
- Permits
- Program
- Provides
Module Directive - Receiver
Parameter - Record
Declaration - Record
Pattern - Record
Pattern Body - Record
Pattern Component - Requires
Modifier - Requires
Module Directive - Resource
- Resource
Specification - Return
Statement - Scoped
Identifier - Scoped
Type Identifier - Span
- Spread
Parameter - Static
Initializer - String
Fragment - String
Interpolation - String
Literal - Super
- Super
Interfaces - Superclass
- Switch
Block - Switch
Block Statement Group - Switch
Expression - Switch
Label - Switch
Rule - Synchronized
Statement - Template
Expression - Ternary
Expression - This
- Throw
Statement - Throws
- True
- TryStatement
- TryWith
Resources Statement - Type
Arguments - Type
Bound - Type
Identifier - Type
List - Type
Parameter - Type
Parameters - Type
Pattern - Unary
Expression - Underscore
Pattern - Update
Expression - Uses
Module Directive - Variable
Declarator - Void
Type - While
Statement - Wildcard
- Yield
Statement
Enums§
- Annotated
Type Children - Annotation
Argument List Children - Annotation
Name - Annotation
Type Body Children - Annotation
Type Element Declaration Value - AnyNode
- Array
Creation Expression Children - Array
Creation Expression Dimensions - Array
Initializer Children - Assignment
Expression Left - Assignment
Expression Operator - Binary
Expression Operator - Catch
Formal Parameter Children - Catch
Formal Parameter Name - Class
Body Children - Constructor
Body Children - Constructor
Declaration Children - Declaration
- Dimensions
Children - Dimensions
Expr Children - Element
Value Array Initializer Children - Element
Value Pair Value - Enhanced
ForStatement Name - Enum
Body Children - Enum
Body Declarations Children - Explicit
Constructor Invocation Constructor - Exports
Module Directive Modules - Exports
Module Directive Package - Expression
- Field
Access Field - Field
Access Object - ForStatement
Init - Formal
Parameter Name - Formal
Parameters Children - Generic
Type Children - Import
Declaration Children - Interface
Body Children - Interface
Declaration Children - Labeled
Statement Children - Lambda
Expression Body - Lambda
Expression Parameters - Literal
- Marker
Annotation Name - Method
Declaration Children - Method
Invocation Object - Method
Reference Children - Modifiers
Children - Module
Declaration Children - Module
Declaration Name - Module
Directive - Object
Creation Expression Children - Opens
Module Directive Modules - Opens
Module Directive Package - Package
Declaration Children - Parse
Error - Pattern
Children - Primary
Expression - Program
Children - Provides
Module Directive Children - Provides
Module Directive Provided - Provides
Module Directive Provider - Receiver
Parameter Children - Record
Pattern Body Children - Record
Pattern Children - Record
Pattern Component Children - Requires
Module Directive Module - Resource
Children - Resource
Name - Scoped
Identifier Scope - Scoped
Type Identifier Children - Simple
Type - Spread
Parameter Children - Statement
- String
Literal Children - Switch
Block Children - Switch
Block Statement Group Children - Switch
Label Children - Switch
Rule Children - TryStatement
Children - TryWith
Resources Statement Children - Type
- Type
Arguments Children - Type
Parameter Children - Type
Pattern Children - Unannotated
Type - Unary
Expression Operator - Uses
Module Directive Type - Variable
Declarator Name - Variable
Declarator Value - Wildcard
Children