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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/protobuf/runtime/CodedStreamReader.dart ('k') | lib/protobuf/runtime/DynamicGeneratedMessage.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/runtime/DynamicBuilder.dart
diff --git a/lib/protobuf/runtime/DynamicBuilder.dart b/lib/protobuf/runtime/DynamicBuilder.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b1711734f53f01493d4b0b3e5e172662225d64b7
--- /dev/null
+++ b/lib/protobuf/runtime/DynamicBuilder.dart
@@ -0,0 +1,36 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// 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 an implementation of 'noSuchMethod' that may be used as a
+ * substitute for fixed getter and setter methods.
+ */
+class DynamicBuilder extends Builder {
+
+ /**
+ * Implement getXxx, setXxx, and hasXxx methods dynamically.
+ */
+ Dynamic noSuchMethod(String name, List args) {
+ if (name.startsWith("get:")) {
+ int tagNumber = info_.tagNumber(name.substring(4));
+ if (tagNumber !== null) {
+ return getField(tagNumber);
+ }
+ } else if (name.startsWith("set:")) {
+ int tagNumber = info_.tagNumber(name.substring(4));
+ if (tagNumber !== null) {
+ setField(tagNumber, args[0]);
+ return;
+ }
+ } else if (name.startsWith("has") && name.length > 3) {
+ String fieldName = "${name[3].toLowerCase()}${name.substring(4)}";
+ int tagNumber = info_.tagNumber(fieldName);
+ if (tagNumber !== null) {
+ return hasField(tagNumber);
+ }
+ }
+ // Throw an exception like what would have occurred if not intercepted here
+ throw new NoSuchMethodException(this, name, args);
+ }
+}
« 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