
it.unibo.collektive.compiler.logging.CollectingMessageCollector.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler-embeddable Show documentation
Show all versions of compiler-embeddable Show documentation
DSL for Aggregate Computing in Kotlin
package it.unibo.collektive.compiler.logging
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.EXCEPTION
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
/**
* A message collector collecting messages for later programmatic use.
*/
class CollectingMessageCollector : MessageCollector {
private val timeline: MutableList = mutableListOf()
/**
* All messages collected so far, sorted by generation time.
*/
val messages: List get() = timeline
/**
* All messages collected so far, grouped by severity.
*/
fun allMessages(): Map> = messages.groupBy { it.severity }
/**
* All messages collected so far with the given [severity].
*/
operator fun get(severity: CompilerMessageSeverity): List =
messages.filter { it.severity == severity }
override fun clear() = timeline.clear()
override fun hasErrors(): Boolean = listOf(ERROR, EXCEPTION).let { errors ->
messages.any { it.severity in errors }
}
override fun report(
severity: CompilerMessageSeverity,
message: String,
location: CompilerMessageSourceLocation?,
) {
timeline += CompilerMessage(severity, message, location)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy