feat(reflector): added a method to get type's interfaces
This commit is contained in:
@@ -71,6 +71,11 @@ class ReflectionCapabilities {
|
||||
return meta.map((m) => m.reflectee).toList();
|
||||
}
|
||||
|
||||
List interfaces(type) {
|
||||
ClassMirror classMirror = reflectType(type);
|
||||
return classMirror.superinterfaces.map((si) => si.reflectedType).toList();
|
||||
}
|
||||
|
||||
GetterFn getter(String name) {
|
||||
var symbol = new Symbol(name);
|
||||
return (receiver) => reflect(receiver).getField(symbol).reflectee;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Type, isPresent, global, stringify} from 'angular2/src/facade/lang';
|
||||
import {Type, isPresent, global, stringify, BaseException} from 'angular2/src/facade/lang';
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {GetterFn, SetterFn, MethodFn} from './types';
|
||||
|
||||
@@ -97,6 +97,10 @@ export class ReflectionCapabilities {
|
||||
return [];
|
||||
}
|
||||
|
||||
interfaces(type): List<any> {
|
||||
throw new BaseException("JavaScript does not support interfaces");
|
||||
}
|
||||
|
||||
getter(name: string): GetterFn { return new Function('o', 'return o.' + name + ';'); }
|
||||
|
||||
setter(name: string): SetterFn { return new Function('o', 'v', 'return o.' + name + ' = v;'); }
|
||||
|
||||
@@ -52,6 +52,14 @@ export class Reflector {
|
||||
}
|
||||
}
|
||||
|
||||
interfaces(type): List<any> {
|
||||
if (MapWrapper.contains(this._typeInfo, type)) {
|
||||
return MapWrapper.get(this._typeInfo, type)["interfaces"];
|
||||
} else {
|
||||
return this.reflectionCapabilities.interfaces(type);
|
||||
}
|
||||
}
|
||||
|
||||
getter(name: string): GetterFn {
|
||||
if (MapWrapper.contains(this._getters, name)) {
|
||||
return MapWrapper.get(this._getters, name);
|
||||
|
||||
+2
@@ -20,6 +20,8 @@ class RecordingReflectionCapabilities implements ReflectionCapabilities {
|
||||
|
||||
List<List> parameters(typeOrFunc) => _notImplemented('parameters');
|
||||
|
||||
List<List> interfaces(typeOrFunc) => _notImplemented('interfaces');
|
||||
|
||||
List annotations(typeOrFunc) => _notImplemented('annotations');
|
||||
|
||||
GetterFn getter(String name) {
|
||||
|
||||
Reference in New Issue
Block a user