From 5a61ec62e5a7dd0c2c16d26f57feee275c72214f Mon Sep 17 00:00:00 2001 From: Andrew Lorenzen Date: Thu, 5 Jan 2017 14:30:57 -0800 Subject: [PATCH 1/2] Extract matchTypes from matchAnnotation. Extract matchTypes from matchAnnotation so that it can be used in cases where the type comes from a different source (like a DartObject instance). --- lib/src/annotation.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/annotation.dart b/lib/src/annotation.dart index 3e567435..6cd5a955 100644 --- a/lib/src/annotation.dart +++ b/lib/src/annotation.dart @@ -215,14 +215,18 @@ DeclarationMirror _getDeclarationMirrorFromType(InterfaceType type) { } bool matchAnnotation(Type annotationType, ElementAnnotation annotation) { - var classMirror = reflectClass(annotationType); - var classMirrorSymbol = classMirror.simpleName; - var annotationValueType = annotation.constantValue?.type; if (annotationValueType == null) { throw new ArgumentError.value(annotation, 'annotation', 'Could not determine type of annotation. Are you missing a dependency?'); } + + return matchTypes(annotationType, annotationValueType); +} + +bool matchTypes(Type annotationType, ParameterizedType annotationValueType) { + var classMirror = reflectClass(annotationType); + var classMirrorSymbol = classMirror.simpleName; var annTypeName = annotationValueType.name; var annotationTypeSymbol = new Symbol(annTypeName); From 5492384047f6de992cf5040a443d2e03b0902435 Mon Sep 17 00:00:00 2001 From: Andrew Lorenzen Date: Mon, 9 Jan 2017 11:45:27 -0800 Subject: [PATCH 2/2] Add dartdoc comments for matchAnnotation() and matchTypes(). --- lib/src/annotation.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/src/annotation.dart b/lib/src/annotation.dart index 6cd5a955..4df22320 100644 --- a/lib/src/annotation.dart +++ b/lib/src/annotation.dart @@ -214,6 +214,8 @@ DeclarationMirror _getDeclarationMirrorFromType(InterfaceType type) { return libMirror.declarations[typeNameSymbol]; } +/// Checks whether the constant type of [annotation] is equivalent to +/// [annotationType]. bool matchAnnotation(Type annotationType, ElementAnnotation annotation) { var annotationValueType = annotation.constantValue?.type; if (annotationValueType == null) { @@ -224,6 +226,10 @@ bool matchAnnotation(Type annotationType, ElementAnnotation annotation) { return matchTypes(annotationType, annotationValueType); } +/// Checks whether [annotationValueType] is equivalent to [annotationType]. +/// +/// Currently, this uses mirrors to compare the name and library uri of the two +/// types. bool matchTypes(Type annotationType, ParameterizedType annotationValueType) { var classMirror = reflectClass(annotationType); var classMirrorSymbol = classMirror.simpleName;