pub(super) use crate::adapters::analyzers::srp::cohesion::*;
pub(super) use crate::adapters::analyzers::srp::{MethodFieldData, StructInfo};
pub(super) use crate::config::sections::SrpConfig;
pub(super) use std::collections::{HashMap, HashSet};
mod lcom4_and_collector;
mod scoring;
mod warnings;
pub(super) type Lcom4Case = (
&'static str,
&'static [(
&'static str,
&'static [&'static str],
&'static [&'static str],
)],
&'static [&'static str],
usize,
Option<usize>,
);
pub(super) type Lcom4CtorCase = (
&'static str,
&'static [(&'static str, &'static [&'static str])],
&'static [&'static str],
&'static [&'static str],
usize,
);
pub(super) fn make_method(
name: &str,
parent: &str,
fields: &[&str],
calls: &[&str],
) -> MethodFieldData {
MethodFieldData {
method_name: name.to_string(),
parent_type: parent.to_string(),
field_accesses: fields.iter().map(|s| s.to_string()).collect(),
call_targets: calls.iter().map(|s| s.to_string()).collect(),
self_method_calls: HashSet::new(),
is_constructor: false,
}
}
pub(super) fn make_method_with_self_calls(
name: &str,
parent: &str,
fields: &[&str],
self_calls: &[&str],
) -> MethodFieldData {
MethodFieldData {
method_name: name.to_string(),
parent_type: parent.to_string(),
field_accesses: fields.iter().map(|s| s.to_string()).collect(),
call_targets: HashSet::new(),
self_method_calls: self_calls.iter().map(|s| s.to_string()).collect(),
is_constructor: false,
}
}
pub(super) fn make_constructor(name: &str, parent: &str, calls: &[&str]) -> MethodFieldData {
MethodFieldData {
method_name: name.to_string(),
parent_type: parent.to_string(),
field_accesses: HashSet::new(),
call_targets: calls.iter().map(|s| s.to_string()).collect(),
self_method_calls: HashSet::new(),
is_constructor: true,
}
}
pub(super) fn make_struct(name: &str, fields: &[&str]) -> StructInfo {
StructInfo {
name: name.to_string(),
file: "test.rs".to_string(),
line: 1,
fields: fields.iter().map(|s| s.to_string()).collect(),
}
}
pub(super) fn collect_methods_for(code: &str) -> Vec<MethodFieldData> {
let syntax = syn::parse_file(code).expect("parse test fixture");
let parsed = vec![("test.rs".to_string(), code.to_string(), syntax)];
let mut result = Vec::new();
let mut bridges = Vec::new();
let mut collector = crate::adapters::analyzers::srp::ImplMethodCollector {
file: String::new(),
methods: &mut result,
bridges: &mut bridges,
};
crate::adapters::shared::file_visitor::visit_all_files(&parsed, &mut collector);
result
}