ryo-executor 0.1.0

[experimental] Mutation execution engine for RYO - parallel execution, conflict detection, workspace management
Documentation
//! DeriveConverter: Converts MutationSpec::AddDerive and RemoveDerive

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::{AddDeriveMutation, RemoveDeriveMutation};

/// Converter for Derive mutations (AddDerive, RemoveDerive)
#[derive(Debug, Clone, Default)]
pub struct DeriveConverter;

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

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

impl MutationConverter for DeriveConverter {
    fn spec_kinds(&self) -> &'static [&'static str] {
        &["AddDerive", "RemoveDerive"]
    }

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

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_derive_converter_spec_kinds() {
        let converter = DeriveConverter::new();
        assert_eq!(converter.spec_kinds(), &["AddDerive", "RemoveDerive"]);
    }
}