treesitter_types_java/lib.rs
1//! Strongly-typed AST types for Java, auto-generated from
2//! [`tree-sitter-java`](https://docs.rs/tree-sitter-java)'s `node-types.json`.
3//!
4//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
5//! automatically kept up to date when a new version of the grammar crate is released.
6//!
7//! These types have been tested by parsing the
8//! [Spring Framework](https://github.com/spring-projects/spring-framework) source code.
9//!
10//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
11//! information about the underlying parser framework.
12//!
13//! # Example
14//!
15//! ```
16//! use treesitter_types_java::*;
17//!
18//! // A minimal Java hello-world program.
19//! let src = b"\
20//! class Hello {
21//! public static void main(String[] args) {
22//! System.out.println(\"Hello, World!\");
23//! }
24//! }
25//! ";
26//!
27//! // Parse the source with tree-sitter and convert into typed AST.
28//! let mut parser = tree_sitter::Parser::new();
29//! parser.set_language(&tree_sitter_java::LANGUAGE.into()).unwrap();
30//! let tree = parser.parse(src, None).unwrap();
31//! let program = Program::from_node(tree.root_node(), src).unwrap();
32//!
33//! // The program has one top-level child: the `Hello` class.
34//! assert_eq!(program.children.len(), 1);
35//!
36//! // Unwrap the class declaration.
37//! let ProgramChildren::Statement(stmt) = &program.children[0] else {
38//! panic!("expected a statement");
39//! };
40//! let Statement::Declaration(decl) = stmt.as_ref() else {
41//! panic!("expected a declaration");
42//! };
43//! let Declaration::ClassDeclaration(class) = decl.as_ref() else {
44//! panic!("expected a class declaration");
45//! };
46//! assert_eq!(class.name.text(), "Hello");
47//! assert!(class.superclass.is_none()); // no `extends`
48//! assert!(class.interfaces.is_none()); // no `implements`
49//!
50//! // The class body contains one method.
51//! assert_eq!(class.body.children.len(), 1);
52//! ```
53
54pub use tree_sitter_java;
55pub use treesitter_types::tree_sitter;
56pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
57
58mod generated;
59pub use generated::*;