/** * @angular-modernizer/plugin-angular - Service Injection Cleanup Orchestrator * * The central "brain" of the service injection cleanup transformation plugin. * Orchestrates the cleanup of manual service instantiations to use dependency injection. * * Philosophy: "API-Driven Orchestration" * - Receives all capabilities via TransformContext * - Uses PublicApi for all AST operations * - Stateless - no constructor dependencies * - Pure business logic, no low-level manipulation */ import type { TransformContext } from '@angular-modernizer/plugin-system'; import type { PublicApi } from '@angular-modernizer/api'; /** * Service Injection Cleanup Orchestrator * * @remarks * The central orchestrator for cleaning up manual service instantiations and converting * them to proper dependency injection using the inject() function. This class demonstrates * the "API-Driven Plugin" pattern where all capabilities are received via context objects * rather than constructor injection. * * ## Architecture Pattern * * This orchestrator follows three core principles: * 1. **Stateless Design** - No constructor dependencies * 2. **Context-Driven** - All capabilities injected via {@link TransformContext} * 3. **API-First** - Uses {@link PublicApi} for all AST operations * * ## Transformation Workflow * * The orchestrator performs the following steps: * 1. Find classes with manual service instantiations (`new Service()`) * 2. Identify service types using common Angular service patterns * 3. Convert manual instantiations to `inject(Service)` calls * 4. Remove manual instantiation statements from constructors and methods * 5. Clean up empty constructors and ensure proper imports * * ## Example Usage * * ```typescript * const orchestrator = new ServiceInjectionCleanupOrchestrator(); * const context = ContextFactory.createTransformContext({ * sourceFile, * project, * api, * config: {} * }); * orchestrator.run(context); * ``` * * @see {@link TransformContext} for context structure * @see {@link PublicApi} for available API tools * * @public */ export declare class ServiceInjectionCleanupOrchestrator { /** * Creates a new ServiceInjectionCleanupOrchestrator instance. * * @remarks * The constructor is intentionally stateless. All dependencies are provided * through the {@link TransformContext} passed to the {@link run} method. * This enables testing, composition, and prevents tight coupling. * * @public */ constructor(); /** * Executes the service injection cleanup transformation on a single source file. * * @remarks * This method is the main entry point for the orchestrator. It receives all * necessary dependencies (project, API, config) through the context parameter, * scans the file for classes with manual service instantiations, and converts * them to proper dependency injection. * * The method operates on one source file at a time and is safe to call * multiple times. It will: * - Find all classes in the file * - Identify manual service instantiations * - Convert them to inject() calls * - Clean up constructors and methods * - Ensure proper imports are in place * * ## Transformation Behavior * * **Property Initializers**: * ```typescript * // Before * private httpClient = new HttpClient(); * * // After * private httpClient = inject(HttpClient); * ``` * * **Constructor Assignments**: * ```typescript * // Before * constructor() { * this.userService = new UserService(); * } * * // After * private userService = inject(UserService); * ``` * * **Method Assignments**: * ```typescript * // Before * ngOnInit() { * this.logger = new LoggerService(); * } * * // After * private logger = inject(LoggerService); * ``` * * @param context - The transformation context containing: * - `sourceFile`: The TypeScript source file to transform * - `project`: The ts-morph Project for cross-file analysis * - `api`: The PublicApi with analysis and transformation tools * - `config`: User-provided configuration options * * @example * ```typescript * // Basic usage * orchestrator.run(context); * * // With custom configuration * const context = ContextFactory.createTransformContext({ * sourceFile, * project, * api, * config: { servicePatterns: ['CustomService$'] } * }); * orchestrator.run(context); * ``` * * @see {@link TransformContext} for context structure * * @public */ run(context: TransformContext): void; /** * Process a single class for service injection cleanup. * * @param classDecl - The class declaration to process * @param context - Transform context with PublicApi access * * @private */ private processClass; /** * Find all manual service instantiations in a class. * * @param classDecl - The class declaration to analyze * @param context - Transform context with PublicApi access * @returns Array of manual instantiation details * * @private */ private findManualServiceInstantiations; /** * Check if an expression is a manual service instantiation. * * @param expression - The expression to check * @param context - Transform context with PublicApi access * @returns True if it's a manual service instantiation * * @private */ private isManualServiceInstantiation; /** * Check if a type name represents a service using ServicePatternRecognizer. * * Uses centralized service detection with confidence scoring: * - 1.0: @Injectable decorator present * - 0.7: Class name matches service patterns * - 0.6: File name matches .service.ts pattern * * For cleanup scenarios, uses lower confidence threshold (0.6) to capture * more potential services for migration. * * @param typeName - The type name to check * @param context - Transform context with PublicApi access * @returns True if the type matches service patterns * * @private */ private isServiceType; /** * Find the source file containing a class definition. * * @param className - The class name to search for * @param context - Transform context with project access * @returns Source file if found, undefined otherwise * * @private */ private findSourceFileForClass; /** * Extract the service type from an instantiation expression. * * @param expression - The instantiation expression * @returns The service type name or null * * @private */ private getServiceTypeFromInstantiation; /** * Convert manual instantiations to inject() calls. * * @param classDecl - The class declaration * @param instantiations - The manual instantiations to convert * * @private */ private convertToInjectCalls; /** * Remove empty constructors that only contained manual instantiations. * * @param classDecl - The class declaration * * @private */ private removeEmptyConstructors; /** * Ensure the inject function is imported from @angular/core. * * @param sourceFile - The source file to add the import to * * @private */ private ensureInjectImport; } //# sourceMappingURL=service-injection-cleanup-orchestrator.d.ts.map