use crate::checkstyle::api::error::CheckstyleResult;
pub trait Configurable: Send + Sync {
fn configure(&mut self, config: &Configuration) -> CheckstyleResult<()>;
}
#[derive(Debug, Clone)]
pub struct Configuration {
pub name: String,
pub properties: std::collections::HashMap<String, String>,
pub children: Vec<Configuration>,
}
impl Configuration {
pub fn new(name: String) -> Self {
Self {
name,
properties: std::collections::HashMap::new(),
children: Vec::new(),
}
}
pub fn add_property(&mut self, key: String, value: String) {
self.properties.insert(key, value);
}
pub fn get_property(&self, key: &str) -> Option<&String> {
self.properties.get(key)
}
pub fn add_child(&mut self, child: Configuration) {
self.children.push(child);
}
pub fn get_children(&self) -> &[Configuration] {
&self.children
}
}
pub trait Contextualizable: Send + Sync {
fn contextualize(&mut self, context: &Context) -> CheckstyleResult<()>;
}
#[derive(Debug, Clone)]
pub struct Context {
pub severity: crate::checkstyle::api::event::SeverityLevel,
pub tab_width: usize,
pub data: std::collections::HashMap<String, String>,
}
impl Context {
pub fn new() -> Self {
Self {
severity: crate::checkstyle::api::event::SeverityLevel::Error,
tab_width: 4,
data: std::collections::HashMap::new(),
}
}
}
impl Default for Context {
fn default() -> Self {
Self::new()
}
}