Use null instead of CompilerMessageLocation.NO_LOCATION in MessageCollector

This commit is contained in:
Alexander Udalov
2017-03-31 17:39:03 +03:00
parent 411a8dc206
commit 861d9a1620
46 changed files with 279 additions and 390 deletions
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
import org.jetbrains.kotlin.daemon.common.*
import java.io.Serializable
import java.io.File
import java.io.Serializable
import java.rmi.server.UnicastRemoteObject
@@ -51,11 +51,11 @@ fun MessageCollector.reportFromDaemon(outputsCollector: ((File, List<File>) -> U
}
}
else {
report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION)
report(CompilerMessageSeverity.OUTPUT, message!!)
}
}
ReportCategory.EXCEPTION -> {
report(CompilerMessageSeverity.EXCEPTION, message.orEmpty(), CompilerMessageLocation.NO_LOCATION)
report(CompilerMessageSeverity.EXCEPTION, message.orEmpty())
}
ReportCategory.COMPILER_MESSAGE -> {
val compilerSeverity = when (ReportSeverity.fromCode(severity)) {
@@ -65,7 +65,7 @@ fun MessageCollector.reportFromDaemon(outputsCollector: ((File, List<File>) -> U
ReportSeverity.DEBUG -> CompilerMessageSeverity.LOGGING
else -> throw IllegalStateException("Unexpected compiler message report severity $severity")
}
if (message != null && attachment is CompilerMessageLocation) {
if (message != null && attachment is CompilerMessageLocation?) {
report(compilerSeverity, message, attachment)
}
else {
@@ -75,7 +75,7 @@ fun MessageCollector.reportFromDaemon(outputsCollector: ((File, List<File>) -> U
ReportCategory.DAEMON_MESSAGE,
ReportCategory.IC_MESSAGE -> {
if (message != null) {
report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION)
report(CompilerMessageSeverity.LOGGING, message)
}
else {
reportUnexpected(category, severity, message, attachment)
@@ -95,8 +95,5 @@ private fun MessageCollector.reportUnexpected(category: Int, severity: Int, mess
else -> CompilerMessageSeverity.LOGGING
}
report(compilerMessageSeverity,
"Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment",
CompilerMessageLocation.NO_LOCATION)
report(compilerMessageSeverity, "Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment")
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.daemon.client
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.daemon.common.*
@@ -33,7 +32,6 @@ import java.rmi.UnmarshalException
import java.rmi.server.UnicastRemoteObject
import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit
import kotlin.comparisons.compareByDescending
import kotlin.concurrent.thread
class CompilationServices(
@@ -343,17 +341,17 @@ object KotlinCompilerClient {
messages?.add(DaemonReportMessage(category, "[$source] $message"))
messageCollector?.let {
when (category) {
DaemonReportCategory.DEBUG -> it.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION)
DaemonReportCategory.INFO -> it.report(CompilerMessageSeverity.INFO, message, CompilerMessageLocation.NO_LOCATION)
DaemonReportCategory.EXCEPTION -> it.report(CompilerMessageSeverity.EXCEPTION, message, CompilerMessageLocation.NO_LOCATION)
DaemonReportCategory.DEBUG -> it.report(CompilerMessageSeverity.LOGGING, message)
DaemonReportCategory.INFO -> it.report(CompilerMessageSeverity.INFO, message)
DaemonReportCategory.EXCEPTION -> it.report(CompilerMessageSeverity.EXCEPTION, message)
}
}
compilerServices?.let {
when (category) {
DaemonReportCategory.DEBUG -> it.report(ReportCategory.DAEMON_MESSAGE, ReportSeverity.DEBUG, message, source)
DaemonReportCategory.INFO -> it.report(ReportCategory.DAEMON_MESSAGE, ReportSeverity.INFO, message, source)
DaemonReportCategory.EXCEPTION -> it.report(ReportCategory.EXCEPTION, ReportSeverity.ERROR, message, source)
}
when (category) {
DaemonReportCategory.DEBUG -> it.report(ReportCategory.DAEMON_MESSAGE, ReportSeverity.DEBUG, message, source)
DaemonReportCategory.INFO -> it.report(ReportCategory.DAEMON_MESSAGE, ReportSeverity.INFO, message, source)
DaemonReportCategory.EXCEPTION -> it.report(ReportCategory.EXCEPTION, ReportSeverity.ERROR, message, source)
}
}
}
@@ -27,9 +27,15 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser
import org.jetbrains.kotlin.cli.common.repl.*
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
@@ -337,7 +343,7 @@ class CompileServiceImpl(
}
}
catch (e: IllegalArgumentException) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, e.stackTraceStr, CompilerMessageLocation.NO_LOCATION)
messageCollector.report(CompilerMessageSeverity.EXCEPTION, e.stackTraceStr)
return@ifAlive CompileService.CallResult.Error("Could not deserialize compiler arguments")
}
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.daemon
import com.intellij.openapi.Disposable
import org.jetbrains.kotlin.cli.common.messages.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
import org.jetbrains.kotlin.cli.common.repl.*
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
import org.jetbrains.kotlin.cli.jvm.repl.GenericReplCompiler
@@ -63,22 +65,15 @@ open class KotlinJvmReplService(
try {
val cls = classloader.loadClass(templateClassName)
val def = KotlinScriptDefinitionFromAnnotatedTemplate(cls.kotlin, null, null, emptyMap())
messageCollector.report(
CompilerMessageSeverity.INFO,
"New script definition $templateClassName: files pattern = \"${def.scriptFilePattern}\", resolver = ${def.resolver?.javaClass?.name}",
CompilerMessageLocation.NO_LOCATION
)
messageCollector.report(INFO, "New script definition $templateClassName: files pattern = \"${def.scriptFilePattern}\", " +
"resolver = ${def.resolver?.javaClass?.name}")
return def
}
catch (ex: ClassNotFoundException) {
messageCollector.report(
CompilerMessageSeverity.ERROR, "Cannot find script definition template class $templateClassName", CompilerMessageLocation.NO_LOCATION
)
messageCollector.report(ERROR, "Cannot find script definition template class $templateClassName")
}
catch (ex: Exception) {
messageCollector.report(
CompilerMessageSeverity.ERROR, "Error processing script definition template $templateClassName: ${ex.message}", CompilerMessageLocation.NO_LOCATION
)
messageCollector.report(ERROR, "Error processing script definition template $templateClassName: ${ex.message}")
}
return null
}
@@ -150,7 +145,7 @@ internal class KeepFirstErrorMessageCollector(compilerMessagesStream: PrintStrea
internal var firstErrorMessage: String? = null
internal var firstErrorLocation: CompilerMessageLocation? = null
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
if (firstErrorMessage == null && severity.isError) {
firstErrorMessage = message
firstErrorLocation = location
@@ -34,8 +34,8 @@ internal class CompileServicesFacadeMessageCollector(
hasErrors = false
}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
log.info("Message: " + MessageRenderer.WITHOUT_PATHS.render(severity, message, location))
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
log.info("Message: " + MessageRenderer.WITHOUT_PATHS.render(severity, message, location ?: CompilerMessageLocation.NO_LOCATION))
when (severity) {
CompilerMessageSeverity.OUTPUT -> {
servicesFacade.report(ReportCategory.OUTPUT_MESSAGE, ReportSeverity.ERROR, message)