提交 f29abe48 编写于 作者: J Johannes Rieken

remove more unused code, #38414

上级 f657b94f
...@@ -120,10 +120,6 @@ export function assign(destination: any, ...sources: any[]): any { ...@@ -120,10 +120,6 @@ export function assign(destination: any, ...sources: any[]): any {
return destination; return destination;
} }
export function toObject<T>(arr: T[], keyMap: (t: T) => string): { [key: string]: T } {
return arr.reduce((o, d) => assign(o, { [keyMap(d)]: d }), Object.create(null));
}
export function equals(one: any, other: any): boolean { export function equals(one: any, other: any): boolean {
if (one === other) { if (one === other) {
return true; return true;
......
...@@ -4,51 +4,17 @@ ...@@ -4,51 +4,17 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import { illegalArgument } from 'vs/base/common/errors';
import * as instantiation from './instantiation'; import * as instantiation from './instantiation';
export class AbstractDescriptor<T> {
constructor(private _staticArguments: any[]) { export class SyncDescriptor<T> {
// empty
}
public appendStaticArguments(more: any[]): void {
this._staticArguments.push.apply(this._staticArguments, more);
}
public staticArguments(): any[]; readonly ctor: any;
public staticArguments(nth: number): any; readonly staticArguments: any[];
public staticArguments(nth?: number): any[] {
if (isNaN(nth)) {
return this._staticArguments.slice(0);
} else {
return this._staticArguments[nth];
}
}
_validate(type: T): void { constructor(ctor: new (...args: any[]) => T, ..._staticArguments: any[]) {
if (!type) { this.ctor = ctor;
throw illegalArgument('can not be falsy'); this.staticArguments = _staticArguments;
}
}
}
export class SyncDescriptor<T> extends AbstractDescriptor<T> {
constructor(private _ctor: any, ...staticArguments: any[]) {
super(staticArguments);
}
public get ctor(): any {
return this._ctor;
}
protected bind(...moreStaticArguments: any[]): SyncDescriptor<T> {
let allArgs: any[] = [];
allArgs = allArgs.concat(this.staticArguments());
allArgs = allArgs.concat(moreStaticArguments);
return new SyncDescriptor<T>(this._ctor, ...allArgs);
} }
} }
...@@ -175,4 +141,4 @@ export interface SyncDescriptor8<A1, A2, A3, A4, A5, A6, A7, A8, T> { ...@@ -175,4 +141,4 @@ export interface SyncDescriptor8<A1, A2, A3, A4, A5, A6, A7, A8, T> {
bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): SyncDescriptor2<A7, A8, T>; bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6): SyncDescriptor2<A7, A8, T>;
bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): SyncDescriptor1<A8, T>; bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): SyncDescriptor1<A8, T>;
bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): SyncDescriptor0<T>; bind(a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): SyncDescriptor0<T>;
} }
\ No newline at end of file
...@@ -77,7 +77,7 @@ export class InstantiationService implements IInstantiationService { ...@@ -77,7 +77,7 @@ export class InstantiationService implements IInstantiationService {
private _createInstance<T>(desc: SyncDescriptor<T>, args: any[]): T { private _createInstance<T>(desc: SyncDescriptor<T>, args: any[]): T {
// arguments given by createInstance-call and/or the descriptor // arguments given by createInstance-call and/or the descriptor
let staticArgs = desc.staticArguments().concat(args); let staticArgs = desc.staticArguments.concat(args);
// arguments defined by service decorators // arguments defined by service decorators
let serviceDependencies = _util.getServiceDependencies(desc.ctor).sort((a, b) => a.index - b.index); let serviceDependencies = _util.getServiceDependencies(desc.ctor).sort((a, b) => a.index - b.index);
...@@ -117,9 +117,7 @@ export class InstantiationService implements IInstantiationService { ...@@ -117,9 +117,7 @@ export class InstantiationService implements IInstantiationService {
argArray.push(...staticArgs); argArray.push(...staticArgs);
argArray.push(...serviceArgs); argArray.push(...serviceArgs);
const instance = create.apply(null, argArray); return <T>create.apply(null, argArray);
desc._validate(instance);
return <T>instance;
} }
private _getOrCreateServiceInstance<T>(id: ServiceIdentifier<T>): T { private _getOrCreateServiceInstance<T>(id: ServiceIdentifier<T>): T {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册