Skip to content

Commit 55294ef

Browse files
authored
[pigeon] Updates writeScoped and addScoped to disallow symbol-less use. (#3081)
* remove left over symbol-less scoped method calls * assert to enforce no nesting with scoped * changelog * fix version num * nits
1 parent 86b21ee commit 55294ef

File tree

25 files changed

+55
-98
lines changed

25 files changed

+55
-98
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 7.0.3
2+
3+
* Updates scoped methods to prevent symbol-less use.
4+
15
## 7.0.2
26

37
* [kotlin] Fixes a missed casting of not nullable Dart 'int' to Kotlin 64bit long.

packages/pigeon/lib/cpp_generator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,17 +849,17 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
849849
indent.write('switch (type) ');
850850
indent.addScoped('{', '}', () {
851851
for (final EnumeratedClass customClass in getCodecClasses(api, root)) {
852-
indent.write('case ${customClass.enumeration}:');
853-
indent.writeScoped('', '', () {
852+
indent.writeln('case ${customClass.enumeration}:');
853+
indent.nest(1, () {
854854
indent.writeln(
855855
'return flutter::CustomEncodableValue(${customClass.name}(std::get<flutter::EncodableList>(ReadValue(stream))));');
856856
});
857857
}
858-
indent.write('default:');
859-
indent.writeScoped('', '', () {
858+
indent.writeln('default:');
859+
indent.nest(1, () {
860860
indent.writeln(
861861
'return $_defaultCodecSerializer::ReadValueOfType(type, stream);');
862-
}, addTrailingNewline: false);
862+
});
863863
});
864864
});
865865
indent.newln();

packages/pigeon/lib/dart_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ void _writeCodec(Indent indent, String codecName, Api api, Root root) {
669669
indent.write('switch (type) ');
670670
indent.addScoped('{', '}', () {
671671
for (final EnumeratedClass customClass in codecClasses) {
672-
indent.write('case ${customClass.enumeration}: ');
673-
indent.writeScoped('', '', () {
672+
indent.writeln('case ${customClass.enumeration}: ');
673+
indent.nest(1, () {
674674
indent.writeln(
675675
'return ${customClass.name}.decode(readValue(buffer)!);');
676676
});

packages/pigeon/lib/generator_tools.dart

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import 'dart:mirrors';
88

99
import 'ast.dart';
1010

11-
/// The current version of pigeon. This must match the version in pubspec.yaml.
12-
const String pigeonVersion = '7.0.2';
11+
/// The current version of pigeon.
12+
///
13+
/// This must match the version in pubspec.yaml.
14+
const String pigeonVersion = '7.0.3';
1315

1416
/// Read all the content from [stdin] to a String.
1517
String readStdin() {
@@ -81,15 +83,18 @@ class Indent {
8183
}
8284
}
8385

84-
/// Scoped increase of the ident level. For the execution of [func] the
85-
/// indentation will be incremented.
86+
/// Scoped increase of the indent level.
87+
///
88+
/// For the execution of [func] the indentation will be incremented.
8689
void addScoped(
8790
String? begin,
8891
String? end,
8992
Function func, {
9093
bool addTrailingNewline = true,
9194
int nestCount = 1,
9295
}) {
96+
assert(begin != '' || end != '',
97+
'Use nest for indentation without any decoration');
9398
if (begin != null) {
9499
_sink.write(begin + newline);
95100
}
@@ -109,12 +114,15 @@ class Indent {
109114
Function func, {
110115
bool addTrailingNewline = true,
111116
}) {
117+
assert(begin != '' || end != '',
118+
'Use nest for indentation without any decoration');
112119
addScoped(str() + (begin ?? ''), end, func,
113120
addTrailingNewline: addTrailingNewline);
114121
}
115122

116-
/// Scoped increase of the ident level. For the execution of [func] the
117-
/// indentation will be incremented by the given amount.
123+
/// Scoped increase of the indent level.
124+
///
125+
/// For the execution of [func] the indentation will be incremented by the given amount.
118126
void nest(int count, Function func) {
119127
inc(count);
120128
func(); // ignore: avoid_dynamic_calls
@@ -270,9 +278,10 @@ void addLines(Indent indent, Iterable<String> lines, {String? linePrefix}) {
270278
}
271279
}
272280

273-
/// Recursively merges [modification] into [base]. In other words, whenever
274-
/// there is a conflict over the value of a key path, [modification]'s value for
275-
/// that key path is selected.
281+
/// Recursively merges [modification] into [base].
282+
///
283+
/// In other words, whenever there is a conflict over the value of a key path,
284+
/// [modification]'s value for that key path is selected.
276285
Map<String, Object> mergeMaps(
277286
Map<String, Object> base,
278287
Map<String, Object> modification,

packages/pigeon/lib/java_generator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,16 +717,16 @@ Result<$returnType> $resultName =
717717
indent.write('switch (type) ');
718718
indent.addScoped('{', '}', () {
719719
for (final EnumeratedClass customClass in codecClasses) {
720-
indent.write('case (byte) ${customClass.enumeration}: ');
721-
indent.writeScoped('', '', () {
720+
indent.writeln('case (byte) ${customClass.enumeration}:');
721+
indent.nest(1, () {
722722
indent.writeln(
723723
'return ${customClass.name}.fromList((ArrayList<Object>) readValue(buffer));');
724724
});
725725
}
726-
indent.write('default:');
727-
indent.addScoped('', '', () {
726+
indent.writeln('default:');
727+
indent.nest(1, () {
728728
indent.writeln('return super.readValueOfType(type, buffer);');
729-
}, addTrailingNewline: false);
729+
});
730730
});
731731
});
732732
indent.newln();

packages/pigeon/lib/objc_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
722722
indent.write('switch (type) ');
723723
indent.addScoped('{', '}', () {
724724
for (final EnumeratedClass customClass in codecClasses) {
725-
indent.write('case ${customClass.enumeration}: ');
726-
indent.writeScoped('', '', () {
725+
indent.writeln('case ${customClass.enumeration}: ');
726+
indent.nest(1, () {
727727
indent.writeln(
728728
'return [${_className(options.prefix, customClass.name)} fromList:[self readValue]];');
729729
});

packages/pigeon/mock_handler_tester/test/message.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
5+
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
88

@@ -146,10 +146,8 @@ class _MessageApiCodec extends StandardMessageCodec {
146146
switch (type) {
147147
case 128:
148148
return MessageSearchReply.decode(readValue(buffer)!);
149-
150149
case 129:
151150
return MessageSearchRequest.decode(readValue(buffer)!);
152-
153151
default:
154152
return super.readValueOfType(type, buffer);
155153
}
@@ -245,13 +243,10 @@ class _MessageNestedApiCodec extends StandardMessageCodec {
245243
switch (type) {
246244
case 128:
247245
return MessageNested.decode(readValue(buffer)!);
248-
249246
case 129:
250247
return MessageSearchReply.decode(readValue(buffer)!);
251-
252248
case 130:
253249
return MessageSearchRequest.decode(readValue(buffer)!);
254-
255250
default:
256251
return super.readValueOfType(type, buffer);
257252
}
@@ -320,10 +315,8 @@ class _MessageFlutterSearchApiCodec extends StandardMessageCodec {
320315
switch (type) {
321316
case 128:
322317
return MessageSearchReply.decode(readValue(buffer)!);
323-
324318
case 129:
325319
return MessageSearchRequest.decode(readValue(buffer)!);
326-
327320
default:
328321
return super.readValueOfType(type, buffer);
329322
}

packages/pigeon/mock_handler_tester/test/test.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
5+
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
88
// ignore_for_file: avoid_relative_lib_imports
@@ -34,10 +34,8 @@ class _TestHostApiCodec extends StandardMessageCodec {
3434
switch (type) {
3535
case 128:
3636
return MessageSearchReply.decode(readValue(buffer)!);
37-
3837
case 129:
3938
return MessageSearchRequest.decode(readValue(buffer)!);
40-
4139
default:
4240
return super.readValueOfType(type, buffer);
4341
}
@@ -119,13 +117,10 @@ class _TestNestedApiCodec extends StandardMessageCodec {
119117
switch (type) {
120118
case 128:
121119
return MessageNested.decode(readValue(buffer)!);
122-
123120
case 129:
124121
return MessageSearchReply.decode(readValue(buffer)!);
125-
126122
case 130:
127123
return MessageSearchRequest.decode(readValue(buffer)!);
128-
129124
default:
130125
return super.readValueOfType(type, buffer);
131126
}

packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
5+
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
package com.example.alternate_language_test_plugin;
@@ -724,13 +724,10 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
724724
switch (type) {
725725
case (byte) 128:
726726
return AllNullableTypes.fromList((ArrayList<Object>) readValue(buffer));
727-
728727
case (byte) 129:
729728
return AllNullableTypesWrapper.fromList((ArrayList<Object>) readValue(buffer));
730-
731729
case (byte) 130:
732730
return AllTypes.fromList((ArrayList<Object>) readValue(buffer));
733-
734731
default:
735732
return super.readValueOfType(type, buffer);
736733
}
@@ -2139,13 +2136,10 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
21392136
switch (type) {
21402137
case (byte) 128:
21412138
return AllNullableTypes.fromList((ArrayList<Object>) readValue(buffer));
2142-
21432139
case (byte) 129:
21442140
return AllNullableTypesWrapper.fromList((ArrayList<Object>) readValue(buffer));
2145-
21462141
case (byte) 130:
21472142
return AllTypes.fromList((ArrayList<Object>) readValue(buffer));
2148-
21492143
default:
21502144
return super.readValueOfType(type, buffer);
21512145
}

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
5+
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import <Foundation/Foundation.h>

0 commit comments

Comments
 (0)