Creates a new GodSwitchTransformOrchestrator instance.
The constructor is intentionally stateless. All dependencies are provided through the TransformContext passed to the run method. This enables testing, composition, and prevents tight coupling.
Executes the God Switch transformation on a single source file.
The transformation context containing:
sourceFile: The TypeScript source file to analyzeproject: The ts-morph Project for cross-file operationsapi: The PublicApi with analysis and transformation toolsconfig: User-provided configuration optionsThis 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:
Switch Analysis:
Code Generation:
Code Replacement:
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);
God Switch Transform Orchestrator
Remarks
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.
Architecture Pattern
This orchestrator follows three core principles:
Transformation Workflow
The orchestrator performs the following transformations:
Example Usage
See