Skip to content

Commit 421cf52

Browse files
committed
Merge pull request #2 from davidmorgan/minor-fixes
Allow static fields in value class. Allow custom setters in builder.
2 parents 66e7078 + ad06ee4 commit 421cf52

File tree

8 files changed

+27
-12
lines changed

8 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.0.3
4+
5+
- Allow static fields in value class.
6+
- Allow custom setters in builder.
7+
38
## 0.0.2
49

510
- Fix error message for missing builder class.

built_value/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: built_value
2-
version: 0.0.2
2+
version: 0.0.3
33
description: >
44
Value types with builders. This library is the runtime dependency.
55
authors:

built_value_generator/lib/built_value_generator.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ class BuiltValueGenerator extends Generator {
130130
List<FieldElement> getFields(ClassElement classElement) {
131131
final result = <FieldElement>[];
132132
for (final field in classElement.fields) {
133-
if (!field.isStatic && field.getter.isAbstract ||
134-
field.getter.isSynthetic) result.add(field);
133+
if (!field.isStatic &&
134+
(field.getter.isAbstract || field.getter.isSynthetic)) result
135+
.add(field);
135136
}
136137
return result;
137138
}
@@ -142,7 +143,7 @@ class BuiltValueGenerator extends Generator {
142143
return result;
143144
}
144145
for (final field in classElement.fields) {
145-
if (!field.isStatic) result.add(field);
146+
if (!field.isStatic && field.getter != null) result.add(field);
146147
}
147148
return result;
148149
}

built_value_generator/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: built_value_generator
2-
version: 0.0.2
2+
version: 0.0.3
33
description: >
44
Value types with builders. This library is the dev dependency.
55
authors:
@@ -12,7 +12,7 @@ environment:
1212
dependencies:
1313
analyzer: '>=0.26.1 <1.0.0'
1414
built_collection: '^1.0.0'
15-
built_value: '^0.0.2'
15+
built_value: '^0.0.3'
1616
source_gen: '>=0.4.3 <1.0.0'
1717
quiver: '>=0.21.0 <0.22.0'
1818

example/lib/compound_value.g.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/value.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ part 'value.g.dart';
1515
/// fields declared as abstract getters. Finally, it must have a particular
1616
/// constructor and factory, as shown here.
1717
abstract class Value implements Built<Value, ValueBuilder> {
18+
static final int youCanHaveStaticFields = 3;
19+
1820
int get anInt;
1921
String get aString;
2022
@nullable Object get anObject;
2123
int get aDefaultInt;
2224
BuiltList<int> get listOfInt;
2325

26+
int get youCanWriteDerivedGetters => anInt + aDefaultInt;
27+
2428
Value._();
2529
factory Value([updates(ValueBuilder b)]) = _$Value;
2630
}
@@ -41,4 +45,9 @@ abstract class ValueBuilder implements Builder<Value, ValueBuilder> {
4145

4246
ValueBuilder._();
4347
factory ValueBuilder() = _$ValueBuilder;
48+
49+
set youCanWriteExtraSetters(int value) {
50+
anInt = value;
51+
aDefaultInt = value;
52+
}
4453
}

example/lib/value.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: example
2-
version: 0.0.2
2+
version: 0.0.3
33
description: >
44
Just an example, not for publishing.
55
authors:
@@ -11,8 +11,8 @@ environment:
1111

1212
dependencies:
1313
built_collection: '^1.0.0'
14-
built_value: '^0.0.2'
14+
built_value: '^0.0.3'
1515

1616
dev_dependencies:
17-
built_value_generator: '^0.0.2'
17+
built_value_generator: '^0.0.3'
1818
test: any

0 commit comments

Comments
 (0)