11import { Type , isPresent , stringify , BaseException } from 'angular2/src/facade/lang' ;
2- import { List , ListWrapper , Map , MapWrapper , StringMapWrapper } from 'angular2/src/facade/collection' ;
2+ import {
3+ List ,
4+ ListWrapper ,
5+ Map ,
6+ MapWrapper ,
7+ StringMap ,
8+ StringMapWrapper
9+ } from 'angular2/src/facade/collection' ;
310import { SetterFn , GetterFn , MethodFn } from './types' ;
4- export { SetterFn , GetterFn , MethodFn } from './types' ;
511
612export class Reflector {
713 _typeInfo : Map < Type , any > ;
@@ -18,7 +24,7 @@ export class Reflector {
1824 this . reflectionCapabilities = reflectionCapabilities ;
1925 }
2026
21- registerType ( type : Type , typeInfo : Map < Type , any > ) : void {
27+ registerType ( type : Type , typeInfo : StringMap < string , any > ) : void {
2228 MapWrapper . set ( this . _typeInfo , type , typeInfo ) ;
2329 }
2430
@@ -29,32 +35,32 @@ export class Reflector {
2935 registerMethods ( methods : Map < string , MethodFn > ) : void { _mergeMaps ( this . _methods , methods ) ; }
3036
3137 factory ( type : Type ) : Function {
32- if ( MapWrapper . contains ( this . _typeInfo , type ) ) {
33- return MapWrapper . get ( this . _typeInfo , type ) [ "factory" ] ;
38+ if ( this . _containsTypeInfo ( type ) ) {
39+ return this . _getTypeInfoField ( type , "factory" , null ) ;
3440 } else {
3541 return this . reflectionCapabilities . factory ( type ) ;
3642 }
3743 }
3844
39- parameters ( typeOfFunc ) : List < any > {
40- if ( MapWrapper . contains ( this . _typeInfo , typeOfFunc ) ) {
41- return MapWrapper . get ( this . _typeInfo , typeOfFunc ) [ "parameters" ] ;
45+ parameters ( typeOrFunc ) : List < any > {
46+ if ( MapWrapper . contains ( this . _typeInfo , typeOrFunc ) ) {
47+ return this . _getTypeInfoField ( typeOrFunc , "parameters" , [ ] ) ;
4248 } else {
43- return this . reflectionCapabilities . parameters ( typeOfFunc ) ;
49+ return this . reflectionCapabilities . parameters ( typeOrFunc ) ;
4450 }
4551 }
4652
47- annotations ( typeOfFunc ) : List < any > {
48- if ( MapWrapper . contains ( this . _typeInfo , typeOfFunc ) ) {
49- return MapWrapper . get ( this . _typeInfo , typeOfFunc ) [ "annotations" ] ;
53+ annotations ( typeOrFunc ) : List < any > {
54+ if ( MapWrapper . contains ( this . _typeInfo , typeOrFunc ) ) {
55+ return this . _getTypeInfoField ( typeOrFunc , "annotations" , [ ] ) ;
5056 } else {
51- return this . reflectionCapabilities . annotations ( typeOfFunc ) ;
57+ return this . reflectionCapabilities . annotations ( typeOrFunc ) ;
5258 }
5359 }
5460
5561 interfaces ( type ) : List < any > {
5662 if ( MapWrapper . contains ( this . _typeInfo , type ) ) {
57- return MapWrapper . get ( this . _typeInfo , type ) [ "interfaces" ] ;
63+ return this . _getTypeInfoField ( type , "interfaces" , [ ] ) ;
5864 } else {
5965 return this . reflectionCapabilities . interfaces ( type ) ;
6066 }
@@ -83,6 +89,13 @@ export class Reflector {
8389 return this . reflectionCapabilities . method ( name ) ;
8490 }
8591 }
92+
93+ _getTypeInfoField ( typeOrFunc , key , defaultValue ) {
94+ var res = MapWrapper . get ( this . _typeInfo , typeOrFunc ) [ key ] ;
95+ return isPresent ( res ) ? res : defaultValue ;
96+ }
97+
98+ _containsTypeInfo ( typeOrFunc ) { return MapWrapper . contains ( this . _typeInfo , typeOrFunc ) ; }
8699}
87100
88101function _mergeMaps ( target : Map < any , any > , config : Map < string , Function > ) : void {
0 commit comments