Angular Modernizer
    Preparing search index...

    God Switch Transform Orchestrator

    The central orchestrator for transforming God Switch patterns into Factory Pattern. This class analyzes large switch statements and refactors them into maintainable strategy-based implementations using the Factory Pattern.

    This orchestrator follows three core principles:

    1. Stateless Design - No constructor dependencies
    2. Context-Driven - All capabilities injected via TransformContext
    3. API-First - Uses ts-morph for all AST operations

    The orchestrator performs the following transformations:

    1. Find all God Switch violations in the source file
    2. Extract switch metadata (expression, cases, return type)
    3. Generate strategy interface with execute() method
    4. Generate strategy classes (one per case)
    5. Generate factory class with strategy instantiation
    6. Replace switch statement with factory call
    7. Update imports as needed
    const orchestrator = new GodSwitchTransformOrchestrator();
    const context = ContextFactory.createTransformContext({
    sourceFile,
    project,
    api,
    config: { godSwitch: { minCaseCount: 10 } }
    });
    orchestrator.run(context);
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Executes the God Switch transformation on a single source file.

      Parameters

      • context: TransformContext<PublicApi>

        The transformation context containing:

        • sourceFile: The TypeScript source file to analyze
        • project: The ts-morph Project for cross-file operations
        • api: The PublicApi with analysis and transformation tools
        • config: User-provided configuration options

      Returns void

      This method is the main entry point for the orchestrator. It receives all necessary dependencies (project, API, config) through the context parameter, analyzes switch statements, and transforms them into Factory Pattern.

      The method operates on one source file at a time and is safe to call multiple times. It will:

      • Find all God Switch violations (switches exceeding case threshold)
      • Extract metadata from each switch statement
      • Generate strategy interface, classes, and factory
      • Replace switch with factory call
      • Update imports

      Switch Analysis:

      • Identifies switch statements exceeding configured case threshold
      • Extracts case labels, logic, and return values
      • Analyzes captured variables from outer scope

      Code Generation:

      • Creates IStrategy interface with execute() method signature
      • Generates one strategy class per case implementing IStrategy
      • Creates factory class with strategy instantiation mapping

      Code Replacement:

      • Replaces switch statement with factory instantiation and execute call
      • Preserves original switch in comment for reference
      • Updates imports for new classes

      Idempotency: Checks if factory/strategies already exist before generating Atomicity: Uses try-catch with rollback on error Reversibility: Preserves original switch in comments with transformation metadata

      // Basic usage
      orchestrator.run(context);

      // With custom configuration
      const context = ContextFactory.createTransformContext({
      sourceFile,
      project,
      api,
      config: {
      '@angular-modernizer/plugin-solid': {
      godSwitch: {
      minCaseCount: 15,
      generateInterfaces: true,
      strategyNamingPattern: '{CaseValue}Handler'
      }
      }
      }
      });
      orchestrator.run(context);