Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hive_generator built value support #533

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
beb9c7f
hive_generator: Support Built codegen
KalilDev Jan 5, 2021
731e6d8
hive_generator: Implement EnumClassBuilder
KalilDev Jan 6, 2021
bec838e
hive_generator: Null aware toBuilder()
KalilDev Jan 6, 2021
a933b50
hive_generator: correctly deserialize null ...
KalilDev Jan 6, 2021
aa70ffb
hive_generator: Refactor class_builder
KalilDev Jan 10, 2021
1b17cf9
hive_generator: Refactor ClassBuilder
KalilDev Jan 10, 2021
f32caa6
hive_generator: depend on built_value and built_collection
KalilDev Jan 10, 2021
7adf101
hive_generator: lookup the name from custom builders
KalilDev Jan 10, 2021
f6ffa2d
hive_generator: expose methods from generator
KalilDev Jan 10, 2021
8fa51a9
hive_generator: lookup setters for custom builders
KalilDev Jan 10, 2021
9c223e7
hive_generator: implement nested and custom builders
KalilDev Jan 10, 2021
a1ce47f
hive_generator: fix _castBuiltCollection
KalilDev Jan 10, 2021
dbd9e2c
hive_generator: Workaround edge case when...
KalilDev Jan 10, 2021
84d624a
hive_generator: remove debuug print
KalilDev Jan 10, 2021
55492ac
hive_generator: add element to AdapterFIeld
KalilDev Jan 10, 2021
c22b39a
hive_generator: expose castIterable and castMap
KalilDev Jan 10, 2021
2cc0141
hive_generator: Support nested built_collection read
KalilDev Jan 10, 2021
c8be0e3
hive_generator: Support nested built_collection write
KalilDev Jan 10, 2021
cab846a
hive_generator: fix _castBuiltCollection
KalilDev Jan 10, 2021
126ce0a
hive_generator: fix buildReadConstructor
KalilDev Jan 10, 2021
ff1181e
hive_generator: basic nullability awareness
KalilDev Jan 10, 2021
5ecf4a6
Revert "hive_generator: basic nullability awareness"
KalilDev Jan 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 49 additions & 3 deletions hive_generator/lib/src/builder.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';

class AdapterField {
final int index;
final String name;
final DartType type;
final PropertyAccessorElement element;

AdapterField(this.index, this.name, this.type);
String get name => element.variable.name;
DartType get type => element.variable.type;

bool get isNullable {
switch (element.variable.type?.nullabilitySuffix) {
case NullabilitySuffix.none:
return false;
default:
return true;
}
}

AdapterField(this.index, this.element);
BuiltAdapterField toBuilt(bool nestedBuilders) => BuiltAdapterField(
index,
element,
nestedBuilders,
);
}

class BuiltAdapterField extends AdapterField {
DartType _type;

@override
DartType get type => _type ?? super.type;
set type(DartType type) => _type = type;

bool nestedBuilders;

BuiltAdapterField(
int index,
PropertyAccessorElement element,
this.nestedBuilders,
) : super(index, element);

bool get hasNullableAnnotation => element.metadata.any((metadata) =>
metadata.computeConstantValue()?.toStringValue() == 'nullable');

bool get hasNullableType =>
element?.returnType?.nullabilitySuffix == NullabilitySuffix.question;

@override
bool get isNullable => hasNullableAnnotation || hasNullableType;

@override
BuiltAdapterField toBuilt(bool nestedBuilders) =>
throw StateError('Already is an BuiltAdapterField');
}

abstract class Builder {
Expand Down