platform/lib/src/util.dart
2018-06-22 23:29:38 -04:00

26 lines
732 B
Dart

import 'dart:async';
import 'dart:mirrors';
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 {
ClassMirror classMirror = reflectClass(obj.runtimeType as Type);
return matchingAnnotation(classMirror.metadata, T);
}
}