Skip to content

Commit

Permalink
Create ProtobufEnum reserved names (google#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias authored Sep 6, 2018
1 parent cd7653b commit c8602c8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.2

* Added ProtobufEnum reserved names.

## 0.10.1

* Added Support for [any](https://developers.google.com/protocol-buffers/docs/proto3#any) messages.
Expand Down
18 changes: 15 additions & 3 deletions lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// 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.

/// Provides metadata about GeneratedMessage to dart-protoc-plugin.
/// (Experimental API; subject to change.)
/// Provides metadata about GeneratedMessage and ProtobufEnum to
/// dart-protoc-plugin. (Experimental API; subject to change.)
library protobuf.meta;

// List of names which cannot be used in a subclass of GeneratedMessage.
const List<String> GeneratedMessage_reservedNames = const [
const GeneratedMessage_reservedNames = const <String>[
'hashCode',
'noSuchMethod',
'copyWith',
Expand Down Expand Up @@ -68,3 +68,15 @@ const List<String> GeneratedMessage_reservedNames = const [
'toBuilder',
'toDebugString',
];

// List of names which cannot be used in a subclass of ProtobufEnum.
const ProtobufEnum_reservedNames = const <String>[
'==',
'Object',
'ProtobufEnum',
'hashCode',
'initByValue',
'noSuchMethod',
'runtimeType',
'toString'
];
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: protobuf
version: 0.10.1
version: 0.10.2
author: Dart Team <[email protected]>
description: Runtime library for protocol buffers support.
homepage: https://github.com/dart-lang/protobuf
Expand Down
13 changes: 11 additions & 2 deletions test/reserved_names_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ library reserved_names_test;

import 'package:test/test.dart';

import 'package:protobuf/meta.dart' show GeneratedMessage_reservedNames;
import 'package:protobuf/meta.dart'
show GeneratedMessage_reservedNames, ProtobufEnum_reservedNames;
import 'package:protobuf/mixins_meta.dart' show findMixin;

import 'mirror_util.dart' show findMemberNames;

// Import the libraries we will access via the mirrors.
// ignore_for_file: unused_import
import 'package:protobuf/protobuf.dart' show GeneratedMessage;
import 'package:protobuf/protobuf.dart' show GeneratedMessage, ProtobufEnum;
import 'package:protobuf/src/protobuf/mixins/event_mixin.dart'
show PbEventMixin;
import 'package:protobuf/src/protobuf/mixins/map_mixin.dart' show PbMapMixin;
Expand All @@ -32,6 +33,14 @@ void main() {
expect(actual.toList()..sort(), equals(expected.toList()..sort()));
});

test('ProtobufEnum reserved names are up to date', () {
var actual = new Set<String>.from(ProtobufEnum_reservedNames);
var expected =
findMemberNames('package:protobuf/protobuf.dart', #ProtobufEnum);

expect(actual.toList()..sort(), equals(expected.toList()..sort()));
});

test("ReadonlyMessageMixin doesn't add any reserved names", () {
var mixinNames = findMemberNames(
'package:protobuf/protobuf.dart', #ReadonlyMessageMixin);
Expand Down

0 comments on commit c8602c8

Please sign in to comment.