DebugProtectionFunctionCallNode.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { inject, injectable, } from 'inversify';
  2. import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
  3. import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
  4. import { TStatement } from '../../types/node/TStatement';
  5. import { IOptions } from '../../interfaces/options/IOptions';
  6. import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
  7. import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
  8. import { initializable } from '../../decorators/Initializable';
  9. import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate';
  10. import { AbstractCustomNode } from '../AbstractCustomNode';
  11. import { NodeUtils } from '../../node/NodeUtils';
  12. @injectable()
  13. export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
  14. /**
  15. * @type {string}
  16. */
  17. @initializable()
  18. private callsControllerFunctionName!: string;
  19. /**
  20. * @type {string}
  21. */
  22. @initializable()
  23. private debugProtectionFunctionName!: string;
  24. /**
  25. * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
  26. * @param {ICustomNodeFormatter} customNodeFormatter
  27. * @param {IRandomGenerator} randomGenerator
  28. * @param {IOptions} options
  29. */
  30. constructor (
  31. @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
  32. identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
  33. @inject(ServiceIdentifiers.ICustomNodeFormatter) customNodeFormatter: ICustomNodeFormatter,
  34. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  35. @inject(ServiceIdentifiers.IOptions) options: IOptions
  36. ) {
  37. super(identifierNamesGeneratorFactory, customNodeFormatter, randomGenerator, options);
  38. }
  39. /**
  40. * @param {string} debugProtectionFunctionName
  41. * @param {string} callsControllerFunctionName
  42. */
  43. public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void {
  44. this.debugProtectionFunctionName = debugProtectionFunctionName;
  45. this.callsControllerFunctionName = callsControllerFunctionName;
  46. }
  47. /**
  48. * @param {string} nodeTemplate
  49. * @returns {TStatement[]}
  50. */
  51. protected getNodeStructure (nodeTemplate: string): TStatement[] {
  52. return NodeUtils.convertCodeToStructure(nodeTemplate);
  53. }
  54. /**
  55. * @returns {string}
  56. */
  57. protected getNodeTemplate (): string {
  58. return this.customNodeFormatter.formatTemplate(DebugProtectionFunctionCallTemplate(), {
  59. debugProtectionFunctionName: this.debugProtectionFunctionName,
  60. singleNodeCallControllerFunctionName: this.callsControllerFunctionName
  61. });
  62. }
  63. }