tree-sitter-java
repository·master·Indexed 42 days ago
https://github.com/tree-sitter/tree-sitter-javaA Java grammar implementation for the tree-sitter incremental parsing library, version 0.23.5. It enables the generation of concrete syntax trees for Java source code to support syntax highlighting, code navigation, and structural analysis.
What's inside tree-sitter-java
- tree-sitter-java provides a Java grammar implementation for the tree-sitter incremental parsing library. It allows developers to generate concrete syntax trees for Java source code, enabling features like syntax highlighting, code navigation, and structural analysis.
Import the tree-sitter-java Node.js bindings
masterTo use the Java grammar in a Node.js application, require the
tree-sitter-javapackage. The module exports the compiled tree-sitter grammar object, which can be used with the maintree-sitterlibrary to parse Java source code.Note: The package includes support for Bun via static analysis for
bun build --compileand usesnode-gyp-buildfor standard Node.js environments.const Parser = require('tree-sitter'); const Java = require('tree-sitter-java'); const parser = new Parser(); parser.setLanguage(Java); const tree = parser.parse('class Test { int x = 1; }');Access Java node type information via nodeTypeInfo
masterThe
tree-sitter-javamodule optionally exports anodeTypeInfoproperty. This property contains a JSON object mapping node types to their metadata (defined insrc/node-types.json). This is useful for programmatic inspection of the grammar's node structure.const Java = require('tree-sitter-java'); if (Java.nodeTypeInfo) { console.log(Java.nodeTypeInfo); }