Skip to main content

ryo_mutations/basic/stmt/
replace_statement.rs

1//! ReplaceStatementMutation: Replace statements with other statements
2//!
3//! Replaces statements matching a pattern with a new statement:
4//! ```ignore
5//! fn example() {
6//!     old_statement();  // -> new_statement();
7//!     other_work();
8//! }
9//! ```
10
11use ryo_source::pure::PureStmt;
12use ryo_symbol::SymbolId;
13
14use crate::Mutation;
15
16/// Replace a statement with another statement
17#[derive(Debug, Clone)]
18pub struct ReplaceStatementMutation {
19    /// Statement pattern to find
20    pub old_stmt: PureStmt,
21    /// Replacement statement
22    pub new_stmt: PureStmt,
23    /// Target function SymbolId
24    pub target_fn: SymbolId,
25}
26
27impl ReplaceStatementMutation {
28    pub fn new(old_stmt: PureStmt, new_stmt: PureStmt, target_fn: SymbolId) -> Self {
29        Self {
30            old_stmt,
31            new_stmt,
32            target_fn,
33        }
34    }
35}
36
37impl Mutation for ReplaceStatementMutation {
38    fn describe(&self) -> String {
39        "Replace statement with another statement".to_string()
40    }
41
42    fn mutation_type(&self) -> &'static str {
43        "ReplaceStatement"
44    }
45
46    fn box_clone(&self) -> Box<dyn Mutation> {
47        Box::new(self.clone())
48    }
49}