Skip to content

Commit 861f9b6

Browse files
author
Ivan Dlugos
committed
update generator dependencies to null-safe versions
1 parent 5f99de4 commit 861f9b6

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

generator/lib/src/entity_resolver.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,17 @@ class EntityResolver extends Builder {
104104
var flags = 0;
105105
int? propUid;
106106

107-
if (_idChecker.hasAnnotationOfExact(f)) {
107+
_idChecker.runIfMatches(f, (annotation) {
108108
flags |= OBXPropertyFlags.ID;
109-
110-
final annotation = _idChecker.firstAnnotationOfExact(f);
111109
if (annotation.getField('assignable')!.toBoolValue()!) {
112110
flags |= OBXPropertyFlags.ID_SELF_ASSIGNABLE;
113111
}
114-
}
112+
});
115113

116-
if (_propertyChecker.hasAnnotationOfExact(f)) {
117-
final annotation = _propertyChecker.firstAnnotationOfExact(f);
114+
_propertyChecker.runIfMatches(f, (annotation) {
118115
propUid = annotation.getField('uid')!.toIntValue();
119116
fieldType = propertyTypeFromAnnotation(annotation.getField('type')!);
120-
}
117+
});
121118

122119
if (fieldType == null) {
123120
final dartType = f.type;
@@ -169,24 +166,23 @@ class EntityResolver extends Builder {
169166
(f.type as ParameterizedType).typeArguments[0].element!.name;
170167
}
171168

172-
if (_backlinkChecker.hasAnnotationOfExact(f)) {
169+
final backlinkAnnotations = _backlinkChecker.annotationsOfExact(f);
170+
if (backlinkAnnotations.isNotEmpty) {
173171
if (!isToManyRel) {
174172
log.severe(
175173
' invalid use of @Backlink() annotation - may only be used on a ToMany<> field');
176174
continue;
177175
}
178-
final backlinkField = _backlinkChecker
179-
.firstAnnotationOfExact(f)
180-
.getField('to')!
181-
.toStringValue()!;
176+
final backlinkField =
177+
backlinkAnnotations.first.getField('to')!.toStringValue()!;
182178
final backlink = ModelBacklink(f.name, relTargetName!, backlinkField);
183179
entity.backlinks.add(backlink);
184180
log.info(' $backlink');
185181
} else if (isToManyRel) {
186182
// create relation
187183
final rel =
188184
ModelRelation(IdUid.empty(), f.name, targetName: relTargetName);
189-
if (propUid != null) rel.id.uid = propUid;
185+
if (propUid != null) rel.id.uid = propUid!;
190186
entity.relations.add(rel);
191187

192188
log.info(' $rel');
@@ -205,7 +201,7 @@ class EntityResolver extends Builder {
205201
// Index and unique annotation.
206202
processAnnotationIndexUnique(f, fieldType, element, prop);
207203

208-
if (propUid != null) prop.id.uid = propUid;
204+
if (propUid != null) prop.id.uid = propUid!;
209205
// for code generation
210206
prop.dartFieldType =
211207
f.type.element!.name! + (isNullable(f.type) ? '?' : '');
@@ -390,3 +386,10 @@ class EntityResolver extends Builder {
390386
return sdk.major > 2 || (sdk.major == 2 && sdk.minor >= 12);
391387
}
392388
}
389+
390+
extension _TypeCheckerExtensions on TypeChecker {
391+
void runIfMatches(Element element, void Function(DartObject) fn) {
392+
final annotations = annotationsOfExact(element);
393+
if (annotations.isNotEmpty) fn(annotations.first);
394+
}
395+
}

generator/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ environment:
99

1010
dependencies:
1111
objectbox: 0.13.0
12-
build: ^1.0.0
13-
source_gen: ^0.9.0
12+
build: ^2.0.0
13+
source_gen: ^1.0.0
1414
analyzer: ^1.1.0
1515
glob: ^2.0.0
1616
path: ^1.8.0
17-
dart_style: ^1.3.0
17+
dart_style: ^2.0.0
1818
collection: ^1.15.0
1919

2020
# NOTE: remove before publishing

0 commit comments

Comments
 (0)