Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: lib/message_generator.dart

Issue 210843002: Include the Dart reserved words in the reserved names handling (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: Minor fix Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/generated_message_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of protoc; 5 part of protoc;
6 6
7 const String SP = ' '; 7 const String SP = ' ';
8 8
9 class MessageGenerator extends ProtobufContainer { 9 class MessageGenerator extends ProtobufContainer {
10 // List of Dart language reserved words in names which cannot be used in a
11 // subclass of GeneratedMessage.
12 static final List<String> reservedWords =
13 ['assert', 'break', 'case', 'catch', 'class', 'const', 'continue',
14 'default', 'do', 'else', 'enum', 'extends', 'false', 'final',
15 'finally', 'for', 'if', 'in', 'is', 'new', 'null', 'rethrow', 'return',
16 'super', 'switch', 'this', 'throw', 'true', 'try', 'var', 'void',
17 'while', 'with'];
18
10 // List of names which cannot be used in a subclass of GeneratedMessage. 19 // List of names which cannot be used in a subclass of GeneratedMessage.
11 static final List<String> reservedNames = 20 static final List<String> reservedNames =
12 ['hashCode', 'noSuchMethod','runtimeType', 'toString', 21 ['hashCode', 'noSuchMethod','runtimeType', 'toString',
13 'fromBuffer', 'fromJson', 'hasRequiredFields', 'isInitialized', 22 'fromBuffer', 'fromJson', 'hasRequiredFields', 'isInitialized',
14 'clear', 'getTagNumber', 'check', 23 'clear', 'getTagNumber', 'check',
15 'writeToBuffer', 'writeToCodedBufferWriter', 24 'writeToBuffer', 'writeToCodedBufferWriter',
16 'mergeFromCodedBufferReader', 'mergeFromBuffer', 25 'mergeFromCodedBufferReader', 'mergeFromBuffer',
17 'writeToJson', 'mergeFromJson', 26 'writeToJson', 'mergeFromJson',
18 'addExtension', 'getExtension', 'setExtension', 27 'addExtension', 'getExtension', 'setExtension',
19 'hasExtension', 'clearExtension', 28 'hasExtension', 'clearExtension',
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 for (FieldDescriptorProto field in _descriptor.field) { 72 for (FieldDescriptorProto field in _descriptor.field) {
64 _fieldList.add(new ProtobufField(field, this, _context)); 73 _fieldList.add(new ProtobufField(field, this, _context));
65 } 74 }
66 for (MessageGenerator m in _messageGenerators) { 75 for (MessageGenerator m in _messageGenerators) {
67 m.initializeFields(); 76 m.initializeFields();
68 } 77 }
69 } 78 }
70 79
71 void generate(IndentingWriter out) { 80 void generate(IndentingWriter out) {
72 _methodNames.clear(); 81 _methodNames.clear();
82 _methodNames.addAll(reservedWords);
73 _methodNames.addAll(reservedNames); 83 _methodNames.addAll(reservedNames);
74 84
75 for (EnumGenerator e in _enumGenerators) { 85 for (EnumGenerator e in _enumGenerators) {
76 e.generate(out); 86 e.generate(out);
77 } 87 }
78 88
79 for (MessageGenerator m in _messageGenerators) { 89 for (MessageGenerator m in _messageGenerators) {
80 m.generate(out); 90 m.generate(out);
81 } 91 }
82 92
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 '(${fieldTypeString} v)${SP}' 250 '(${fieldTypeString} v)${SP}'
241 '{${SP}setField(${field.number},${SP}v);${SP}}'); 251 '{${SP}setField(${field.number},${SP}v);${SP}}');
242 out.println('bool $hasIdentifier()${SP}=>' 252 out.println('bool $hasIdentifier()${SP}=>'
243 '${SP}hasField(${field.number});'); 253 '${SP}hasField(${field.number});');
244 out.println('void $clearIdentifier()${SP}=>' 254 out.println('void $clearIdentifier()${SP}=>'
245 '${SP}clearField(${field.number});'); 255 '${SP}clearField(${field.number});');
246 } 256 }
247 } 257 }
248 } 258 }
249 } 259 }
OLDNEW
« no previous file with comments | « no previous file | test/generated_message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698