Skip to content

Commit

Permalink
Merge pull request #2 from davidmorgan/minor-fixes
Browse files Browse the repository at this point in the history
Allow static fields in value class. Allow custom setters in builder.
  • Loading branch information
davidmorgan committed Oct 10, 2015
2 parents 66e7078 + ad06ee4 commit 421cf52
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 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.3

- Allow static fields in value class.
- Allow custom setters in builder.

## 0.0.2

- Fix error message for missing builder 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.2
version: 0.0.3
description: >
Value types with builders. This library is the runtime dependency.
authors:
Expand Down
7 changes: 4 additions & 3 deletions built_value_generator/lib/built_value_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ class BuiltValueGenerator extends Generator {
List<FieldElement> getFields(ClassElement classElement) {
final result = <FieldElement>[];
for (final field in classElement.fields) {
if (!field.isStatic && field.getter.isAbstract ||
field.getter.isSynthetic) result.add(field);
if (!field.isStatic &&
(field.getter.isAbstract || field.getter.isSynthetic)) result
.add(field);
}
return result;
}
Expand All @@ -142,7 +143,7 @@ class BuiltValueGenerator extends Generator {
return result;
}
for (final field in classElement.fields) {
if (!field.isStatic) result.add(field);
if (!field.isStatic && field.getter != null) result.add(field);
}
return result;
}
Expand Down
4 changes: 2 additions & 2 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.2
version: 0.0.3
description: >
Value types with builders. This library is the dev dependency.
authors:
Expand All @@ -12,7 +12,7 @@ environment:
dependencies:
analyzer: '>=0.26.1 <1.0.0'
built_collection: '^1.0.0'
built_value: '^0.0.2'
built_value: '^0.0.3'
source_gen: '>=0.4.3 <1.0.0'
quiver: '>=0.21.0 <0.22.0'

Expand Down
4 changes: 2 additions & 2 deletions example/lib/compound_value.g.dart

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

9 changes: 9 additions & 0 deletions example/lib/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ part 'value.g.dart';
/// fields declared as abstract getters. Finally, it must have a particular
/// constructor and factory, as shown here.
abstract class Value implements Built<Value, ValueBuilder> {
static final int youCanHaveStaticFields = 3;

int get anInt;
String get aString;
@nullable Object get anObject;
int get aDefaultInt;
BuiltList<int> get listOfInt;

int get youCanWriteDerivedGetters => anInt + aDefaultInt;

Value._();
factory Value([updates(ValueBuilder b)]) = _$Value;
}
Expand All @@ -41,4 +45,9 @@ abstract class ValueBuilder implements Builder<Value, ValueBuilder> {

ValueBuilder._();
factory ValueBuilder() = _$ValueBuilder;

set youCanWriteExtraSetters(int value) {
anInt = value;
aDefaultInt = value;
}
}
2 changes: 1 addition & 1 deletion example/lib/value.g.dart

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

6 changes: 3 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.2
version: 0.0.3
description: >
Just an example, not for publishing.
authors:
Expand All @@ -11,8 +11,8 @@ environment:

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

dev_dependencies:
built_value_generator: '^0.0.2'
built_value_generator: '^0.0.3'
test: any

0 comments on commit 421cf52

Please sign in to comment.