Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 17.0.0

* **Breaking Change** [kotlin] Converts Kotlin enum case generation to SCREAMING_SNAKE_CASE.
* Updates `writeEnum` function to adhere to Kotlin naming conventions.
* Improves handling of complex names with enhanced regex patterns.
* Expands unit tests for comprehensive name conversion validation.
* **Migration Note**: This change modifies the naming convention of Kotlin enum cases generated from the Pigeon package. It is recommended to review the impact on your existing codebase and update any dependent code accordingly.

## 16.0.3

* [kotlin] Separates message call code generation into separate methods.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '16.0.3';
const String pigeonVersion = '17.0.0';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
7 changes: 6 additions & 1 deletion packages/pigeon/lib/kotlin_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
enumerate(anEnum.members, (int index, final EnumMember member) {
addDocumentationComments(
indent, member.documentationComments, _docCommentSpec);
indent.write('${member.name.toUpperCase()}($index)');
final String nameScreamingSnakeCase = member.name
.replaceAllMapped(
RegExp(r'(?<=[a-z])[A-Z]'),
(Match m) => '_${m.group(0)}')
.toUpperCase();
indent.write('$nameScreamingSnakeCase($index)');
if (index != anEnum.members.length - 1) {
indent.addln(',');
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pigeon
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
version: 16.0.3 # This must match the version in lib/generator_tools.dart
version: 17.0.0 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
18 changes: 9 additions & 9 deletions packages/pigeon/test/kotlin_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -845,24 +845,24 @@ void main() {
expect(code, matches('fun doSomething.*Input.*callback.*Output.*Unit'));
});

test('gen one enum class', () {
test('gen one enum class with screaming snake case conversion', () {
final Enum anEnum = Enum(
name: 'Enum1',
name: 'SampleEnum',
members: <EnumMember>[
EnumMember(name: 'one'),
EnumMember(name: 'two'),
EnumMember(name: 'sampleVersion'),
EnumMember(name: 'sampleTest'),
],
);
final Class classDefinition = Class(
name: 'EnumClass',
fields: <NamedType>[
NamedType(
type: TypeDeclaration(
baseName: 'Enum1',
baseName: 'SampleEnum',
associatedEnum: emptyEnum,
isNullable: true,
),
name: 'enum1',
name: 'sampleEnum',
),
],
);
Expand All @@ -881,9 +881,9 @@ void main() {
dartPackageName: DEFAULT_PACKAGE_NAME,
);
final String code = sink.toString();
expect(code, contains('enum class Enum1(val raw: Int)'));
expect(code, contains('ONE(0)'));
expect(code, contains('TWO(1)'));
expect(code, contains('enum class SampleEnum(val raw: Int)'));
expect(code, contains('SAMPLE_VERSION(0)'));
expect(code, contains('SAMPLE_TEST(1)'));
});

Iterable<String> makeIterable(String string) sync* {
Expand Down