@@ -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+ }
0 commit comments