All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.mokkery.plugin.MessageCollectorUtils.kt Maven / Gradle / Ivy

Go to download

Mokkery is a mocking library for Kotlin Multiplatform, easy to use, boilerplate-free and compiler plugin driven.

The newest version!
package dev.mokkery.plugin

import dev.mokkery.MokkeryConfig
import dev.mokkery.plugin.ir.locationInFile
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.messageCollector
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.expressions.IrExpression

@Suppress("DEPRECATION")
val CompilerConfiguration.messageCollectorCompat: MessageCollector get() = try {
    messageCollector
} catch (e: NoSuchMethodError) {
    get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
}

internal inline fun MessageCollector.log(message: () -> String) {
    report(CompilerMessageSeverity.LOGGING, "${MokkeryConfig.PLUGIN_ID}: ${message()}")
}


internal inline fun MessageCollector.logAt(expression: IrExpression, file: IrFile, message: () -> String) {
    report(
        severity = CompilerMessageSeverity.LOGGING,
        message = "${MokkeryConfig.PLUGIN_ID}: ${message()} Expression at: ${expression.locationInFile(file)}"
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy