Skip to content

Commit 362b9e3

Browse files
alorenzennatebosch
authored andcommitted
Extract matchTypes from matchAnnotation. (#116)
Extract matchTypes from matchAnnotation so that it can be used in cases where the type comes from a different source (like a DartObject instance).
1 parent 8c78650 commit 362b9e3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/src/annotation.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,25 @@ DeclarationMirror _getDeclarationMirrorFromType(InterfaceType type) {
214214
return libMirror.declarations[typeNameSymbol];
215215
}
216216

217+
/// Checks whether the constant type of [annotation] is equivalent to
218+
/// [annotationType].
217219
bool matchAnnotation(Type annotationType, ElementAnnotation annotation) {
218-
var classMirror = reflectClass(annotationType);
219-
var classMirrorSymbol = classMirror.simpleName;
220-
221220
var annotationValueType = annotation.constantValue?.type;
222221
if (annotationValueType == null) {
223222
throw new ArgumentError.value(annotation, 'annotation',
224223
'Could not determine type of annotation. Are you missing a dependency?');
225224
}
225+
226+
return matchTypes(annotationType, annotationValueType);
227+
}
228+
229+
/// Checks whether [annotationValueType] is equivalent to [annotationType].
230+
///
231+
/// Currently, this uses mirrors to compare the name and library uri of the two
232+
/// types.
233+
bool matchTypes(Type annotationType, ParameterizedType annotationValueType) {
234+
var classMirror = reflectClass(annotationType);
235+
var classMirrorSymbol = classMirror.simpleName;
226236

227237
var annTypeName = annotationValueType.name;
228238
var annotationTypeSymbol = new Symbol(annTypeName);

0 commit comments

Comments
 (0)