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

Side by Side Diff: lib/protobuf/runtime/DynamicBuilder.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 /**
6 * Provides an implementation of 'noSuchMethod' that may be used as a
7 * substitute for fixed getter and setter methods.
8 */
9 class DynamicBuilder extends Builder {
10
11 /**
12 * Implement getXxx, setXxx, and hasXxx methods dynamically.
13 */
14 Dynamic noSuchMethod(String name, List args) {
15 if (name.startsWith("get:")) {
16 int tagNumber = info_.tagNumber(name.substring(4));
17 if (tagNumber !== null) {
18 return getField(tagNumber);
19 }
20 } else if (name.startsWith("set:")) {
21 int tagNumber = info_.tagNumber(name.substring(4));
22 if (tagNumber !== null) {
23 setField(tagNumber, args[0]);
24 return;
25 }
26 } else if (name.startsWith("has") && name.length > 3) {
27 String fieldName = "${name[3].toLowerCase()}${name.substring(4)}";
28 int tagNumber = info_.tagNumber(fieldName);
29 if (tagNumber !== null) {
30 return hasField(tagNumber);
31 }
32 }
33 // Throw an exception like what would have occurred if not intercepted here
34 throw new NoSuchMethodException(this, name, args);
35 }
36 }
OLDNEW
« no previous file with comments | « lib/protobuf/runtime/CodedStreamReader.dart ('k') | lib/protobuf/runtime/DynamicGeneratedMessage.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698