2 releases
Uses new Rust 2024
| 0.1.2 | Feb 12, 2026 |
|---|---|
| 0.1.0 | Feb 8, 2026 |
#177 in #java
Used in java2pyi
63KB
1.5K
SLoC
java2pyi
Java‑to‑PYI is a Rust tool that parses Java source into a preprocessed AST and generates Python stub files (.pyi) with type definitions only. It was originally designed to generate class declarations to provide accurate type hints in the Telegram codebase when developing Exteragram plugins.
Installation from crates.io
cargo install java2pyi
Building from source code and installation steps
- Clone this repo
git clone https://github.com/n08i40k/java2pyi
- Compile and install
cargo install --path .
Usage example
- Clone OpenJDK source code (required for all use-cases, otherwise, non-promitive java types won't be resolved)
git clone https://github.com/openjdk/jdk
- Remove sample file from OpenJDK source code
rm ./jdk/src/java.base/share/classes/java/lang/snippet-files/ProcessExamples.java
- Clone Telegram for Android source code
git clone https://github.com/DrKLO/Telegram
- Create directory for stub files
mkdir stubs
- Start generator
java2pyi -i ./jdk/src/java.base/share/classes/java/ -i ./Telegram/TMessagesProj/src/main/java/ -o ./stubs
Where -i is directories with .java files and -o is output directory for generated stubs.
Dependencies
~1.1–2.8MB
~56K SLoC