#![cfg_attr(coverage_nightly, coverage(off))]
use super::types::*;
use std::fs;
use std::path::{Path, PathBuf};
const SKIP_DIRS: &[&str] = &[
".git",
".claude",
"node_modules",
"target",
".pmat",
"vendor",
"build",
"dist",
".bsp",
".metals",
".bloop",
".idea",
"project/target",
];
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn walkdir_scala_files(dir: &Path) -> Vec<PathBuf> {
let mut files = Vec::new();
walk_scala_recursive(dir, &mut files);
files
}
fn walk_scala_recursive(dir: &Path, files: &mut Vec<PathBuf>) {
let entries = match fs::read_dir(dir) {
Ok(e) => e,
Err(_) => return,
};
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
let dir_name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
if !SKIP_DIRS.contains(&dir_name) {
walk_scala_recursive(&path, files);
}
} else if path
.extension()
.and_then(|e| e.to_str())
.map(|e| matches!(e, "scala" | "sc"))
.unwrap_or(false)
{
files.push(path);
}
}
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn is_scala_test_file(path: &Path) -> bool {
let stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
if stem.ends_with("Test")
|| stem.ends_with("Spec")
|| stem.ends_with("Suite")
|| stem.starts_with("Test")
{
return true;
}
path.components().any(|c| {
let s = c.as_os_str().to_str().unwrap_or("");
s == "test" || s == "tests" || s == "it" || s == "spec"
})
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "score_range")]
pub fn compute_scala_production_lines(content: &str) -> Vec<(usize, String)> {
let mut result = Vec::new();
let mut in_block_comment = false;
for (i, line) in content.lines().enumerate() {
let trimmed = line.trim();
if in_block_comment {
if trimmed.contains("*/") {
in_block_comment = false;
}
continue;
}
if trimmed.starts_with("/*") {
if !trimmed.contains("*/") {
in_block_comment = true;
}
continue;
}
if trimmed.starts_with("//") || trimmed.is_empty() {
continue;
}
let line_content = if let Some(pos) = trimmed.find("//") {
if pos > 0 && &trimmed[pos - 1..pos] == ":" {
trimmed
} else {
trimmed[..pos].trim()
}
} else {
trimmed
};
if !line_content.is_empty() {
result.push((i + 1, line_content.to_string()));
}
}
result
}
include!("scala_bp_mutable_null_wildcard.rs");
include!("scala_bp_return_var_future.rs");