From 475bdfffdb46704e2c37513fe77285162a6fd94f Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 17 Feb 2017 10:09:26 -0800 Subject: [PATCH] Better compilation error reporting. --- .../beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 3e7c6239..cb38210b 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -181,19 +181,26 @@ class KotlinCompiler @Inject constructor( throw UnsupportedOperationException("not implemented") } - fun CompilerMessageLocation.dump(s: String) = "$lineContent\n$path:$line:$column $s" + fun dump(location: CompilerMessageLocation?, s: String) = + if (location != null && location.lineContent != null) { + with(location) { + "$lineContent\n$path:$line:$column $s" + } + } else { + s + } override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) { if (severity.isError) { - "Couldn't compile file: ${location.dump(message)}".let { fullMessage -> + "Couldn't compile file: ${dump(location, message)}".let { fullMessage -> System.err.println(fullMessage) throw KobaltException(fullMessage) } } else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) { - warn(location.dump(message)) + warn(dump(location, message)) } else if (severity == CompilerMessageSeverity.INFO && KobaltLogger.LOG_LEVEL >= 2) { - logk(2, location.dump(message)) + logk(2, dump(location, message)) } } }