in compiler/src/main/kotlin/motif/compiler/MotifProcessingStep.kt [43:108]
override fun process(
env: XProcessingEnv,
elementsByAnnotation: Map<String, Set<XElement>>,
isLastRound: Boolean,
): Set<XElement> {
messageWatcher?.let { env.messager.addMessageWatcher(messageWatcher) }
val scopeElements =
elementsByAnnotation[Scope::class.qualifiedName]
?.filterIsInstance<XTypeElement>()
?.mapNotNull { it }
?.toList()
.orEmpty()
val initialScopeClasses = scopeElements.map { CompilerClass(env, it.type) }
if (initialScopeClasses.isEmpty()) {
return emptySet()
} else {
initialScopeNames += initialScopeClasses.map { it.qualifiedName }
}
val graph = ResolvedGraph.create(initialScopeClasses)
graphSetter(graph)
val graphErrors = graph.errors
val filteredGraphErrors =
graphErrors.filterNot {
when (it) {
is AlreadySatisfiedError ->
(it.existingSources.firstOrNull()?.type?.type as? CompilerType)?.mirror?.isError()
?: false
is DependencyCycleError ->
it.path.any { (it.type.type as? CompilerType)?.mirror?.isError() ?: false }
else -> false
}
}
if (filteredGraphErrors.isNotEmpty()) {
val errorMessage = ErrorMessage.toString(filteredGraphErrors)
env.messager.printMessage(Diagnostic.Kind.ERROR, errorMessage)
return emptySet()
}
val mode: OutputMode? =
try {
OutputMode.valueOf(env.options[OPTION_MODE]?.uppercase() ?: "")
} catch (ignore: IllegalArgumentException) {
if (env.backend == XProcessingEnv.Backend.KSP) OutputMode.KOTLIN else null
}
createdScopeNames += CodeGenerator.generate(env, graph, mode)
if (createdScopeNames.size < initialScopeNames.size) {
val missingScopeNames = HashSet(initialScopeNames).apply { removeAll(createdScopeNames) }
env.messager.printMessage(
Diagnostic.Kind.ERROR,
"""
Not all scopes were generated.
Expected: ${initialScopeNames.sorted().joinToString(", ")}
Created: ${createdScopeNames.sorted().joinToString(", ")}
Missing: ${missingScopeNames.sorted().joinToString(", ")}
"""
.trimIndent(),
)
return emptySet()
}
return emptySet()
}