ryo-mutations 0.1.0

[experimental] Code transformation primitives for Rust source code
Documentation
//! ReplaceStatementMutation: Replace statements with other statements
//!
//! Replaces statements matching a pattern with a new statement:
//! ```ignore
//! fn example() {
//!     old_statement();  // -> new_statement();
//!     other_work();
//! }
//! ```

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

use crate::Mutation;

/// Replace a statement with another statement
#[derive(Debug, Clone)]
pub struct ReplaceStatementMutation {
    /// Statement pattern to find
    pub old_stmt: PureStmt,
    /// Replacement statement
    pub new_stmt: PureStmt,
    /// Target function SymbolId
    pub target_fn: SymbolId,
}

impl ReplaceStatementMutation {
    pub fn new(old_stmt: PureStmt, new_stmt: PureStmt, target_fn: SymbolId) -> Self {
        Self {
            old_stmt,
            new_stmt,
            target_fn,
        }
    }
}

impl Mutation for ReplaceStatementMutation {
    fn describe(&self) -> String {
        "Replace statement with another statement".to_string()
    }

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

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