Repository navigation
Expand file tree
/
Copy pathreflector.js
More file actions
88 lines (75 loc) · 2.42 KB
/
Copy pathreflector.js
File metadata and controls
88 lines (75 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {Type, isPresent, stringify, BaseException} from 'angular2/src/facade/lang';
import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {SetterFn, GetterFn, MethodFn} from './types';
export {SetterFn, GetterFn, MethodFn} from './types';
export class Reflector {
_typeInfo:Map;
_getters:Map;
_setters:Map;
_methods:Map;
reflectionCapabilities:any;
constructor(reflectionCapabilities) {
this._typeInfo = MapWrapper.create();
this._getters = MapWrapper.create();
this._setters = MapWrapper.create();
this._methods = MapWrapper.create();
this.reflectionCapabilities = reflectionCapabilities;
}
registerType(type, typeInfo){
MapWrapper.set(this._typeInfo, type, typeInfo);
}
registerGetters(getters){
_mergeMaps(this._getters, getters);
}
registerSetters(setters){
_mergeMaps(this._setters, setters);
}
registerMethods(methods){
_mergeMaps(this._methods, methods);
}
factory(type:Type):Function {
if(MapWrapper.contains(this._typeInfo, type)) {
return MapWrapper.get(this._typeInfo, type)["factory"];
} else {
return this.reflectionCapabilities.factory(type);
}
}
parameters(typeOfFunc):List {
if(MapWrapper.contains(this._typeInfo, typeOfFunc)) {
return MapWrapper.get(this._typeInfo, typeOfFunc)["parameters"];
} else {
return this.reflectionCapabilities.parameters(typeOfFunc);
}
}
annotations(typeOfFunc):List {
if(MapWrapper.contains(this._typeInfo, typeOfFunc)) {
return MapWrapper.get(this._typeInfo, typeOfFunc)["annotations"];
} else {
return this.reflectionCapabilities.annotations(typeOfFunc);
}
}
getter(name:string):GetterFn {
if(MapWrapper.contains(this._getters, name)) {
return MapWrapper.get(this._getters, name);
} else {
return this.reflectionCapabilities.getter(name);
}
}
setter(name:string):SetterFn {
if(MapWrapper.contains(this._setters, name)) {
return MapWrapper.get(this._setters, name);
} else {
return this.reflectionCapabilities.setter(name);
}
}
method(name:string):MethodFn {
if(MapWrapper.contains(this._methods, name)) {
return MapWrapper.get(this._methods, name);
} else {
return this.reflectionCapabilities.method(name);
}
}
}
function _mergeMaps(target:Map, config) {
StringMapWrapper.forEach(config, (v, k) => MapWrapper.set(target, k, v));
}