platform/lib/src/util.dart

27 lines
732 B
Dart
Raw Normal View History

import 'dart:async';
import 'dart:mirrors';
2017-11-28 18:14:50 +00:00
final RegExp straySlashes = new RegExp(r'(^/+)|(/+$)');
matchingAnnotation(List<InstanceMirror> metadata, Type T) {
for (InstanceMirror metaDatum in metadata) {
if (metaDatum.hasReflectee) {
var reflectee = metaDatum.reflectee;
if (reflectee.runtimeType == T) {
return reflectee;
}
}
}
return null;
}
getAnnotation(obj, Type T) {
if (obj is Function || obj is Future) {
MethodMirror methodMirror = (reflect(obj) as ClosureMirror).function;
return matchingAnnotation(methodMirror.metadata, T);
} else {
2018-06-23 03:29:38 +00:00
ClassMirror classMirror = reflectClass(obj.runtimeType as Type);
return matchingAnnotation(classMirror.metadata, T);
}
2017-09-22 14:03:23 +00:00
}