[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
This commit is contained in:
Tarrin Neal
2023-01-23 15:19:16 -08:00
committed by GitHub
parent 86b21ee05a
commit 55294efc3b
25 changed files with 55 additions and 98 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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)!);');
});

View File

@ -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() {
@ -81,8 +83,9 @@ 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,
@ -90,6 +93,8 @@ class Indent {
bool addTrailingNewline = true,
int nestCount = 1,
}) {
assert(begin != '' || end != '',
'Use nest for indentation without any decoration');
if (begin != null) {
_sink.write(begin + newline);
}
@ -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
@ -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,

View File

@ -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();

View File

@ -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]];');
});

View File

@ -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
@ -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);
}
@ -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);
}
@ -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);
}

View File

@ -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
@ -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);
}
@ -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);
}

View File

@ -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;
@ -724,13 +724,10 @@ public class CoreTests {
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);
}
@ -2139,13 +2136,10 @@ public class CoreTests {
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);
}

View File

@ -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>

View File

@ -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"
@ -221,13 +221,10 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
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];
}
@ -1136,13 +1133,10 @@ void HostIntegrationCoreApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
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];
}

View File

@ -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
@ -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);
}
@ -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);
}

View File

@ -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
@ -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);
}

View File

@ -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

View File

@ -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
@ -128,13 +128,10 @@ class _NonNullFieldHostApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return ExtraData.decode(readValue(buffer)!);
case 129:
return NonNullFieldSearchReply.decode(readValue(buffer)!);
case 130:
return NonNullFieldSearchRequest.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}
@ -203,13 +200,10 @@ class _NonNullFieldFlutterApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return ExtraData.decode(readValue(buffer)!);
case 129:
return NonNullFieldSearchReply.decode(readValue(buffer)!);
case 130:
return NonNullFieldSearchRequest.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}

View File

@ -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
@ -108,10 +108,8 @@ class _NullFieldsHostApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return NullFieldsSearchReply.decode(readValue(buffer)!);
case 129:
return NullFieldsSearchRequest.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}
@ -177,10 +175,8 @@ class _NullFieldsFlutterApiCodec extends StandardMessageCodec {
switch (type) {
case 128:
return NullFieldsSearchReply.decode(readValue(buffer)!);
case 129:
return NullFieldsSearchRequest.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}

View File

@ -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

View File

@ -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

View File

@ -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
@ -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);
}
@ -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);
}

View File

@ -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.test_plugin

View File

@ -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

View File

@ -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

View File

@ -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
#undef _HAS_EXCEPTIONS
@ -488,15 +488,12 @@ flutter::EncodableValue HostIntegrationCoreApiCodecSerializer::ReadValueOfType(
case 128:
return flutter::CustomEncodableValue(AllNullableTypes(
std::get<flutter::EncodableList>(ReadValue(stream))));
case 129:
return flutter::CustomEncodableValue(AllNullableTypesWrapper(
std::get<flutter::EncodableList>(ReadValue(stream))));
case 130:
return flutter::CustomEncodableValue(
AllTypes(std::get<flutter::EncodableList>(ReadValue(stream))));
default:
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
}
@ -1960,15 +1957,12 @@ FlutterIntegrationCoreApiCodecSerializer::ReadValueOfType(
case 128:
return flutter::CustomEncodableValue(AllNullableTypes(
std::get<flutter::EncodableList>(ReadValue(stream))));
case 129:
return flutter::CustomEncodableValue(AllNullableTypesWrapper(
std::get<flutter::EncodableList>(ReadValue(stream))));
case 130:
return flutter::CustomEncodableValue(
AllTypes(std::get<flutter::EncodableList>(ReadValue(stream))));
default:
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
}

View File

@ -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
#ifndef PIGEON_CORE_TESTS_GEN_H_

View File

@ -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%3Apigeon
version: 7.0.2 # This must match the version in lib/generator_tools.dart
version: 7.0.3 # This must match the version in lib/generator_tools.dart
environment:
sdk: ">=2.12.0 <3.0.0"