Skip to content

Commit

Permalink
null safe cleanup (google#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Jul 26, 2021
1 parent 6afeb0a commit 8571b58
Show file tree
Hide file tree
Showing 64 changed files with 915 additions and 644 deletions.
363 changes: 164 additions & 199 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api_benchmark/compile_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
rm -rf lib/generated
mkdir lib/generated
protoc --dart_out=lib/generated --plugin=protoc-gen-dart=run_protoc_plugin.sh -Iprotos protos/*.proto
dartfmt -w lib/generated
dart format lib/generated
5 changes: 3 additions & 2 deletions api_benchmark/lib/dashboard_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ library protoc.benchmark.html_view;
import 'dart:async' show Stream, StreamController, EventSink;
import 'dart:html';

import 'generated/benchmark.pb.dart' as pb;
import 'package:api_benchmark/dashboard_model.dart';
import 'package:api_benchmark/report.dart' show encodeReport;

import 'generated/benchmark.pb.dart' as pb;

/// A dashboard allowing the user to run a benchmark suite and compare the
/// results to any saved report.
class DashboardView {
Expand Down Expand Up @@ -235,7 +236,7 @@ class _JsonView {
class _Menu {
final SelectElement elt;
final _changes = StreamController<String>.broadcast();
final _options = List<_MenuOption>();
final _options = <_MenuOption>[];

_Menu(this.elt) {
elt.onChange.listen((e) => _changes.add(elt.value));
Expand Down
4 changes: 3 additions & 1 deletion api_benchmark/lib/suite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
library protoc.benchmark.suite;

import 'package:api_benchmark/benchmark.dart';
import 'package:protobuf/protobuf.dart';

import 'benchmarks/index.dart' show createBenchmark;
import 'generated/benchmark.pb.dart' as pb;

Expand All @@ -31,7 +33,7 @@ Iterable<pb.Report> runSuite(List<pb.Request> requests,
}
pb.Report progress() {
report.message = "Running ($sampleCount/$totalSamples)";
return report.clone();
return report.deepCopy();
}

// Send first progress message before starting.
Expand Down
4 changes: 2 additions & 2 deletions api_benchmark/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ stages:
- group:
- command: ./../tool/setup.sh
- command: ./compile_protos.sh
- dartfmt
- dartanalyzer: --fatal-warnings .
- format
- analyze: --fatal-infos
dart: [dev]
12 changes: 6 additions & 6 deletions api_benchmark/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ name: api_benchmark
description: Benchmarking a number of different api calls.

environment:
sdk: '>=2.3.0 <3.0.0'
sdk: '>=2.11.99 <3.0.0'

dependencies:
protobuf:

dev_dependencies:
build: ^1.0.0
build_runner: ^1.0.0
build_web_compilers: ^2.0.0
glob: ^1.1.7
yaml: ^2.1.15
build: ^2.0.0
build_runner: ^2.0.6
build_web_compilers: ^3.0.0
glob: ^2.0.0
yaml: ^3.0.0
protoc_plugin:
path: "../protoc_plugin"

Expand Down
3 changes: 1 addition & 2 deletions mono_repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ github:
- cron: "0 0 * * 0"

merge_stages:
- format
- analyze
- format_analyze
- run_tests
4 changes: 2 additions & 2 deletions protobuf/benchmarks/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Factories {
final FromJsonFactory fromJson;

static Factories forMessage(String name) =>
_factories[name] ?? (throw 'Unsupported message: ${name}');
_factories[name] ?? (throw 'Unsupported message: $name');

/// Mapping between [BenchmarkProto.messageName] and corresponding
/// deserialization factories.
Expand All @@ -93,7 +93,7 @@ class Factories {
fromJson: (String json) => GoogleMessage4.fromJson(json)),
};

Factories._({this.fromBuffer, this.fromJson});
Factories._({required this.fromBuffer, required this.fromJson});
}

/// Base for all protobuf benchmarks.
Expand Down
2 changes: 1 addition & 1 deletion protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ class _FieldSet {
if (map != null) {
_values[index] = (fieldInfo as MapFieldInfo)
._createMapField(_message!)
..addAll(map);
..addAll(map);
}
} else if (fieldInfo.isRepeated) {
PbListBase? list = _values[index];
Expand Down
8 changes: 3 additions & 5 deletions protobuf/mono_pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
# - test stage runs for all oses and all sdks

stages:
- format:
- group: [dartfmt]
dart: [dev]
- analyze:
- format_analyze:
- group:
- dartanalyzer: --fatal-infos --fatal-warnings lib test
- format
- analyze: --fatal-infos
dart: [dev]
- run_tests:
- group: [test]
Expand Down
4 changes: 2 additions & 2 deletions protoc_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $(TEST_PROTO_LIBS): $(PLUGIN_PATH) $(TEST_PROTO_SRCS)
-I$(TEST_PROTO_SRC_DIR)\
--plugin=protoc-gen-dart=$(realpath $(PLUGIN_PATH))\
$(TEST_PROTO_SRCS)
dartfmt -w $(TEST_PROTO_DIR)
dart format $(TEST_PROTO_DIR)

build-plugin: $(PLUGIN_PATH)

Expand All @@ -90,7 +90,7 @@ update-pregenerated: $(PLUGIN_PATH) $(PREGENERATED_SRCS)
rm lib/src/descriptor.pb{json,server}.dart
rm lib/src/dart_options.pb{enum,json,server}.dart
rm lib/src/plugin.pb{json,server}.dart
dartfmt -w lib/src
dart format lib/src

protos: $(PLUGIN_PATH) $(TEST_PROTO_LIBS)

Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/client_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ClientApiGenerator {
'$_protobufImportPrefix.ClientContext? ctx, $inputType request) {',
'}', () {
out.println('var emptyResponse = $outputType();');
out.println('return _client.invoke<$outputType>(ctx, \'${className}\', '
out.println('return _client.invoke<$outputType>(ctx, \'$className\', '
'\'${m.name}\', request, emptyResponse);');
});
}
Expand Down
2 changes: 0 additions & 2 deletions protoc_plugin/lib/const_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.11

library protoc.const_generator;

import "indenting_writer.dart";
Expand Down
21 changes: 10 additions & 11 deletions protoc_plugin/lib/enum_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class EnumGenerator extends ProtobufContainer {

void generate(IndentingWriter out) {
out.addAnnotatedBlock(
'class ${classname} extends $_protobufImportPrefix.ProtobufEnum {',
'class $classname extends $_protobufImportPrefix.ProtobufEnum {',
'}\n', [
NamedLocation(
name: classname, fieldPathSegment: fieldPath, start: 'class '.length)
Expand All @@ -117,14 +117,14 @@ class EnumGenerator extends ProtobufContainer {
final conditionalValName = configurationDependent(
'protobuf.omit_enum_names', quoted(val.name));
out.printlnAnnotated(
'static const ${classname} $name = '
'${classname}._(${val.number}, $conditionalValName);',
'static const $classname $name = '
'$classname._(${val.number}, $conditionalValName);',
[
NamedLocation(
name: name,
fieldPathSegment: List.from(fieldPath)
..addAll([_enumValueTag, _originalCanonicalIndices[i]]),
start: 'static const ${classname} '.length)
start: 'static const $classname '.length)
]);
}
if (_aliases.isNotEmpty) {
Expand All @@ -133,21 +133,21 @@ class EnumGenerator extends ProtobufContainer {
var alias = _aliases[i];
final name = dartNames[alias.value.name];
out.printlnAnnotated(
'static const ${classname} $name ='
'static const $classname $name ='
' ${dartNames[alias.canonicalValue.name]};',
[
NamedLocation(
name: name,
fieldPathSegment: List.from(fieldPath)
..addAll([_enumValueTag, _originalAliasIndices[i]]),
start: 'static const ${classname} '.length)
start: 'static const $classname '.length)
]);
}
}
out.println();

out.println('static const $_coreImportPrefix.List<${classname}> values ='
' <${classname}> [');
out.println('static const $_coreImportPrefix.List<$classname> values ='
' <$classname> [');
for (var val in _canonicalValues) {
final name = dartNames[val.name];
out.println(' $name,');
Expand All @@ -158,13 +158,12 @@ class EnumGenerator extends ProtobufContainer {
out.println(
'static final $_coreImportPrefix.Map<$_coreImportPrefix.int, $classname> _byValue ='
' $_protobufImportPrefix.ProtobufEnum.initByValue(values);');
out.println(
'static ${classname}? valueOf($_coreImportPrefix.int value) =>'
out.println('static $classname? valueOf($_coreImportPrefix.int value) =>'
' _byValue[value];');
out.println();

out.println(
'const ${classname}._($_coreImportPrefix.int v, $_coreImportPrefix.String n) '
'const $classname._($_coreImportPrefix.int v, $_coreImportPrefix.String n) '
': super(v, n);');
});
}
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 @@ -401,7 +401,7 @@ class FileGenerator extends ProtobufContainer {
.map((mixin) => mixin.importFrom)
.toSet()
.toList(growable: false)
..sort();
..sort();
}

/// Returns the contents of the .pbenum.dart file for this .proto file.
Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/grpc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class GrpcServiceGenerator {
if (mg == null) {
var location = _undefinedDeps[fqname];
// TODO(nichite): Throw more actionable error.
throw 'FAILURE: Unknown type reference (${fqname}) for ${location}';
throw 'FAILURE: Unknown type reference ($fqname) for $location';
}
return mg.fileImportPrefix + '.' + mg.classname;
}
Expand Down
13 changes: 7 additions & 6 deletions protoc_plugin/lib/indenting_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.11

library protoc.indenting_writer;

import 'src/descriptor.pb.dart';
Expand All @@ -14,7 +12,10 @@ class NamedLocation {
final String name;
final List<int> fieldPathSegment;
final int start;
NamedLocation({this.name, this.fieldPathSegment, this.start});
NamedLocation(
{required this.name,
required this.fieldPathSegment,
required this.start});
}

/// A buffer for writing indented source code.
Expand All @@ -26,9 +27,9 @@ class IndentingWriter {
// After writing any chunk, _previousOffset is the size of everything that was
// written to the buffer before the latest call to print or addBlock.
int _previousOffset = 0;
final String _sourceFile;
final String? _sourceFile;

IndentingWriter({String filename}) : _sourceFile = filename;
IndentingWriter({String? filename}) : _sourceFile = filename;

/// Appends a string indented to the current level.
/// (Indentation will be added after newline characters where needed.)
Expand Down Expand Up @@ -133,7 +134,7 @@ class IndentingWriter {
}
var annotation = GeneratedCodeInfo_Annotation()
..path.addAll(fieldPath)
..sourceFile = _sourceFile
..sourceFile = _sourceFile!
..begin = _previousOffset + start
..end = _previousOffset + start + name.length;
sourceLocationInfo.annotation.add(annotation);
Expand Down
Loading

0 comments on commit 8571b58

Please sign in to comment.