Repository navigation
Commit f918311
authored
[pigeon] add support for top level consts (flutter#12032)
# Add Top-level Constants Support to Pigeon
This PR adds support for defining and generating top-level constants across all target languages supported by Pigeon (Dart, Kotlin, Java, Swift, Objective-C, C++, and GObject).
Resolves: flutter#188642
## Summary of Changes
### 1. AST & Parser
* Added a `Constant` node type to the AST representing top-level constants.
* Updated `pigeon_lib_internal.dart` to parse `const` declarations.
* Restrained constant types to: `String`, `int`, `double`, and `bool`.
* Implemented validation for explicit type annotations, type matching, and initialization values (unsupported types, binary expressions, and string interpolations will trigger compilation errors).
### 2. Code Generation
Added constant generation to all target languages:
* **Dart**: Generates top-level `const` variables.
* **Java**: Generates `public static final` fields inside the main generated class.
* **Kotlin**: Generates companion object `const val` properties (using `val` for double/boolean where JVM `const` is not supported).
* **Swift**: Generates global `public let` constants.
* **Objective-C**: Generates global `static const` / `static NSString *const` variables in the header file.
* **C++**: Generates global `inline constexpr` variables in the header.
* **GObject**: Generates global `#define` macros in the header.
### 3. Tests & Documentation
* Added parsing validation tests in `test/pigeon_lib_test.dart`.
* Added generator unit tests (`test/*_generator_test.dart`) for each language verifying the syntax of generated constants.
* Updated `pigeons/core_tests.dart` with constant declarations, and added corresponding unit tests verifying their correctness in each target platform project.
* Added an integration test in `platform_tests/shared_test_plugin_code/lib/integration_tests.dart` to assert constant values at runtime.
* Updated `packages/pigeon/README.md` to document the new feature, using code excerpts linked to `example/app/pigeons/messages.dart`.1 parent b39bbbb commit f918311
48 files changed
Lines changed: 1167 additions & 10 deletions
File tree
- packages/pigeon
- example/app
- android/app/src/main
- java/io/flutter/plugins
- kotlin/dev/flutter/pigeon_example_app
- ios/Runner
- lib/src
- linux
- macos/Runner
- pigeons
- windows/runner
- lib/src
- cpp
- dart
- gobject
- java
- kotlin
- objc
- swift
- pigeons
- platform_tests
- alternate_language_test_plugin
- android/src
- main/java/com/example/alternate_language_test_plugin
- test/java/com/example/alternate_language_test_plugin
- darwin/alternate_language_test_plugin/Sources/alternate_language_test_plugin
- include/alternate_language_test_plugin
- example/ios/RunnerTests
- test_plugin
- android/src
- main/kotlin/com/example/test_plugin
- test/kotlin/com/example/test_plugin
- darwin/test_plugin/Sources/test_plugin
- example/ios/RunnerTests
- linux
- pigeon
- test
- windows
- pigeon
- test
- test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
85 | 100 | | |
86 | 101 | | |
87 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments