From 27782ee71b9e5d0e2308a0965e77b297d63b2422 Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 20 Oct 2015 13:54:05 -0700 Subject: [PATCH] translate -> transform --- adapter/adapterProxy.ts | 40 +++++++++---------- ...Translator.ts => lineNumberTransformer.ts} | 2 +- tsconfig.json | 2 +- webkit/webKitAdapterInterfaces.d.ts | 2 +- webkit/webKitDebugSession.ts | 4 +- 5 files changed, 25 insertions(+), 25 deletions(-) rename adapter/{lineNumberTranslator.ts => lineNumberTransformer.ts} (96%) diff --git a/adapter/adapterProxy.ts b/adapter/adapterProxy.ts index 6437465..528f5d0 100644 --- a/adapter/adapterProxy.ts +++ b/adapter/adapterProxy.ts @@ -7,7 +7,7 @@ import Utilities = require('../webkit/utilities'); export type EventHandler = (event: DebugProtocol.Event) => void; export class AdapterProxy { - public constructor(private _requestTranslators: IDebugTranslator[], private _debugAdapter: IDebugAdapter, private _eventHandler: EventHandler) { + public constructor(private _requestTransformers: IDebugTransformer[], private _debugAdapter: IDebugAdapter, private _eventHandler: EventHandler) { this._debugAdapter.registerEventHandler(this._eventHandler); } @@ -16,45 +16,45 @@ export class AdapterProxy { Promise.reject('unknowncommand'); } - return this.translateRequest(request) + return this.transformRequest(request) // Pass the modified args to the adapter .then(() => this._debugAdapter[request.command](request.arguments)) - // Pass the body back through the translators and ensure the body is returned + // Pass the body back through the transformers and ensure the body is returned .then((body?) => { - return this.translateResponse(request, body) + return this.transformResponse(request, body) .then(() => body); }); } /** - * Pass the request arguments through the translators. They modify the object in place. + * Pass the request arguments through the transformers. They modify the object in place. */ - private translateRequest(request: DebugProtocol.Request): Promise { - return this._requestTranslators.reduce( - (p, translator) => { - // If the translator implements this command, give it a chance to modify the args. Otherwise skip it - return request.command in translator ? - p.then(() => translator[request.command](request.arguments)) : + private transformRequest(request: DebugProtocol.Request): Promise { + return this._requestTransformers.reduce( + (p, transformer) => { + // If the transformer implements this command, give it a chance to modify the args. Otherwise skip it + return request.command in transformer ? + p.then(() => transformer[request.command](request.arguments)) : p; }, Promise.resolve()) } /** - * Pass the response body back through the translators in reverse order. They modify the body in place. + * Pass the response body back through the transformers in reverse order. They modify the body in place. */ - private translateResponse(request: DebugProtocol.Request, body: any): Promise { + private transformResponse(request: DebugProtocol.Request, body: any): Promise { if (!body) { return Promise.resolve(); } - const reversedTranslators = Utilities.reversedArr(this._requestTranslators); - return reversedTranslators.reduce( - (p, translator) => { - // If the translator implements this command, give it a chance to modify the args. Otherwise skip it - const bodyTranslateMethodName = request.command + "Response"; - return bodyTranslateMethodName in translator ? - p.then(() => translator[bodyTranslateMethodName](body)) : + const reversedTransformers = Utilities.reversedArr(this._requestTransformers); + return reversedTransformers.reduce( + (p, transformer) => { + // If the transformer implements this command, give it a chance to modify the args. Otherwise skip it + const bodyTransformMethodName = request.command + "Response"; + return bodyTransformMethodName in transformer ? + p.then(() => transformer[bodyTransformMethodName](body)) : p; }, Promise.resolve()); } diff --git a/adapter/lineNumberTranslator.ts b/adapter/lineNumberTransformer.ts similarity index 96% rename from adapter/lineNumberTranslator.ts rename to adapter/lineNumberTransformer.ts index d6dabfa..2cdc163 100644 --- a/adapter/lineNumberTranslator.ts +++ b/adapter/lineNumberTransformer.ts @@ -5,7 +5,7 @@ /** * Converts from 1 based lines on the client side to 0 based lines on the target side */ -export class LineNumberTranslator { +export class LineNumberTransformer implements IDebugTransformer { private _targetLinesStartAt1: boolean; private _clientLinesStartAt1: boolean; diff --git a/tsconfig.json b/tsconfig.json index a40fede..a408875 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ }, "files": [ "adapter/adapterProxy.ts", - "adapter/lineNumberTranslator.ts", + "adapter/lineNumberTransformer.ts", "webkit/openDebugWebKit.ts", "webkit/pathUtilities.ts", "webkit/sourceMaps.ts", diff --git a/webkit/webKitAdapterInterfaces.d.ts b/webkit/webKitAdapterInterfaces.d.ts index 8a3fa64..f2b58c0 100644 --- a/webkit/webKitAdapterInterfaces.d.ts +++ b/webkit/webKitAdapterInterfaces.d.ts @@ -76,7 +76,7 @@ interface IDebugAdapter { } declare type PromiseOrNot = T | Promise; -interface IDebugTranslator { +interface IDebugTransformer { initialize?(args: IInitializeRequestArgs): PromiseOrNot; launch?(args: ILaunchRequestArgs): PromiseOrNot; attach?(args: IAttachRequestArgs): PromiseOrNot; diff --git a/webkit/webKitDebugSession.ts b/webkit/webKitDebugSession.ts index b08b6ba..9fce7f2 100644 --- a/webkit/webKitDebugSession.ts +++ b/webkit/webKitDebugSession.ts @@ -7,7 +7,7 @@ import {DebugSession, ErrorDestination} from '../common/debugSession'; import {WebKitDebugAdapter} from './webKitDebugAdapter'; import {AdapterProxy} from '../adapter/adapterProxy'; -import {LineNumberTranslator} from '../adapter/lineNumberTranslator'; +import {LineNumberTransformer} from '../adapter/lineNumberTransformer'; export class WebKitDebugSession extends DebugSession { private _adapterProxy: AdapterProxy; @@ -16,7 +16,7 @@ export class WebKitDebugSession extends DebugSession { super(targetLinesStartAt1, isServer); this._adapterProxy = new AdapterProxy( - [new LineNumberTranslator(targetLinesStartAt1)], + [new LineNumberTransformer(targetLinesStartAt1)], new WebKitDebugAdapter(), event => this.sendEvent(event)); }