2018-08-21 02:44:32 +00:00
|
|
|
import 'package:angel_container/angel_container.dart';
|
2016-09-15 19:53:01 +00:00
|
|
|
|
2019-05-02 22:48:31 +00:00
|
|
|
final RegExp straySlashes = RegExp(r'(^/+)|(/+$)');
|
2017-11-28 18:14:50 +00:00
|
|
|
|
2021-03-20 08:11:18 +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) {
|
2021-03-20 08:11:18 +00:00
|
|
|
return metaDatum.reflectee as T?;
|
2016-09-15 19:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 18:50:43 +00:00
|
|
|
|
2016-09-15 19:53:01 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-03-20 08:11:18 +00:00
|
|
|
T? getAnnotation<T>(obj, Reflector? reflector) {
|
2018-08-21 02:44:32 +00:00
|
|
|
if (reflector == null) {
|
|
|
|
return null;
|
2016-09-15 19:53:01 +00:00
|
|
|
} else {
|
2018-08-21 02:44:32 +00:00
|
|
|
if (obj is Function) {
|
2021-03-20 08:11:18 +00:00
|
|
|
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 {
|
2021-03-20 08:11:18 +00:00
|
|
|
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
|
|
|
}
|
2016-09-15 19:53:01 +00:00
|
|
|
}
|
2017-09-22 14:03:23 +00:00
|
|
|
}
|