From 072edf4b5a489bc4072c80aa39135cf98e4540e8 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 13 Jan 2017 08:24:23 +0300 Subject: [PATCH] Minor: introduce EXCEPTION report category --- .../common/CompilerServicesFacadeBase.kt | 16 ++------ .../CompileServicesFacadeMessageCollector.kt | 37 ++++++++++--------- .../JpsCompilerServicesFacadeImpl.kt | 17 ++++++--- .../compilerRunner/JpsKotlinCompilerRunner.kt | 11 ++++-- ...leIncrementalCompilerServicesFacadeImpl.kt | 20 +++++++--- 5 files changed, 59 insertions(+), 42 deletions(-) diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt index 701ef68cbed..4d35ded7b1d 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt @@ -32,9 +32,10 @@ interface CompilerServicesFacadeBase : Remote { enum class ReportCategory(val code: Int) { COMPILER_MESSAGE(0), - DAEMON_MESSAGE(1), - IC_MESSAGE(2), - OUTPUT_MESSAGE(3); + EXCEPTION(1), + DAEMON_MESSAGE(2), + IC_MESSAGE(3), + OUTPUT_MESSAGE(4); companion object { fun fromCode(code: Int): ReportCategory? = @@ -58,12 +59,3 @@ enum class ReportSeverity(val code: Int) { fun CompilerServicesFacadeBase.report(category: ReportCategory, severity: ReportSeverity, message: String? = null, attachment: Serializable? = null) { report(category.code, severity.code, message, attachment) } - -data class CompilerMessageAttachment( - val severity: CompilerMessageSeverity, - val location: CompilerMessageLocation -) : Serializable { - companion object { - const val serialVersionUID = 0L - } -} diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt index 986908cef5a..fc9444ea57c 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt @@ -33,25 +33,28 @@ internal class CompileServicesFacadeMessageCollector( } override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { - val reportCategory = when (severity) { - CompilerMessageSeverity.OUTPUT -> ReportCategory.OUTPUT_MESSAGE - else -> ReportCategory.COMPILER_MESSAGE + when (severity) { + CompilerMessageSeverity.OUTPUT -> { + servicesFacade.report(ReportCategory.OUTPUT_MESSAGE, ReportSeverity.ERROR, message) + } + CompilerMessageSeverity.EXCEPTION -> { + servicesFacade.report(ReportCategory.EXCEPTION, ReportSeverity.ERROR, message) + } + else -> { + val reportSeverity = when (severity) { + CompilerMessageSeverity.ERROR -> ReportSeverity.ERROR + CompilerMessageSeverity.WARNING -> ReportSeverity.WARNING + CompilerMessageSeverity.INFO -> ReportSeverity.INFO + else -> ReportSeverity.DEBUG + } + + if (reportSeverity.code <= mySeverity) { + servicesFacade.report(ReportCategory.COMPILER_MESSAGE, reportSeverity, message, location) + } + } } - val reportSeverity = when (severity) { - CompilerMessageSeverity.ERROR, - CompilerMessageSeverity.EXCEPTION -> ReportSeverity.ERROR - CompilerMessageSeverity.WARNING -> ReportSeverity.WARNING - CompilerMessageSeverity.INFO -> ReportSeverity.INFO - CompilerMessageSeverity.LOGGING -> ReportSeverity.DEBUG - CompilerMessageSeverity.OUTPUT -> ReportSeverity.ERROR - } - - if (reportSeverity.code <= mySeverity) { - servicesFacade.report(reportCategory, reportSeverity, message, CompilerMessageAttachment(severity, location)) - } - - hasErrors = hasErrors || severity == CompilerMessageSeverity.ERROR + hasErrors = hasErrors || severity == CompilerMessageSeverity.ERROR || severity == CompilerMessageSeverity.EXCEPTION } override fun hasErrors(): Boolean = hasErrors diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt index b4df5aa4089..f3610bbfed9 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt @@ -39,12 +39,19 @@ internal class JpsCompilerServicesFacadeImpl( ReportCategory.OUTPUT_MESSAGE -> { env.messageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION) } + ReportCategory.EXCEPTION -> { + env.messageCollector.report(CompilerMessageSeverity.EXCEPTION, message!!, CompilerMessageLocation.NO_LOCATION) + } ReportCategory.COMPILER_MESSAGE -> { - val compilerMessageAttachment = attachment as? CompilerMessageAttachment - if (message != null && compilerMessageAttachment != null) { - val originalSeverity = compilerMessageAttachment.severity - val originalLocation = compilerMessageAttachment.location - env.messageCollector.report(originalSeverity, message, originalLocation) + val compilerSeverity = when (ReportSeverity.fromCode(severity)) { + ReportSeverity.ERROR -> CompilerMessageSeverity.ERROR + ReportSeverity.WARNING -> CompilerMessageSeverity.WARNING + ReportSeverity.INFO -> CompilerMessageSeverity.INFO + ReportSeverity.DEBUG -> CompilerMessageSeverity.LOGGING + else -> throw IllegalStateException("Unexpected compiler message report severity $severity") + } + if (message != null && attachment is CompilerMessageLocation) { + env.messageCollector.report(compilerSeverity, message, attachment) } else { reportUnexpected(category, severity, message, attachment) diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 75c670d28e4..e4f20cfb84d 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -110,14 +110,19 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { return res?.get()?.let { exitCodeFromProcessExitCode(it) } } - private fun reportCategories(verbose: Boolean): Array = + private fun reportCategories(verbose: Boolean): Array { + val categories = if (!verbose) { - arrayOf(ReportCategory.COMPILER_MESSAGE.code) + arrayOf(ReportCategory.COMPILER_MESSAGE, ReportCategory.EXCEPTION) } else { - ReportCategory.values().map { it.code }.toTypedArray() + ReportCategory.values() } + return categories.map { it.code }.toTypedArray() + } + + private fun reportSeverity(verbose: Boolean): Int = if (!verbose) { ReportSeverity.INFO.code diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt index 03e36300205..c7263870683 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt @@ -29,9 +29,22 @@ internal open class GradleCompilerServicesFacadeImpl( val reportCategory = ReportCategory.fromCode(category) when (reportCategory) { + ReportCategory.OUTPUT_MESSAGE -> { + compilerMessageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION) + } + ReportCategory.EXCEPTION -> { + compilerMessageCollector.report(CompilerMessageSeverity.EXCEPTION, message!!, CompilerMessageLocation.NO_LOCATION) + } ReportCategory.COMPILER_MESSAGE -> { - if (message != null && attachment is CompilerMessageAttachment) { - compilerMessageCollector.report(attachment.severity, message, attachment.location) + val compilerSeverity = when (ReportSeverity.fromCode(severity)) { + ReportSeverity.ERROR -> CompilerMessageSeverity.ERROR + ReportSeverity.WARNING -> CompilerMessageSeverity.WARNING + ReportSeverity.INFO -> CompilerMessageSeverity.INFO + ReportSeverity.DEBUG -> CompilerMessageSeverity.LOGGING + else -> throw IllegalStateException("Unexpected compiler message report severity $severity") + } + if (message != null && attachment is CompilerMessageLocation) { + compilerMessageCollector.report(compilerSeverity, message, attachment) } else { reportUnexpectedMessage(category, severity, message, attachment) @@ -43,9 +56,6 @@ internal open class GradleCompilerServicesFacadeImpl( ReportCategory.DAEMON_MESSAGE -> { log.kotlinDebug { "[DAEMON] $message" } } - ReportCategory.OUTPUT_MESSAGE -> { - compilerMessageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION) - } else -> { reportUnexpectedMessage(category, severity, message, attachment) }