Javalang is a pure Python library designed for working with Java source code. It provides a lexer and parser specifically targeting Java 8, with its implementation based on the Java Language Specification. The library's current version is 0.13.0, released on March 28, 2020.
pip install javalangVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a complete Java source file using `javalang.parse.parse()` and then traversing the resulting Abstract Syntax Tree (AST) to extract package, class, method, and field names. Error handling for common parsing issues is included.
Ensure the Java source code to be parsed adheres to Java 8 syntax. For newer Java versions, consider alternatives or extensions like `javalang-ext` if they support the desired Java version, though `javalang-ext` also builds on `javalang`'s Java 8 parsing.
Always wrap code snippets in a minimal but valid Java class and package structure before passing them to `javalang.parse.parse()`. For more flexible snippet parsing, investigate `javalang-ext` or `javalang-plus`, which offer 'syntactic element-deducing' parse functions.
Users requiring ongoing support, new features, or compatibility with Java versions beyond 8 should evaluate forks, extensions (like `javalang-ext` or `javalang-plus`), or other Java parsing libraries in Python.
No dependency data recorded yet.