style(reflector): formatting

This commit is contained in:
vsavkin
2014-10-07 10:34:07 -04:00
parent 187c4aa33c
commit 7d566adea0
8 changed files with 78 additions and 65 deletions

View File

@ -2,21 +2,21 @@ import {CONST} from "facade/lang";
export class Inject {
@CONST()
constructor(token){
constructor(token) {
this.token = token;
}
}
export class InjectFuture {
@CONST()
constructor(token){
constructor(token) {
this.token = token;
}
}
export class InjectLazy {
@CONST()
constructor(token){
constructor(token) {
this.token = token;
}
}

View File

@ -2,7 +2,7 @@ import {ListWrapper, List} from 'facade/collection';
import {stringify} from 'facade/lang';
import {Key} from './key';
function constructResolvingPath(keys: List) {
function constructResolvingPath(keys:List) {
if (keys.length > 1) {
var reversed = ListWrapper.reversed(keys);
var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token));
@ -13,13 +13,13 @@ function constructResolvingPath(keys: List) {
}
export class ProviderError extends Error {
constructor(key:Key, constructResolvingMessage:Function){
constructor(key:Key, constructResolvingMessage:Function) {
this.keys = [key];
this.constructResolvingMessage = constructResolvingMessage;
this.message = this.constructResolvingMessage(this.keys);
}
addKey(key: Key) {
addKey(key:Key) {
ListWrapper.push(this.keys, key);
this.message = this.constructResolvingMessage(this.keys);
}
@ -30,8 +30,8 @@ export class ProviderError extends Error {
}
export class NoProviderError extends ProviderError {
constructor(key:Key){
super(key, function(keys:List) {
constructor(key:Key) {
super(key, function (keys:List) {
var first = stringify(ListWrapper.first(keys).token);
return `No provider for ${first}!${constructResolvingPath(keys)}`;
});
@ -39,8 +39,8 @@ export class NoProviderError extends ProviderError {
}
export class AsyncBindingError extends ProviderError {
constructor(key:Key){
super(key, function(keys:List) {
constructor(key:Key) {
super(key, function (keys:List) {
var first = stringify(ListWrapper.first(keys).token);
return `Cannot instantiate ${first} synchronously. ` +
`It is provided as a future!${constructResolvingPath(keys)}`;
@ -49,25 +49,25 @@ export class AsyncBindingError extends ProviderError {
}
export class CyclicDependencyError extends ProviderError {
constructor(key:Key){
super(key, function(keys:List) {
constructor(key:Key) {
super(key, function (keys:List) {
return `Cannot instantiate cyclic dependency!${constructResolvingPath(keys)}`;
});
}
}
export class InstantiationError extends ProviderError {
constructor(originalException, key:Key){
super(key, function(keys:List) {
constructor(originalException, key:Key) {
super(key, function (keys:List) {
var first = stringify(ListWrapper.first(keys).token);
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.`+
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}.` +
` ORIGINAL ERROR: ${originalException}`;
});
}
}
export class InvalidBindingError extends Error {
constructor(binding){
constructor(binding) {
this.message = `Invalid binding ${binding}`;
}
@ -77,7 +77,7 @@ export class InvalidBindingError extends Error {
}
export class NoAnnotationError extends Error {
constructor(type){
constructor(type) {
this.message = `Cannot resolve all parameters for ${stringify(type)}`;
}

View File

@ -81,16 +81,16 @@ export class Injector {
throw new NoProviderError(key);
}
_getInstance(key:Key){
_getInstance(key:Key) {
if (this._instances.length <= key.id) return null;
return ListWrapper.get(this._instances, key.id);
}
_setInstance(key:Key, obj){
_setInstance(key:Key, obj) {
ListWrapper.set(this._instances, key.id, obj);
}
_getBinding(key:Key){
_getBinding(key:Key) {
if (this._bindings.length <= key.id) return null;
return ListWrapper.get(this._bindings, key.id);
}
@ -154,7 +154,6 @@ class _SyncInjectorStrategy {
}
class _AsyncInjectorStrategy {
constructor(injector:Injector) {
this.injector = injector;
@ -212,13 +211,13 @@ class _AsyncInjectorStrategy {
return FutureWrapper.error(e);
}
_findOrCreate(key:Key, binding: Binding, deps:List) {
_findOrCreate(key:Key, binding:Binding, deps:List) {
try {
var instance = this.injector._getInstance(key);
if (!_isWaiting(instance)) return instance;
return binding.factory(deps);
} catch (e) {
throw new InstantiationError(e, key);
throw new InstantiationError(e, key);
}
}
@ -229,10 +228,9 @@ class _AsyncInjectorStrategy {
}
function _flattenBindings(bindings:List) {
var res = {};
ListWrapper.forEach(bindings, function (b){
ListWrapper.forEach(bindings, function (b) {
if (b instanceof Binding) {
MapWrapper.set(res, b.key.id, b);

View File

@ -9,7 +9,7 @@ var _id:int = 0;
@FIELD('final asFuture:bool')
@FIELD('final lazy:bool')
export class Dependency {
constructor(key:Key, asFuture:bool, lazy:bool){
constructor(key:Key, asFuture:bool, lazy:bool) {
this.key = key;
this.asFuture = asFuture;
this.lazy = lazy;

View File

@ -37,12 +37,16 @@ class Reflector {
if (inject != null) {
return new Dependency(Key.get(inject.token), false, false);
} else if (injectFuture != null) {
return new Dependency(Key.get(injectFuture.token), true, false);
} else if (injectLazy != null) {
return new Dependency(Key.get(injectLazy.token), false, true);
} else if (p.type.qualifiedName != #dynamic) {
return new Dependency(Key.get(p.type.reflectedType), false, false);
} else {
throw new NoAnnotationError(type);
}