2.5 KiB
2.5 KiB
Low-Impact Abstraction: The Enrichment Pipeline
1. Goal
Support enhanced codebase analysis (Endpoints, Listeners, etc.) without a massive refactor of the existing JDT state machine parsers.
2. The Core Model: AnalysisResult
We wrap the existing output into a container that can hold optional metadata.
public class AnalysisResult {
// Current Core Data
private final String name;
private final List<Transition> transitions;
private final Set<String> startStates;
private final Set<String> endStates;
// Optional Enhanced Data
private CodebaseMetadata metadata = CodebaseMetadata.empty();
public AnalysisResult(String name, List<Transition> transitions, Set<String> startStates, Set<String> endStates) {
this.name = name;
this.transitions = transitions;
this.startStates = startStates;
this.endStates = endStates;
}
public void setMetadata(CodebaseMetadata metadata) {
this.metadata = metadata;
}
}
3. The "Enricher" Abstraction
Instead of modifying the parser, we "enrich" the result after it's produced.
public interface AnalysisEnricher {
/**
* Examines the core analysis result and the codebase context
* to add extra metadata (triggers, endpoints, etc.).
*/
void enrich(AnalysisResult result, CodebaseContext context);
}
4. Implementation Tiers
Tier 1: Current State (No-Op)
The ExportService calls enrich(), but since no enrichers are registered, it just returns the core data. This is zero-impact refactoring.
Tier 2: Enhanced Analysis
Once we implement SpringMvcEnricher or RabbitMqEnricher, we register them. They will:
- Scan the
CodebaseContext. - Find
TriggerPoints. - Link them to the
transitionsalready present in theAnalysisResult. - Update the
metadatafield.
5. Why this is "Good":
- Non-Breaking:
StateMachineAggregatorremains untouched. - Pluggable: You can add/remove "Intelligence" without changing the core parser.
- Future-Proof: If you switch from JDT to another tool for code analysis, you only change the
Enricherimplementation.
6. Refactoring Steps
- Create
AnalysisResultandCodebaseMetadataclasses. - Update
ExportService.generateOutputsto take anAnalysisResultobject instead of 4 separate parameters. - Introduce
EnrichmentServicethat holds a list ofAnalysisEnrichers. - Modify
ExportServiceto callenrichmentService.enrich(result, context)before passing the result to exporters.