Skip to content

Commit

Permalink
Merge pull request #11 from google/version-constraints-null-builders
Browse files Browse the repository at this point in the history
Support @nullable for fields using builders. Fix constraints for source_gen.
  • Loading branch information
davidmorgan committed Oct 23, 2015
2 parents 9dadf6f + 6d1f7df commit 6152dad
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.0.4

- Support @nullable for fields using builders.
- Fix constraints for source_gen.

## 0.0.3

- Allow static fields in value class.
Expand Down
2 changes: 1 addition & 1 deletion built_value/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: built_value
version: 0.0.3
version: 0.0.4
description: >
Value types with builders. This library is the runtime dependency.
authors:
Expand Down
4 changes: 2 additions & 2 deletions built_value_generator/lib/built_value_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class BuiltValueGenerator extends Generator {
result.writeln('void replace(${className} other) {');
result.writeln((fieldNames.map((name) {
return buildableFieldNames.contains(name)
? 'super.$name = other.$name.toBuilder();'
? 'super.$name = other.$name?.toBuilder();'
: 'super.$name = other.$name;';
})).join('\n'));
result.writeln('}');
Expand All @@ -316,7 +316,7 @@ class BuiltValueGenerator extends Generator {
final fieldName = field.displayName;

return buildableFieldNames.contains(fieldName)
? '$fieldName: $fieldName.build()'
? '$fieldName: $fieldName?.build()'
: '$fieldName: $fieldName';
}).join(', '));
result.write(');');
Expand Down
6 changes: 3 additions & 3 deletions built_value_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: built_value_generator
version: 0.0.3
version: 0.0.4
description: >
Value types with builders. This library is the dev dependency.
authors:
Expand All @@ -12,8 +12,8 @@ environment:
dependencies:
analyzer: '>=0.26.1 <1.0.0'
built_collection: '^1.0.0'
built_value: '^0.0.3'
source_gen: '>=0.4.3 <1.0.0'
built_value: '^0.0.4'
source_gen: '>=0.4.3 <0.5.0'
quiver: '>=0.21.0 <0.22.0'

dev_dependencies:
Expand Down
6 changes: 3 additions & 3 deletions example/lib/compound_value.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions example/lib/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class Value implements Built<Value, ValueBuilder> {
@nullable Object get anObject;
int get aDefaultInt;
BuiltList<int> get listOfInt;
@nullable BuiltSet<String> get setOfString;

int get youCanWriteDerivedGetters => anInt + aDefaultInt;

Expand All @@ -46,6 +47,7 @@ abstract class ValueBuilder implements Builder<Value, ValueBuilder> {
@nullable Object anObject;
int aDefaultInt = 7;
ListBuilder<int> listOfInt = new ListBuilder<int>();
@nullable SetBuilder<String> setOfString;

ValueBuilder._();
factory ValueBuilder() = _$ValueBuilder;
Expand Down
24 changes: 18 additions & 6 deletions example/lib/value.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: example
version: 0.0.3
version: 0.0.4
description: >
Just an example, not for publishing.
authors:
Expand All @@ -11,8 +11,10 @@ environment:

dependencies:
built_collection: '^1.0.0'
built_value: '^0.0.3'
built_value: '^0.0.4'

dev_dependencies:
built_value_generator: '^0.0.3'
# built_value_generator: '^0.0.3'
built_value_generator:
path: ../built_value_generator
test: any
10 changes: 10 additions & 0 deletions example/test/value_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'package:built_collection/built_collection.dart';
import 'package:example/value.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -71,6 +72,14 @@ void main() {
expect(value.listOfInt, [1, 2, 3]);
});

test('nullable builders can be updated', () {
final value = new Value((b) => b
..anInt = 1
..aString = 'two'
..setOfString = new SetBuilder<String>(['1', '2', '3']));
expect(value.setOfString, ['1', '2', '3']);
});

test('compares equal when equal', () {
final value1 = new Value((b) => b
..anInt = 0
Expand Down Expand Up @@ -122,6 +131,7 @@ aString=
anObject=null
aDefaultInt=7
listOfInt=[]
setOfString=null
}''');
});
});
Expand Down

0 comments on commit 6152dad

Please sign in to comment.