pub trait LanguageAnalyzer: Send + Sync {
// Required methods
fn file_extensions(&self) -> &[&str];
fn parse_file(
&self,
path: &Path,
source: &str,
config: &AnalysisConfig,
) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>>;
fn is_test_code(&self, unit: &CodeUnit) -> bool;
}Expand description
Trait for language-specific code analysis.
Implementors provide file-extension detection and parsing logic,
allowing dry4rust to work with any language.
Test code handling: Analyzers should set CodeUnit::is_test to true
for test functions, test modules, etc. The crate::analysis::analyze function will
filter them out when Config::exclude_tests is enabled, using LanguageAnalyzer::is_test_code.
Required Methods§
Sourcefn file_extensions(&self) -> &[&str]
fn file_extensions(&self) -> &[&str]
File extensions this analyzer handles (without the leading dot).
Sourcefn parse_file(
&self,
path: &Path,
source: &str,
config: &AnalysisConfig,
) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>>
fn parse_file( &self, path: &Path, source: &str, config: &AnalysisConfig, ) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>>
Parse a single source file into code units.
path is the file’s location (for diagnostics), source is the file content,
and config carries min-node / min-line thresholds.
Analyzers should tag test code via CodeUnit::is_test rather than
filtering it out; the caller handles exclusion.
Sourcefn is_test_code(&self, unit: &CodeUnit) -> bool
fn is_test_code(&self, unit: &CodeUnit) -> bool
Check whether a code unit represents test code.
Required rather than defaulted: an analyser that cannot tell test code from production code should have to say so, not inherit an answer.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".