platform/lib/src/util.dart

28 lines
743 B
Dart
Raw Normal View History

2018-08-21 02:44:32 +00:00
import 'package:angel_container/angel_container.dart';
2017-11-28 18:14:50 +00:00
final RegExp straySlashes = new RegExp(r'(^/+)|(/+$)');
2019-04-08 19:53:07 +00:00
T matchingAnnotation<T>(List<ReflectedInstance> metadata) {
2018-08-21 02:44:32 +00:00
for (ReflectedInstance metaDatum in metadata) {
2018-08-21 18:50:43 +00:00
if (metaDatum.type.reflectedType == T) {
2019-04-08 19:53:07 +00:00
return metaDatum.reflectee as T;
}
}
2018-08-21 18:50:43 +00:00
return null;
}
2019-04-08 19:53:07 +00:00
T getAnnotation<T>(obj, Reflector reflector) {
2018-08-21 02:44:32 +00:00
if (reflector == null) {
return null;
} else {
2018-08-21 02:44:32 +00:00
if (obj is Function) {
var methodMirror = reflector.reflectFunction(obj);
2019-04-08 19:53:07 +00:00
return matchingAnnotation<T>(methodMirror.annotations);
2018-08-21 02:44:32 +00:00
} else {
var classMirror = reflector.reflectClass(obj.runtimeType as Type);
2019-04-08 19:53:07 +00:00
return matchingAnnotation<T>(classMirror.annotations);
2018-08-21 02:44:32 +00:00
}
}
2017-09-22 14:03:23 +00:00
}