Class TraitImplementationAnalyzer
java.lang.Object
org.ek9lang.compiler.phase5.TraitImplementationAnalyzer
Analyzes how traits are implemented in an aggregate to detect E11023 pattern
(missing 'by' delegation).
The E11023 anti-pattern occurs when:
- A class implements a trait WITHOUT using 'by' delegation
- The class has a field of the trait type (or compatible type)
- The developer manually implements all trait methods by forwarding to that field
This is boilerplate that could be eliminated by using 'by' delegation:
// Anti-pattern (manual forwarding): class Foo with trait of Bar barImpl as Bar? override method1() -> barImpl.method1() override method2() -> barImpl.method2() ... // Better (use 'by' delegation): class Foo with trait of Bar by barImpl barImpl as Bar? // Methods automatically delegated!
Detection approach:
- Find traits implemented WITHOUT 'by'
- Check if the class has a field assignable to that trait
- Count how many trait methods are overridden in this class
- If all/most trait methods are overridden and there's a compatible field = likely forwarding
Note: We cannot detect actual forwarding without IR analysis. This is a heuristic that identifies LIKELY forwarding patterns.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordResult of analyzing trait implementation for potential missing 'by' delegation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) List<TraitImplementationAnalyzer.TraitAnalysis> analyzeTraitsWithoutDelegation(IAggregateSymbol aggregate, EK9Parser.TraitsListContext traitsListContext) Analyze traits implemented WITHOUT 'by' delegation to detect potential E11023 patterns.
-
Constructor Details
-
TraitImplementationAnalyzer
TraitImplementationAnalyzer()
-
-
Method Details
-
analyzeTraitsWithoutDelegation
List<TraitImplementationAnalyzer.TraitAnalysis> analyzeTraitsWithoutDelegation(IAggregateSymbol aggregate, EK9Parser.TraitsListContext traitsListContext) Analyze traits implemented WITHOUT 'by' delegation to detect potential E11023 patterns.- Parameters:
aggregate- The aggregate to analyzetraitsListContext- Parse tree context for trait declarations- Returns:
- List of analysis results for each trait implemented without 'by'
-