2016-09-15 19:53:01 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:mirrors';
|
|
|
|
|
2017-11-28 18:14:50 +00:00
|
|
|
final RegExp straySlashes = new RegExp(r'(^/+)|(/+$)');
|
|
|
|
|
2016-09-15 19:53:01 +00:00
|
|
|
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);
|
2016-09-15 19:53:01 +00:00
|
|
|
return matchingAnnotation(classMirror.metadata, T);
|
|
|
|
}
|
2017-09-22 14:03:23 +00:00
|
|
|
}
|