|
| 1 | +// Copyright (c) 2015, Google Inc. Please see the AUTHORS file for details. |
| 2 | +// All rights reserved. Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +library built_value; |
| 6 | + |
| 7 | +export 'package:quiver/core.dart' show hashObjects; |
| 8 | + |
| 9 | +/// Implement this for a Built Value. |
| 10 | +/// |
| 11 | +/// Then use built_value_generator.dart code generation functionality to |
| 12 | +/// provide the rest of the implementation. |
| 13 | +/// |
| 14 | +/// See <https://github.com/google/built_value.dart/tree/master/example> |
| 15 | +abstract class Built<V extends Built<V, B>, B extends Builder<V, B>> { |
| 16 | + /// Rebuilds the instance. |
| 17 | + /// |
| 18 | + /// The result is the same as this instance but with [updates] applied. |
| 19 | + /// [updates] is a function that takes a builder [B]. |
| 20 | + /// |
| 21 | + /// The implementation of this method will be generated for you by the |
| 22 | + /// built_value generator. |
| 23 | + V rebuild(updates(B builder)); |
| 24 | + |
| 25 | + /// Converts the instance to a builder [B]. |
| 26 | + /// |
| 27 | + /// The implementation of this method will be generated for you by the |
| 28 | + /// built_value generator. |
| 29 | + B toBuilder(); |
| 30 | +} |
| 31 | + |
| 32 | +/// Every Built Value must have a [Builder] class. |
| 33 | +/// |
| 34 | +/// Use it to set defaults, if needed, and to do validation. |
| 35 | +/// |
| 36 | +/// See <https://github.com/google/built_value.dart/tree/master/example> |
| 37 | +abstract class Builder<V extends Built<V, B>, B extends Builder<V, B>> { |
| 38 | + /// Replaces the value in the builder with a new one. |
| 39 | + /// |
| 40 | + /// The implementation of this method will be generated for you by the |
| 41 | + /// built_value generator. |
| 42 | + void replace(V value); |
| 43 | + |
| 44 | + /// Applies updates. |
| 45 | + /// |
| 46 | + /// [updates] is a function that takes a builder [B]. |
| 47 | + void update(updates(B builder)); |
| 48 | + |
| 49 | + /// Builds. |
| 50 | + /// |
| 51 | + /// The implementation of this method will be generated for you by the |
| 52 | + /// built_value generator. |
| 53 | + /// |
| 54 | + /// Override this method to add validation at build time. |
| 55 | + V build(); |
| 56 | +} |
| 57 | + |
| 58 | +// Nullable annotation for Built Value fields. |
| 59 | +// |
| 60 | +// Fields marked with this annotation are allowed to be null. |
| 61 | +const String nullable = 'nullable'; |
0 commit comments