/** * @angular-modernizer/plugin-angular - Inheritance to Composition Transform Rule * * Transform rule that refactors inheritance patterns to composition using dependency injection. * This rule wraps the InheritanceAnalyzer and InheritanceToCompositionTransformer from the core package. */ import type { TransformRule, TransformContext, TransformResult } from '@angular-modernizer/plugin-system'; /** * Transform rule for refactoring inheritance to composition. * * @remarks * This rule detects classes that extend base classes and refactors them to use * composition via dependency injection instead. It extracts base class methods * into separate services and updates the derived class to inject those services. * * ## Pattern Detection * - Detects classes with `extends` clauses * - Analyzes method usage and extractability * - Calculates confidence scores based on complexity * * ## Transformation Strategy * 1. Analyze inheritance patterns in the source file * 2. Filter patterns by confidence threshold * 3. For each high-confidence pattern: * - Extract base class methods into a new service * - Remove the extends clause from the derived class * - Add constructor parameter for the extracted service * - Update method calls to use the injected service * - Add Angular dependency injection decorators * * ## Configuration Options * - `minConfidence`: Minimum confidence score (0-1) to perform transformation (default: 0.8) * - `requireApproval`: Require user approval for medium-confidence transformations (default: false) * - `safeMode`: Generate only high-confidence transformations (default: false) * - `preserveOriginalAsComments`: Preserve original code as comments (default: false) * - `useInjectFunction`: Use modern inject() function instead of constructor injection (default: true) * * @example * ```typescript * // Before transformation * export class CustomDateAdapter extends NativeDateAdapter { * parse(value: any): Date | null { ... } * format(date: Date, displayFormat: any): string { ... } * } * * // After transformation (with extract strategy) * @Injectable() * export class DateFormattingService { * parse(value: any): Date | null { ... } * format(date: Date, displayFormat: any): string { ... } * } * * @Injectable() * export class CustomDateAdapter { * constructor( * private dateFormatting: DateFormattingService, * private nativeDateAdapter: NativeDateAdapter * ) {} * } * ``` */ export declare class InheritanceToCompositionRule implements TransformRule { /** * Unique rule identifier. */ readonly id = "angular:transform:inheritance-to-composition"; /** * Human-readable rule name. */ readonly name = "Inheritance to Composition"; /** * Rule description. */ readonly description = "Refactor inheritance patterns to composition using dependency injection"; /** * Rule category for grouping. */ readonly category = "refactoring"; /** * Tags for filtering and search. */ readonly tags: string[]; /** * Transform a source file by refactoring inheritance to composition. * * @param context - Transformation context with source file and configuration * * @returns Transformation result with success status and change details */ transform(context: TransformContext): Promise; } //# sourceMappingURL=inheritance-to-composition.rule.d.ts.map