Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Fix issues with reserved names
Browse files Browse the repository at this point in the history
- Get GeneratedMessage reserved names from the protobuf package.
- reserve "create" and "createRepeated" to avoid a conflict.

BUG=#46
[email protected]

Review URL: https://chromiumcodereview.appspot.com//1225573004.
  • Loading branch information
Brian Slesinsky committed Jul 7, 2015
1 parent f33e6e8 commit bee0817
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 62 deletions.
20 changes: 5 additions & 15 deletions lib/message_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,9 @@ class MessageGenerator extends ProtobufContainer {
'super', 'switch', 'this', 'throw', 'true', 'try', 'var', 'void',
'while', 'with'];

// List of names which cannot be used in a subclass of GeneratedMessage.
static final List<String> reservedNames =
['hashCode', 'noSuchMethod','runtimeType', 'toString',
'fromBuffer', 'fromJson', 'hasRequiredFields', 'isInitialized',
'clear', 'getTagNumber', 'check',
'writeToBuffer', 'writeToCodedBufferWriter',
'mergeFromCodedBufferReader', 'mergeFromBuffer',
'writeToJson', 'mergeFromJson',
'writeToJsonMap', 'mergeFromJsonMap',
'addExtension', 'getExtension', 'setExtension',
'hasExtension', 'clearExtension',
'getField', 'setField', 'hasField', 'clearField',
'extensionsAreInitialized', 'mergeFromMessage', 'mergeUnknownFields',
'==', 'info_', 'GeneratedMessage', 'Object'];
// List of names used in the generated class itself
static final List<String> generatedNames =
['create', 'createRepeated'];

// Returns the mixin for this message, or null if none.
static PbMixin _getMixin(DescriptorProto desc, PbMixin defaultValue) {
Expand Down Expand Up @@ -110,7 +99,8 @@ class MessageGenerator extends ProtobufContainer {
void generate(IndentingWriter out) {
_methodNames.clear();
_methodNames.addAll(reservedWords);
_methodNames.addAll(reservedNames);
_methodNames.addAll(GeneratedMessage_reservedNames);
_methodNames.addAll(generatedNames);

if (mixin != null) {
_methodNames.addAll(mixin.findReservedNames());
Expand Down
1 change: 1 addition & 0 deletions lib/protoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ library protoc;
import 'dart:async';
import 'dart:io';

import 'package:protobuf/meta.dart';
import 'package:protobuf/protobuf.dart';
import 'package:protobuf/mixins_meta.dart';
import 'package:path/path.dart' as path;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: protoc_plugin
version: 0.3.10
version: 0.3.11
author: Dart Team <[email protected]>
description: Protoc compiler plugin to generate Dart code
homepage: https://github.com/dart-lang/dart-protoc-plugin
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
protobuf: '>=0.3.10 <0.4.0'
protobuf: '>=0.3.11 <0.4.0'
path: '>=1.0.0 <2.0.0'
dev_dependencies:
unittest: '>=0.9.0 <0.11.0'
2 changes: 0 additions & 2 deletions test/all_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'map_test.dart' as map_test;
import 'message_generator_test.dart' as mgt;
import 'message_test.dart' as mt;
import 'protoc_options_test.dart' as pot;
import 'reserved_names_test.dart' as rnt;
import 'service_test.dart' as st;
import 'service_generator_test.dart' as sgt;
import 'unknown_field_set_test.dart' as ufst;
Expand All @@ -37,7 +36,6 @@ void main() {
mgt.main();
mt.main();
pot.main();
rnt.main();
st.main();
sgt.main();
ufst.main();
Expand Down
4 changes: 4 additions & 0 deletions test/protos/duplicate_names_import.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ message M {
optional pkg1_pkg2.M m3 = 5;
optional pkg1_pkg2.M.M m3_m = 6;
}

message M2 {
optional int32 pkg1 = 1;
}
6 changes: 6 additions & 0 deletions test/protos/reserved_names.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ message ReservedNamesOptional {

// Other conflicts.
optional int32 hash_code_1 = 40;
optional int32 create = 41;
optional int32 create_repeated = 42;

optional int32 x = 50;
optional int32 has_x = 51;
Expand Down Expand Up @@ -86,6 +88,8 @@ message ReservedNamesRepeated {

// Other conflicts.
repeated int32 hash_code_1 = 40;
repeated int32 create = 41;
repeated int32 create_repeated = 42;

repeated int32 x = 50;
repeated int32 has_x = 51;
Expand Down Expand Up @@ -130,6 +134,8 @@ message ReservedNamesRequired {

// Other conflicts.
required int32 hash_code_1 = 40;
required int32 create = 41;
required int32 create_repeated = 42;

required int32 x = 50;
required int32 has_x = 51;
Expand Down
43 changes: 0 additions & 43 deletions test/reserved_names_test.dart

This file was deleted.

0 comments on commit bee0817

Please sign in to comment.