ryo-executor 0.1.0

[experimental] Mutation execution engine for RYO - parallel execution, conflict detection, workspace management
Documentation
//! RemoveConverter: Converts MutationSpec::RemoveItem

use crate::engine::ASTRegApply;
use crate::executor::registry::converters::ResolveTargetSymbol;
use crate::executor::registry::{ConvertError, MutationConverter};
use crate::executor::spec::MutationSpec;
use ryo_analysis::AnalysisContext;
use ryo_mutations::RemoveItemMutation;

/// Converter for RemoveItem mutations
#[derive(Debug, Clone, Default)]
pub struct RemoveConverter;

impl RemoveConverter {
    pub fn new() -> Self {
        Self
    }
}

// RemoveConverter uses the default implementation of ResolveTargetSymbol
impl ResolveTargetSymbol for RemoveConverter {}

impl MutationConverter for RemoveConverter {
    fn spec_kinds(&self) -> &'static [&'static str] {
        &["RemoveItem"]
    }

    fn convert_v2(
        &self,
        spec: &MutationSpec,
        ctx: &AnalysisContext,
    ) -> Result<Vec<Box<dyn ASTRegApply>>, ConvertError> {
        match spec {
            MutationSpec::RemoveItem {
                target: target_symbol,
                item_kind,
            } => {
                // Resolve target_symbol to SymbolId
                let symbol_id = self.resolve_target_symbol(target_symbol, ctx)?;
                let mutation = RemoveItemMutation::new(symbol_id, *item_kind);
                Ok(vec![Box::new(mutation)])
            }
            _ => Err(ConvertError::TypeMismatch {
                expected: "RemoveItem",
                actual: spec.kind_name().to_string(),
            }),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use ryo_source::ItemKind;
    use ryo_symbol::SymbolId;

    #[test]
    fn test_remove_converter_spec_kinds() {
        let converter = RemoveConverter::new();
        assert_eq!(converter.spec_kinds(), &["RemoveItem"]);
    }

    #[test]
    fn test_remove_converter_can_handle() {
        let converter = RemoveConverter::new();

        let spec = MutationSpec::RemoveItem {
            target: crate::executor::spec::MutationTargetSymbol::ById(SymbolId::default()),
            item_kind: ItemKind::Struct,
        };
        assert!(converter.can_handle(&spec));
    }
}