platform/packages/framework/lib/src/util.dart

28 lines
739 B
Dart
Raw Normal View History

2018-08-21 02:44:32 +00:00
import 'package:angel_container/angel_container.dart';
2019-05-02 22:48:31 +00:00
final RegExp straySlashes = RegExp(r'(^/+)|(/+$)');
2017-11-28 18:14:50 +00:00
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
}