Skip to main content

ryo_mutations/basic/stmt/
remove_statement.rs

1//! RemoveStatementMutation: Remove statements matching a target
2//!
3//! Removes statements that match the target statement:
4//! ```ignore
5//! fn example() {
6//!     println!("debug");  // removed
7//!     do_work();
8//!     println!("debug");  // removed
9//! }
10//! ```
11
12use ryo_source::pure::PureStmt;
13use ryo_symbol::SymbolId;
14
15use crate::Mutation;
16
17/// Remove statements matching a target statement
18#[derive(Debug, Clone)]
19pub struct RemoveStatementMutation {
20    /// Target statement to match and remove
21    pub target_stmt: PureStmt,
22    /// Original pattern string for flexible matching (e.g., "println!(..)")
23    pub pattern: String,
24    /// Target function SymbolId
25    pub target_fn: SymbolId,
26    /// Remove all occurrences (true) or just first (false)
27    pub remove_all: bool,
28}
29
30impl RemoveStatementMutation {
31    pub fn new(target_stmt: PureStmt, pattern: String, target_fn: SymbolId) -> Self {
32        Self {
33            target_stmt,
34            pattern,
35            target_fn,
36            remove_all: true,
37        }
38    }
39
40    /// Remove only the first occurrence
41    pub fn first_only(mut self) -> Self {
42        self.remove_all = false;
43        self
44    }
45}
46
47impl Mutation for RemoveStatementMutation {
48    fn describe(&self) -> String {
49        "Remove statements matching target".to_string()
50    }
51
52    fn mutation_type(&self) -> &'static str {
53        "RemoveStatement"
54    }
55
56    fn box_clone(&self) -> Box<dyn Mutation> {
57        Box::new(self.clone())
58    }
59}