Skip to content

Commit f64a6a1

Browse files
committed
rust: Transformation trait refactoring
1 parent ea3a5b3 commit f64a6a1

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

rust/bear/src/modes/semantic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::intercept::Envelope;
44
use crate::output::OutputWriter;
55
use crate::semantic::interpreters::create_interpreter;
6+
use crate::semantic::transformation;
67
use crate::semantic::transformation::FilterAndFormat;
78
use crate::{args, config, output, semantic};
89
use anyhow::Context;
@@ -13,7 +14,7 @@ use std::path::{Path, PathBuf};
1314
/// The semantic analysis that is independent of the event source.
1415
pub(super) struct SemanticAnalysisPipeline {
1516
interpreter: Box<dyn semantic::Interpreter>,
16-
transformation: Box<dyn semantic::Transformation>,
17+
transformation: Box<dyn transformation::Transformation>,
1718
output_writer: OutputWriterImpl,
1819
}
1920

rust/bear/src/semantic/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ impl<T> IntoIterator for Recognition<T> {
7979
}
8080
}
8181

82-
/// Responsible to transform the semantic of an executed command.
83-
///
84-
/// It conditionally removes compiler calls based on compiler names or flags.
85-
/// It can also alter the compiler flags of the compiler calls. The actions
86-
/// are defined in the configuration this module is given.
87-
pub trait Transformation: Send {
88-
fn apply(&self, _: CompilerCall) -> anyhow::Result<CompilerCall>;
89-
}
90-
9182
/// Serialize compiler calls into a JSON array.
9283
pub fn serialize(
9384
writer: impl std::io::Write,

rust/bear/src/semantic/transformation.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
99
use crate::{config, semantic};
1010

11+
/// Responsible to transform the semantic of an executed command.
12+
pub trait Transformation: Send {
13+
fn apply(&self, _: semantic::CompilerCall) -> anyhow::Result<semantic::CompilerCall>;
14+
}
15+
1116
/// FilterAndFormat is a transformation that filters and formats the compiler calls.
1217
pub struct FilterAndFormat {
1318
filter: filter::SemanticFilter,
1419
formatter: formatter::PathFormatter,
1520
}
1621

17-
impl semantic::Transformation for FilterAndFormat {
22+
impl Transformation for FilterAndFormat {
1823
fn apply(&self, input: semantic::CompilerCall) -> anyhow::Result<semantic::CompilerCall> {
1924
let candidate = self.filter.apply(input)?;
2025
let formatted = self.formatter.apply(candidate)?;
@@ -67,7 +72,7 @@ mod formatter {
6772
//! file paths. In the current implementation, the `arguments` attribute is not
6873
//! transformed.
6974
70-
use crate::{config, semantic};
75+
use super::*;
7176
use std::env;
7277
use std::path::{Path, PathBuf};
7378

@@ -78,7 +83,7 @@ mod formatter {
7883
SkipFormat,
7984
}
8085

81-
impl semantic::Transformation for PathFormatter {
86+
impl Transformation for PathFormatter {
8287
fn apply(&self, call: semantic::CompilerCall) -> anyhow::Result<semantic::CompilerCall> {
8388
match self {
8489
PathFormatter::SkipFormat => Ok(call),
@@ -169,7 +174,7 @@ mod formatter {
169174
}
170175

171176
mod filter {
172-
use crate::{config, semantic};
177+
use super::*;
173178
use anyhow::anyhow;
174179
use std::collections::HashMap;
175180
use std::path::PathBuf;
@@ -184,7 +189,7 @@ mod filter {
184189
compilers: HashMap<PathBuf, Vec<config::Compiler>>,
185190
}
186191

187-
impl semantic::Transformation for SemanticFilter {
192+
impl Transformation for SemanticFilter {
188193
fn apply(&self, input: semantic::CompilerCall) -> anyhow::Result<semantic::CompilerCall> {
189194
if let Some(configs) = self.compilers.get(&input.compiler) {
190195
Self::apply_when_match_compiler(configs.as_slice(), input)
@@ -310,7 +315,8 @@ mod filter {
310315
mod tests {
311316
use super::*;
312317
use crate::config::{Arguments, Compiler, IgnoreOrConsider};
313-
use crate::semantic::{CompilerCall, CompilerPass, Transformation};
318+
use crate::semantic::transformation::Transformation;
319+
use crate::semantic::{CompilerCall, CompilerPass};
314320
use std::path::PathBuf;
315321

316322
#[test]

0 commit comments

Comments
 (0)