Use null instead of CompilerMessageLocation.NO_LOCATION in MessageCollector

Original commit: 861d9a1620
This commit is contained in:
Alexander Udalov
2017-03-31 17:39:03 +03:00
parent 55c4221d9f
commit a56ccdc951
4 changed files with 20 additions and 43 deletions
@@ -30,7 +30,6 @@ import java.lang.ref.SoftReference;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collections; import java.util.Collections;
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR; import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR;
public class CompilerRunnerUtil { public class CompilerRunnerUtil {
@@ -63,7 +62,7 @@ public class CompilerRunnerUtil {
messageCollector.report( messageCollector.report(
ERROR, ERROR,
"Broken compiler at '" + libs.getAbsolutePath() + "'. Make sure plugin is properly installed", "Broken compiler at '" + libs.getAbsolutePath() + "'. Make sure plugin is properly installed",
NO_LOCATION null
); );
return null; return null;
@@ -16,8 +16,7 @@
package org.jetbrains.kotlin.compilerRunner package org.jetbrains.kotlin.compilerRunner
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.preloading.ClassCondition import org.jetbrains.kotlin.preloading.ClassCondition
@@ -37,8 +36,8 @@ class JpsCompilerEnvironment(
fun reportErrorsTo(messageCollector: MessageCollector) { fun reportErrorsTo(messageCollector: MessageCollector) {
if (!kotlinPaths.homePath.exists()) { if (!kotlinPaths.homePath.exists()) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Cannot find kotlinc home: " + kotlinPaths.homePath + ". Make sure plugin is properly installed, " + messageCollector.report(ERROR, "Cannot find kotlinc home: " + kotlinPaths.homePath + ". Make sure plugin is properly installed, " +
"or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property", CompilerMessageLocation.NO_LOCATION) "or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property")
} }
} }
} }
@@ -21,7 +21,6 @@ import org.jetbrains.jps.api.GlobalOptions
import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.config.additionalArgumentsAsList import org.jetbrains.kotlin.config.additionalArgumentsAsList
@@ -105,7 +104,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
compilerArgs: CommonCompilerArguments, compilerArgs: CommonCompilerArguments,
environment: JpsCompilerEnvironment environment: JpsCompilerEnvironment
): ExitCode { ): ExitCode {
environment.messageCollector.report(CompilerMessageSeverity.INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath, CompilerMessageLocation.NO_LOCATION) environment.messageCollector.report(CompilerMessageSeverity.INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath)
return if (isDaemonEnabled()) { return if (isDaemonEnabled()) {
val daemonExitCode = compileWithDaemon(compilerClassName, compilerArgs, environment) val daemonExitCode = compileWithDaemon(compilerClassName, compilerArgs, environment)
@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollector import org.jetbrains.kotlin.compilerRunner.OutputItemsCollector
@@ -194,12 +194,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
} }
catch (e: Throwable) { catch (e: Throwable) {
LOG.info("Caught exception: " + e) LOG.info("Caught exception: " + e)
MessageCollectorUtil.reportException(messageCollector, e)
messageCollector.report(
CompilerMessageSeverity.EXCEPTION,
OutputMessageUtil.renderException(e),
CompilerMessageLocation.NO_LOCATION
)
return ABORT return ABORT
} }
} }
@@ -214,7 +209,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
): ModuleLevelBuilder.ExitCode { ): ModuleLevelBuilder.ExitCode {
// Workaround for Android Studio // Workaround for Android Studio
if (!JavaBuilder.IS_ENABLED[context, true] && !JpsUtils.isJsKotlinModule(chunk.representativeTarget())) { if (!JavaBuilder.IS_ENABLED[context, true] && !JpsUtils.isJsKotlinModule(chunk.representativeTarget())) {
messageCollector.report(INFO, "Kotlin JPS plugin is disabled", CompilerMessageLocation.NO_LOCATION) messageCollector.report(INFO, "Kotlin JPS plugin is disabled")
return NOTHING_DONE return NOTHING_DONE
} }
@@ -235,11 +230,11 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
return NOTHING_DONE return NOTHING_DONE
} }
messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinCompilerVersion.VERSION, CompilerMessageLocation.NO_LOCATION) messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinCompilerVersion.VERSION)
val targetsWithoutOutputDir = targets.filter { it.outputDir == null } val targetsWithoutOutputDir = targets.filter { it.outputDir == null }
if (targetsWithoutOutputDir.isNotEmpty()) { if (targetsWithoutOutputDir.isNotEmpty()) {
messageCollector.report(ERROR, "Output directory not specified for " + targetsWithoutOutputDir.joinToString(), CompilerMessageLocation.NO_LOCATION) messageCollector.report(ERROR, "Output directory not specified for " + targetsWithoutOutputDir.joinToString())
return ABORT return ABORT
} }
@@ -448,11 +443,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
commonArguments.pluginClasspaths = concatenate(commonArguments.pluginClasspaths, commonArguments.pluginClasspaths = concatenate(commonArguments.pluginClasspaths,
argumentProvider.getClasspath(representativeTarget, context)) argumentProvider.getClasspath(representativeTarget, context))
messageCollector.report( messageCollector.report(INFO, "Plugin loaded: ${argumentProvider::class.java.simpleName}")
INFO,
"Plugin loaded: ${argumentProvider::class.java.simpleName}",
CompilerMessageLocation.NO_LOCATION
)
} }
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile) return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile)
@@ -651,8 +642,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
STRONG_WARNING, STRONG_WARNING,
"Circular dependencies are not supported. The following JS modules depend on each other: " "Circular dependencies are not supported. The following JS modules depend on each other: "
+ chunk.modules.map { it.name }.joinToString(", ") + ". " + chunk.modules.map { it.name }.joinToString(", ") + ". "
+ "Kotlin is not compiled for these modules", + "Kotlin is not compiled for these modules"
CompilerMessageLocation.NO_LOCATION
) )
return null return null
} }
@@ -702,8 +692,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
STRONG_WARNING, STRONG_WARNING,
"Circular dependencies are only partially supported. The following modules depend on each other: " "Circular dependencies are only partially supported. The following modules depend on each other: "
+ chunk.modules.map { it.name }.joinToString(", ") + ". " + chunk.modules.map { it.name }.joinToString(", ") + ". "
+ "Kotlin will compile them, but some strange effect may happen", + "Kotlin will compile them, but some strange effect may happen"
CompilerMessageLocation.NO_LOCATION
) )
} }
@@ -746,7 +735,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
class MessageCollectorAdapter(private val context: CompileContext) : MessageCollector { class MessageCollectorAdapter(private val context: CompileContext) : MessageCollector {
private var hasErrors = false private var hasErrors = false
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
hasErrors = hasErrors or severity.isError hasErrors = hasErrors or severity.isError
var prefix = "" var prefix = ""
if (severity == EXCEPTION) { if (severity == EXCEPTION) {
@@ -755,10 +744,11 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
context.processMessage(CompilerMessage( context.processMessage(CompilerMessage(
CompilerRunnerConstants.KOTLIN_COMPILER_NAME, CompilerRunnerConstants.KOTLIN_COMPILER_NAME,
kind(severity), kind(severity),
prefix + message + renderLocationIfNeeded(location), prefix + message,
location.path, location?.path,
-1, -1, -1, -1, -1, -1,
location.line.toLong(), location.column.toLong() location?.line?.toLong() ?: -1,
location?.column?.toLong() ?: -1
)) ))
} }
@@ -768,16 +758,6 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
override fun hasErrors(): Boolean = hasErrors override fun hasErrors(): Boolean = hasErrors
private fun renderLocationIfNeeded(location: CompilerMessageLocation): String {
if (location == CompilerMessageLocation.NO_LOCATION) return ""
// Sometimes we report errors in JavaScript library stubs, i.e. files like core/javautil.kt
// IDEA can't find these files, and does not display paths in Messages View, so we add the position information
// to the error message itself:
val pathname = "" + location.path
return if (File(pathname).exists()) "" else " ($location)"
}
private fun kind(severity: CompilerMessageSeverity): BuildMessage.Kind { private fun kind(severity: CompilerMessageSeverity): BuildMessage.Kind {
return when (severity) { return when (severity) {
INFO -> BuildMessage.Kind.INFO INFO -> BuildMessage.Kind.INFO