From 46515afb22908f042869b5db99b46c488429f3af Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sat, 13 Jun 2015 03:03:16 +0300 Subject: [PATCH] CLI: don't render non-positive line and column in error messages --- .../cli/common/messages/MessageRenderer.java | 18 ++++++++++++++++-- .../messages/AnalyzerWithCompilerReport.java | 2 +- compiler/testData/cli/jvm/wrongAbiVersion.out | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/MessageRenderer.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/MessageRenderer.java index 552ab612e08..e1822fa1de1 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/MessageRenderer.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/MessageRenderer.java @@ -87,9 +87,23 @@ public interface MessageRenderer { public String render( @NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location ) { + StringBuilder result = new StringBuilder(); + result.append(severity).append(": "); + String path = getPath(location); - String position = path == null ? "" : path + ": (" + (location.getLine() + ", " + location.getColumn()) + ") "; - return severity + ": " + position + message; + if (path != null) { + result.append(path); + result.append(": "); + if (location.getLine() > 0 && location.getColumn() > 0) { + result.append("("); + result.append(location.getLine()).append(", ").append(location.getColumn()); + result.append(") "); + } + } + + result.append(message); + + return result.toString(); } @Nullable diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java index 50d1f343041..8a70c251c72 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/AnalyzerWithCompilerReport.java @@ -141,7 +141,7 @@ public final class AnalyzerWithCompilerReport { CompilerMessageSeverity.ERROR, "Class '" + JvmClassName.byClassId(data.getClassId()) + "' was compiled with an incompatible version of Kotlin. " + "Its ABI version is " + data.getActualVersion() + ", expected ABI version is " + JvmAbi.VERSION, - CompilerMessageLocation.create(path, 0, 0) + CompilerMessageLocation.create(path, -1, -1) ); } } diff --git a/compiler/testData/cli/jvm/wrongAbiVersion.out b/compiler/testData/cli/jvm/wrongAbiVersion.out index a35912a6b2b..0a03b81cd66 100644 --- a/compiler/testData/cli/jvm/wrongAbiVersion.out +++ b/compiler/testData/cli/jvm/wrongAbiVersion.out @@ -1,4 +1,4 @@ -ERROR: compiler/testData/cli/jvm/wrongAbiVersionLib/bin/ClassWithWrongAbiVersion.class: (0, 0) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is $ABI_VERSION$ -ERROR: compiler/testData/cli/jvm/wrongAbiVersionLib/bin/wrong/WrongPackage.class: (0, 0) Class 'wrong/WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is $ABI_VERSION$ +ERROR: compiler/testData/cli/jvm/wrongAbiVersionLib/bin/ClassWithWrongAbiVersion.class: Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is $ABI_VERSION$ +ERROR: compiler/testData/cli/jvm/wrongAbiVersionLib/bin/wrong/WrongPackage.class: Class 'wrong/WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is $ABI_VERSION$ ERROR: compiler/testData/cli/jvm/wrongAbiVersion.kt: (4, 3) Unresolved reference: bar COMPILATION_ERROR \ No newline at end of file