PsiMaterializer
Materializes MetamodelEntity instances from Kotlin source PSI.
The materializer walks Kotlin source files, finds top-level and class-member val/var declarations whose initializer constructs a metamodel entity, and produces real MetamodelEntity instances using kClass.primaryConstructor!!.callBy(args). Instances are registered into the ModelScope active on the calling thread — the rule engine in :stig-core then consumes them unchanged.
Current state (slice C)
Type filter: only constructors of types in
com.stigway.metamodels.highway.*are accepted (slice F broadens this to user subclasses via supertype walking).Argument resolution: literals (string / int / float / boolean), enum references (
ASIL.B), entity references (element = camera), and list-of-entity references (propagatesTo = listOf(a, b)). List references are back-patched after the first construction pass so cycles can resolve.Identity: every materialized entity gets bindToSource called with the Kotlin
valname and the declaring file-facade / containing-class FQN.
Roadmap
Slice D — single-entity reference resolution (
element = cameraresolves to the materializedcameraentity).Slice E — list-of-refs + back-patching for cycle handling.
Slice F — user-defined subclasses (
class CameraAnalysis : Analysis(...)), Q2 hybrid: instantiate the subclass directly, then sweep its body for member entities.Slice G —
SafetyRuleInspectionwires the materializer toProblemsHolderfor red squiggles.
Types
Returned by materializeFileWithSourceMap. Pair of (entities, source-map).
Functions
Finds constructor/factory candidates and other model-valued declarations. Unsupported model expressions are retained for completeness diagnostics.
Walk file, materialize every metamodel-entity declaration we can construct, and return the resulting list. Side effect: each constructed entity is also registered in ModelScope.current (via MetamodelEntity's init block).
All requested context phases share one identity cache; the planner controls any scope expansion.
Same as materializeFile but also returns the source map linking each materialized entity back to the KtProperty it came from. The inspection in :stig-idea-plugin uses this to translate a Finding (which carries an entity id) back to the source PSI element it should highlight.