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 val name and the declaring file-facade / containing-class FQN.

Roadmap

  • Slice D — single-entity reference resolution (element = camera resolves to the materialized camera entity).

  • 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 — SafetyRuleInspection wires the materializer to ProblemsHolder for red squiggles.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class MaterializationResult(val entities: List<MetamodelEntity>, val sourceMap: Map<MetamodelEntity, KtNamedDeclaration>, val unresolvedDeclarations: Set<KtNamedDeclaration> = emptySet(), val unresolvedDetails: Map<KtNamedDeclaration, List<String>> = emptyMap())

Returned by materializeFileWithSourceMap. Pair of (entities, source-map).

Functions

Link copied to clipboard
fun findCandidateProperties(file: KtFile): List<KtProperty>

Finds constructor/factory candidates and other model-valued declarations. Unsupported model expressions are retained for completeness diagnostics.

Link copied to clipboard

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).

Link copied to clipboard

All requested context phases share one identity cache; the planner controls any scope expansion.

Link copied to clipboard

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.