Skip to content

Commit

Permalink
Use @Dart = 2.7 in generated files (google#455)
Browse files Browse the repository at this point in the history
* Use @Dart = 2.7 in genereted files

* More in changelog

* Fix goldens

* Fix lints

* Fix more lints
  • Loading branch information
sigurdm authored Jan 5, 2021
1 parent 7ac17d0 commit 27d382d
Show file tree
Hide file tree
Showing 26 changed files with 773 additions and 62 deletions.
4 changes: 2 additions & 2 deletions protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class _FieldSet {

static List _makeValueList(int length) {
if (length == 0) return _zeroList;
return List(length);
return List.filled(length, null, growable: false);
}

// Use a fixed length list and not a constant list to ensure that _values
// always has the same implementation type.
static final List _zeroList = List(0);
static final List _zeroList = [];

// Metadata about multiple fields

Expand Down
4 changes: 4 additions & 0 deletions protoc_plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 19.3.0

* Generate constructors with optional named arguments for prefilling fields.
* Output language version 2.7 in generated files to support extension methods.
## 19.2.1

* Support optional proto3 fields.
Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/file_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class FileGenerator extends ProtobufContainer {
// Generated code. Do not modify.
// source: ${descriptor.name}
//
// @dart = 2.3
// @dart = 2.7
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields
''');
}
Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ MemberNames messageMemberNames(DescriptorProto descriptor,

var existingNames = <String>{}..addAll(reservedMemberNames)..addAll(reserved);

var fieldNames = List<FieldNames>(indexes.length);
var fieldNames = List<FieldNames>.filled(indexes.length, null);

void takeFieldNames(FieldNames chosen) {
fieldNames[chosen.index] = chosen;
Expand Down
30 changes: 27 additions & 3 deletions protoc_plugin/lib/src/dart_options.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Generated code. Do not modify.
// source: dart_options.proto
//
// @dart = 2.3
// @dart = 2.7
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields

import 'dart:core' as $core;
Expand Down Expand Up @@ -37,7 +37,23 @@ class DartMixin extends $pb.GeneratedMessage {
..hasRequiredFields = false;

DartMixin._() : super();
factory DartMixin() => create();
factory DartMixin({
$core.String name,
$core.String importFrom,
$core.String parent,
}) {
final _result = create();
if (name != null) {
_result.name = name;
}
if (importFrom != null) {
_result.importFrom = importFrom;
}
if (parent != null) {
_result.parent = parent;
}
return _result;
}
factory DartMixin.fromBuffer($core.List<$core.int> i,
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
create()..mergeFromBuffer(i, r);
Expand Down Expand Up @@ -121,7 +137,15 @@ class Imports extends $pb.GeneratedMessage {
..hasRequiredFields = false;

Imports._() : super();
factory Imports() => create();
factory Imports({
$core.Iterable<DartMixin> mixins,
}) {
final _result = create();
if (mixins != null) {
_result.mixins.addAll(mixins);
}
return _result;
}
factory Imports.fromBuffer($core.List<$core.int> i,
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
create()..mergeFromBuffer(i, r);
Expand Down
Loading

0 comments on commit 27d382d

Please sign in to comment.