https://github.com/matrixeditor/aidl-parser
Android Interface Defintion Parser (AIDL) in Python3 - modified fork of javalang, a pure Python parser of the Java language.
https://github.com/matrixeditor/aidl-parser
Last synced: 3 months ago
JSON representation
Android Interface Defintion Parser (AIDL) in Python3 - modified fork of javalang, a pure Python parser of the Java language.
- Host: GitHub
- URL: https://github.com/matrixeditor/aidl-parser
- Owner: MatrixEditor
- License: mit
- Created: 2023-12-10T14:19:27.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-16T06:59:18.000Z (about 1 year ago)
- Last Synced: 2024-12-28T20:45:59.863Z (5 months ago)
- Language: Python
- Size: 51.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Android Interface Definition Language (AIDL) Parser
[](https://www.python.org/downloads/)


[](https://github.com/c2nes/javalang)> [!Warning]
> This repository aims to provide an implementation of an AIDL parser in Python. For information about the original repository, visit [c2nes/javalang](https://github.com/c2nes/javalang).`aidl-parser` is a small Python library that can be used to lex and parse Android Interface Definition Language (AIDL) files as well as default Java files.
## Installation
First, clone the repository and change the working directory. Next, install the python library to your local site-packages.
```bash
git clone https://github.com/MatrixEditor/aidl-parser.git
cd aidl-parser && pip install .
```## Getting Started
```python
>>> import aidl
>>> unit = aidl.fromstring("package com.example; parcelable Foo;")
```The call above will return an instance of `CompilationUnit`. This particular object serves as the root of a tree structure that can be navigated to retrieve various pieces of information regarding the compilation unit.
```python
>>> unit.package.name
'com.example'
>>> unit.types[0]
ParcelableDeclaration
>>> unit.types[0].name
'Foo'
```The string provided to `aidl.fromstring` must represent a complete unit, indicating that it should represent a valid AIDL or Java source file in its entirety. However, other functions within the `aidl.parse` module enable the parsing of smaller code snippets without the need to supply a complete compilation unit.
## AIDL Types
### `Parcelable`
As a simple parcelable defintion can be just a reference to the Java implementation file, there will be a special attribute named `is_ref`. It will indicate the presence of a Java implementation file. The `cpp_header` stores an optional C++ file reference.
ParcelableDeclaration(
is_ref: bool
name: str
cpp_header: str
)An example AIDL file with a parcelable would look like this:
```aidl
package com.example;parcelable Foo cpp_header "native/include/Foo.h";
```### `Binder`
Binder declarations will be treated as `InterfaceDeclaration` objects internally. As the AIDL specification contains new keywords, the following example tries to illustrates their use case:
```aidl
package com.example;import com.example.Foo; // all types must be imported
// 'oneway' indicates we don't get a result
oneway interface FooListener {
// all non-primitive types except String, IBinder and AIDL-generated
// interfaces must be defined with a directional tag: in, out, inout
void onActionPerformed(in @nullable Foo foo) = 2; // manually defined transaction code
}
```For more information about how to write AIDL files, use the [Android Developer](https://developer.android.com/guide/components/aidl?hl=en) reference on AIDL.