Class MagicLiteralTracker
java.lang.Object
org.ek9lang.compiler.phase5.MagicLiteralTracker
Tracks literal occurrences across files for repeated magic literal detection (E11065).
A repeated magic literal is the same value appearing 3+ times in a single file
or 4+ times across files in the same module. Only String literals are tracked —
numeric literals in test/production code are domain data, not duplication bugs.
This matches SonarQube S1192 and PMD AvoidDuplicateLiterals (strings only).
Thread-safe: designed to be used during parallel file processing where multiple PreIRListener instances (one per file) share a single MagicLiteralTracker.
Context exemptions: literals in constant declarations, list/dict literals, require/assert statements, constrain declarations, range expressions, named arguments (the parameter name documents the value), and constructor calls (type construction is data, not logic).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordOne recorded occurrence of a literal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) List<MagicLiteralTracker.LiteralRecord> getRecords(String moduleName) Get a snapshot copy of literal records for a specific module.(package private) static booleanCheck if a module is exempt from magic literal checking.(package private) voidprocessLiteral(EK9Parser.LiteralContext literal, String moduleName, String filePath, Set<org.antlr.v4.runtime.Token> reportedByTier1) Record a literal occurrence for a specific module, if not exempt.
-
Constructor Details
-
MagicLiteralTracker
MagicLiteralTracker()
-
-
Method Details
-
processLiteral
void processLiteral(EK9Parser.LiteralContext literal, String moduleName, String filePath, Set<org.antlr.v4.runtime.Token> reportedByTier1) Record a literal occurrence for a specific module, if not exempt.- Parameters:
literal- the literal parser contextmoduleName- the module containing the literalfilePath- the source file pathreportedByTier1- tokens already reported by Tier 1 (to avoid double-reporting)
-
getRecords
Get a snapshot copy of literal records for a specific module.- Parameters:
moduleName- the module to query- Returns:
- list of literal records (may be empty, never null)
-
isExempt
Check if a module is exempt from magic literal checking. Built-in modules (org.ek9.*) are exempt.
-