ryo-mutations 0.1.0

[experimental] Code transformation primitives for Rust source code
Documentation
//! RemoveStatementMutation: Remove statements matching a target
//!
//! Removes statements that match the target statement:
//! ```ignore
//! fn example() {
//!     println!("debug");  // removed
//!     do_work();
//!     println!("debug");  // removed
//! }
//! ```

use ryo_source::pure::PureStmt;
use ryo_symbol::SymbolId;

use crate::Mutation;

/// Remove statements matching a target statement
#[derive(Debug, Clone)]
pub struct RemoveStatementMutation {
    /// Target statement to match and remove
    pub target_stmt: PureStmt,
    /// Original pattern string for flexible matching (e.g., "println!(..)")
    pub pattern: String,
    /// Target function SymbolId
    pub target_fn: SymbolId,
    /// Remove all occurrences (true) or just first (false)
    pub remove_all: bool,
}

impl RemoveStatementMutation {
    pub fn new(target_stmt: PureStmt, pattern: String, target_fn: SymbolId) -> Self {
        Self {
            target_stmt,
            pattern,
            target_fn,
            remove_all: true,
        }
    }

    /// Remove only the first occurrence
    pub fn first_only(mut self) -> Self {
        self.remove_all = false;
        self
    }
}

impl Mutation for RemoveStatementMutation {
    fn describe(&self) -> String {
        "Remove statements matching target".to_string()
    }

    fn mutation_type(&self) -> &'static str {
        "RemoveStatement"
    }

    fn box_clone(&self) -> Box<dyn Mutation> {
        Box::new(self.clone())
    }
}