#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::path::Path;
use std::sync::Arc;
pub mod duplicates;
pub mod integration_tests;
pub mod polyglot;
pub mod satd;
#[async_trait]
pub trait Detector: Send + Sync {
type Input;
type Output;
type Config;
async fn detect(&self, input: Self::Input, config: Self::Config) -> Result<Self::Output>;
fn name(&self) -> &'static str;
fn capabilities(&self) -> DetectorCapabilities;
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DetectorCapabilities {
pub supports_batch: bool,
pub supports_streaming: bool,
pub language_agnostic: bool,
pub requires_ast: bool,
}
pub struct DetectionRegistry {
detectors: std::collections::HashMap<
String,
Arc<
dyn Detector<
Input = DetectionInput,
Output = DetectionOutput,
Config = DetectionConfig,
>,
>,
>,
}
#[derive(Debug, Clone)]
pub enum DetectionInput {
SingleFile(std::path::PathBuf),
MultipleFiles(Vec<std::path::PathBuf>),
ProjectDirectory(std::path::PathBuf),
Content(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DetectionOutput {
Duplicates(duplicates::DuplicateDetectionResult),
SATD(satd::SATDAnalysisResult),
Polyglot(polyglot::PolyglotAnalysis),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DetectionConfig {
pub max_files: Option<usize>,
pub parallel_processing: bool,
pub output_format: OutputFormat,
pub detector_specific: DetectorSpecificConfig,
}
pub use crate::contracts::OutputFormat;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DetectorSpecificConfig {
Duplicates(duplicates::DuplicateConfig),
SATD(satd::SATDConfig),
Polyglot(polyglot::PolyglotConfig),
}
include!("registry_impl.rs");
include!("unified_processor.rs");
include!("tests_detection.rs");