Skip to content

[pigeon] Updates writeScoped and addScoped to disallow symbol-less use. #3081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.0.3

* Updates scoped methods to prevent symbol-less use.

## 7.0.2

* [kotlin] Fixes a missed casting of not nullable Dart 'int' to Kotlin 64bit long.
Expand Down
10 changes: 5 additions & 5 deletions packages/pigeon/lib/cpp_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -849,17 +849,17 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
indent.write('switch (type) ');
indent.addScoped('{', '}', () {
for (final EnumeratedClass customClass in getCodecClasses(api, root)) {
indent.write('case ${customClass.enumeration}:');
indent.writeScoped('', '', () {
indent.writeln('case ${customClass.enumeration}:');
indent.nest(1, () {
indent.writeln(
'return flutter::CustomEncodableValue(${customClass.name}(std::get<flutter::EncodableList>(ReadValue(stream))));');
});
}
indent.write('default:');
indent.writeScoped('', '', () {
indent.writeln('default:');
indent.nest(1, () {
indent.writeln(
'return $_defaultCodecSerializer::ReadValueOfType(type, stream);');
}, addTrailingNewline: false);
});
});
});
indent.newln();
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/lib/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ void _writeCodec(Indent indent, String codecName, Api api, Root root) {
indent.write('switch (type) ');
indent.addScoped('{', '}', () {
for (final EnumeratedClass customClass in codecClasses) {
indent.write('case ${customClass.enumeration}: ');
indent.writeScoped('', '', () {
indent.writeln('case ${customClass.enumeration}: ');
indent.nest(1, () {
indent.writeln(
'return ${customClass.name}.decode(readValue(buffer)!);');
});
Expand Down
27 changes: 18 additions & 9 deletions packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'dart:mirrors';

import 'ast.dart';

/// The current version of pigeon. This must match the version in pubspec.yaml.
const String pigeonVersion = '7.0.2';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '7.0.3';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down Expand Up @@ -81,15 +83,18 @@ class Indent {
}
}

/// Scoped increase of the ident level. For the execution of [func] the
/// indentation will be incremented.
/// Scoped increase of the indent level.
///
/// For the execution of [func] the indentation will be incremented.
void addScoped(
String? begin,
String? end,
Function func, {
bool addTrailingNewline = true,
int nestCount = 1,
}) {
assert(begin != '' || end != '',
'Use nest for indentation without any decoration');
if (begin != null) {
_sink.write(begin + newline);
}
Expand All @@ -109,12 +114,15 @@ class Indent {
Function func, {
bool addTrailingNewline = true,
}) {
assert(begin != '' || end != '',
'Use nest for indentation without any decoration');
addScoped(str() + (begin ?? ''), end, func,
addTrailingNewline: addTrailingNewline);
}

/// Scoped increase of the ident level. For the execution of [func] the
/// indentation will be incremented by the given amount.
/// Scoped increase of the indent level.
///
/// For the execution of [func] the indentation will be incremented by the given amount.
void nest(int count, Function func) {
inc(count);
func(); // ignore: avoid_dynamic_calls
Expand Down Expand Up @@ -270,9 +278,10 @@ void addLines(Indent indent, Iterable<String> lines, {String? linePrefix}) {
}
}

/// Recursively merges [modification] into [base]. In other words, whenever
/// there is a conflict over the value of a key path, [modification]'s value for
/// that key path is selected.
/// Recursively merges [modification] into [base].
///
/// In other words, whenever there is a conflict over the value of a key path,
/// [modification]'s value for that key path is selected.
Map<String, Object> mergeMaps(
Map<String, Object> base,
Map<String, Object> modification,
Expand Down
10 changes: 5 additions & 5 deletions packages/pigeon/lib/java_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -717,16 +717,16 @@ Result<$returnType> $resultName =
indent.write('switch (type) ');
indent.addScoped('{', '}', () {
for (final EnumeratedClass customClass in codecClasses) {
indent.write('case (byte) ${customClass.enumeration}: ');
indent.writeScoped('', '', () {
indent.writeln('case (byte) ${customClass.enumeration}:');
indent.nest(1, () {
indent.writeln(
'return ${customClass.name}.fromList((ArrayList<Object>) readValue(buffer));');
});
}
indent.write('default:');
indent.addScoped('', '', () {
indent.writeln('default:');
indent.nest(1, () {
indent.writeln('return super.readValueOfType(type, buffer);');
}, addTrailingNewline: false);
});
});
});
indent.newln();
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/lib/objc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
indent.write('switch (type) ');
indent.addScoped('{', '}', () {
for (final EnumeratedClass customClass in codecClasses) {
indent.write('case ${customClass.enumeration}: ');
indent.writeScoped('', '', () {
indent.writeln('case ${customClass.enumeration}: ');
indent.nest(1, () {
indent.writeln(
'return [${_className(options.prefix, customClass.name)} fromList:[self readValue]];');
});
Expand Down
9 changes: 1 addition & 8 deletions packages/pigeon/mock_handler_tester/test/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down Expand Up @@ -146,10 +146,8 @@ class _MessageApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return MessageSearchReply.decode(readValue(buffer)!);

case 129:
return MessageSearchRequest.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -245,13 +243,10 @@ class _MessageNestedApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return MessageNested.decode(readValue(buffer)!);

case 129:
return MessageSearchReply.decode(readValue(buffer)!);

case 130:
return MessageSearchRequest.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -320,10 +315,8 @@ class _MessageFlutterSearchApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return MessageSearchReply.decode(readValue(buffer)!);

case 129:
return MessageSearchRequest.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down
7 changes: 1 addition & 6 deletions packages/pigeon/mock_handler_tester/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
// ignore_for_file: avoid_relative_lib_imports
Expand Down Expand Up @@ -34,10 +34,8 @@ class _TestHostApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return MessageSearchReply.decode(readValue(buffer)!);

case 129:
return MessageSearchRequest.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -119,13 +117,10 @@ class _TestNestedApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return MessageNested.decode(readValue(buffer)!);

case 129:
return MessageSearchReply.decode(readValue(buffer)!);

case 130:
return MessageSearchRequest.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.alternate_language_test_plugin;
Expand Down Expand Up @@ -724,13 +724,10 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return AllNullableTypes.fromList((ArrayList<Object>) readValue(buffer));

case (byte) 129:
return AllNullableTypesWrapper.fromList((ArrayList<Object>) readValue(buffer));

case (byte) 130:
return AllTypes.fromList((ArrayList<Object>) readValue(buffer));

default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -2139,13 +2136,10 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
switch (type) {
case (byte) 128:
return AllNullableTypes.fromList((ArrayList<Object>) readValue(buffer));

case (byte) 129:
return AllNullableTypesWrapper.fromList((ArrayList<Object>) readValue(buffer));

case (byte) 130:
return AllTypes.fromList((ArrayList<Object>) readValue(buffer));

default:
return super.readValueOfType(type, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "CoreTests.gen.h"
Expand Down Expand Up @@ -221,13 +221,10 @@ - (nullable id)readValueOfType:(UInt8)type {
switch (type) {
case 128:
return [AllNullableTypes fromList:[self readValue]];

case 129:
return [AllNullableTypesWrapper fromList:[self readValue]];

case 130:
return [AllTypes fromList:[self readValue]];

default:
return [super readValueOfType:type];
}
Expand Down Expand Up @@ -1136,13 +1133,10 @@ - (nullable id)readValueOfType:(UInt8)type {
switch (type) {
case 128:
return [AllNullableTypes fromList:[self readValue]];

case 129:
return [AllNullableTypesWrapper fromList:[self readValue]];

case 130:
return [AllTypes fromList:[self readValue]];

default:
return [super readValueOfType:type];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down Expand Up @@ -222,13 +222,10 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return AllNullableTypes.decode(readValue(buffer)!);

case 129:
return AllNullableTypesWrapper.decode(readValue(buffer)!);

case 130:
return AllTypes.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -1253,13 +1250,10 @@ class _FlutterIntegrationCoreApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return AllNullableTypes.decode(readValue(buffer)!);

case 129:
return AllNullableTypesWrapper.decode(readValue(buffer)!);

case 130:
return AllTypes.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down Expand Up @@ -127,16 +127,12 @@ class _ApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return FlutterSearchReplies.decode(readValue(buffer)!);

case 129:
return FlutterSearchReply.decode(readValue(buffer)!);

case 130:
return FlutterSearchRequest.decode(readValue(buffer)!);

case 131:
return FlutterSearchRequests.decode(readValue(buffer)!);

default:
return super.readValueOfType(type, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// Autogenerated from Pigeon (v7.0.3), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Loading