Index: lib/src/utils.dart |
diff --git a/lib/src/utils.dart b/lib/src/utils.dart |
index 4c7339520c673f724b77c967c1d74164a4615bbe..d89e05ac18e48ee26b658c12761ebe32aae836b8 100644 |
--- a/lib/src/utils.dart |
+++ b/lib/src/utils.dart |
@@ -349,7 +349,7 @@ String resourceOutputPath(Uri resourceUri, Uri entryUri) { |
/// |
/// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore |
/// |
-DartObjectImpl getAnnotationValue( |
+DartObjectImpl findNodeAnnotation( |
AnnotatedNode node, bool test(DartObjectImpl value)) { |
vsm
2015/05/20 19:15:29
Could this just call findElementAnnotation(node.el
Jennifer Messerly
2015/05/20 19:25:32
you'd think so, but AnnotatedNode doesn't have .el
vsm
2015/05/20 19:39:50
sgtm
|
for (var metadata in node.metadata) { |
ElementAnnotationImpl element = metadata.elementAnnotation; |
@@ -364,6 +364,19 @@ DartObjectImpl getAnnotationValue( |
return null; |
} |
+/// Similar to [findNodeAnnotation] but starts from any element. |
+DartObjectImpl findElementAnnotation( |
+ Element element, bool test(DartObjectImpl value)) { |
+ for (var metadata in element.metadata) { |
+ var evalResult = metadata.evaluationResult; |
+ if (evalResult == null) continue; |
+ |
+ var value = evalResult.value; |
+ if (value != null && test(value)) return value; |
+ } |
+ return null; |
+} |
+ |
/// Given a constant [value], a [fieldName], and an [expectedType], returns the |
/// value of that field. |
/// |