OLD | NEW |
(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 DynamicGeneratedMessage extends GeneratedMessage { |
| 10 |
| 11 /** |
| 12 * Implement getXxx and hasXxx methods dynamically. |
| 13 */ |
| 14 Dynamic noSuchMethod(String name, List args) { |
| 15 if (name.startsWith("get:")) { |
| 16 int tagNumber = getTagNumber(name.substring(4)); |
| 17 if (tagNumber != null) { |
| 18 return getField(tagNumber); |
| 19 } |
| 20 } else if (name.startsWith("has") && name.length > 3) { |
| 21 String fieldName = "${name[3].toLowerCase()}${name.substring(4)}"; |
| 22 int tagNumber = getTagNumber(fieldName); |
| 23 if (tagNumber != null) { |
| 24 return hasField(tagNumber); |
| 25 } |
| 26 } |
| 27 throw "NoSuchMethod: $name"; |
| 28 } |
| 29 } |
OLD | NEW |