CLI: output relative paths in diagnostic messages

This commit is contained in:
Alexander Udalov
2014-07-23 16:38:29 +04:00
parent 807cf1dcc0
commit 5a792ca11f
10 changed files with 67 additions and 43 deletions
@@ -17,10 +17,11 @@
package org.jetbrains.jet.cli.common.messages;
import com.intellij.openapi.util.text.StringUtil;
import kotlin.io.IoPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.File;
public interface MessageRenderer {
@@ -57,24 +58,48 @@ public interface MessageRenderer {
}
};
MessageRenderer PLAIN = new MessageRenderer() {
MessageRenderer PLAIN = new PlainText() {
@Nullable
@Override
protected String getPath(@NotNull CompilerMessageLocation location) {
return location.getPath();
}
};
MessageRenderer PLAIN_WITH_RELATIVE_PATH = new PlainText() {
private final File cwd = new File(".").getAbsoluteFile();
@Nullable
@Override
protected String getPath(@NotNull CompilerMessageLocation location) {
String path = location.getPath();
return cwd == null || path == null ? path : IoPackage.relativePath(cwd, new File(path));
}
};
abstract class PlainText implements MessageRenderer {
@Override
public String renderPreamble() {
return "";
}
@Override
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
String path = location.getPath();
public String render(
@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location
) {
String path = getPath(location);
String position = path == null ? "" : path + ": (" + (location.getLine() + ", " + location.getColumn()) + ") ";
return severity + ": " + position + message;
}
@Nullable
protected abstract String getPath(@NotNull CompilerMessageLocation location);
@Override
public String renderConclusion() {
return "";
}
};
}
String renderPreamble();
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
@@ -34,7 +34,6 @@ import java.util.List;
import static org.jetbrains.jet.cli.common.ExitCode.*;
public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull
private List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
@@ -49,7 +48,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) {
return exec(errStream, MessageRenderer.PLAIN, args);
return exec(errStream, MessageRenderer.PLAIN_WITH_RELATIVE_PATH, args);
}
@SuppressWarnings("UnusedDeclaration") // Used via reflection in CompilerRunnerUtil#invokeExecMethod
@@ -1,5 +1,5 @@
ERR:
ERROR: [TestData]/hello.kt: (4, 5) Unresolved reference: a
ERROR: hello.kt: (4, 5) Unresolved reference: a
Return code: 1
@@ -1,5 +1,5 @@
ERR:
ERROR: [TestData]/test.kt: (4, 20) Expecting an element
ERROR: test.kt: (4, 20) Expecting an element
Return code: 1
+5 -5
View File
@@ -1,6 +1,6 @@
WARNING: $TESTDATA_DIR$/classpath.kt: (8, 9) Variable 'a' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (9, 9) Variable 'c' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (10, 9) Variable 'e' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (11, 9) Variable 'f' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (12, 9) Variable 'j' is never used
WARNING: compiler/testData/cli/jvm/classpath.kt: (8, 9) Variable 'a' is never used
WARNING: compiler/testData/cli/jvm/classpath.kt: (9, 9) Variable 'c' is never used
WARNING: compiler/testData/cli/jvm/classpath.kt: (10, 9) Variable 'e' is never used
WARNING: compiler/testData/cli/jvm/classpath.kt: (11, 9) Variable 'f' is never used
WARNING: compiler/testData/cli/jvm/classpath.kt: (12, 9) Variable 'j' is never used
OK
@@ -1,3 +1,3 @@
ERROR: $TESTDATA_DIR$/conflictingOverloads.kt: (1, 1) 'internal fun a(): kotlin.List<kotlin.Int>' is already defined in root package
ERROR: $TESTDATA_DIR$/conflictingOverloads.kt: (2, 1) 'internal fun a(): kotlin.List<kotlin.String>' is already defined in root package
ERROR: compiler/testData/cli/jvm/conflictingOverloads.kt: (1, 1) 'internal fun a(): kotlin.List<kotlin.Int>' is already defined in root package
ERROR: compiler/testData/cli/jvm/conflictingOverloads.kt: (2, 1) 'internal fun a(): kotlin.List<kotlin.String>' is already defined in root package
COMPILATION_ERROR
@@ -1,10 +1,10 @@
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (1, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (2, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (3, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (4, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (5, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (6, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder1.kt: (7, 5) Redeclaration: x
ERROR: $TESTDATA_DIR$/diagnosticsOrder2.kt: (1, 5) Redeclaration: y
ERROR: $TESTDATA_DIR$/diagnosticsOrder2.kt: (2, 5) Redeclaration: y
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (1, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (2, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (3, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (4, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (5, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (6, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder1.kt: (7, 5) Redeclaration: x
ERROR: compiler/testData/cli/jvm/diagnosticsOrder2.kt: (1, 5) Redeclaration: y
ERROR: compiler/testData/cli/jvm/diagnosticsOrder2.kt: (2, 5) Redeclaration: y
COMPILATION_ERROR
@@ -1,4 +1,4 @@
ERROR: $TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt: (6, 14) Cannot weaken access privilege 'public' for 'c' in 'A'
ERROR: $TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt: (6, 14) Incompatible modifiers: 'private protected'
ERROR: $TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt: (6, 24) Incompatible modifiers: 'private protected'
ERROR: compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.kt: (6, 14) Cannot weaken access privilege 'public' for 'c' in 'A'
ERROR: compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.kt: (6, 14) Incompatible modifiers: 'private protected'
ERROR: compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.kt: (6, 24) Incompatible modifiers: 'private protected'
COMPILATION_ERROR
+10 -10
View File
@@ -1,29 +1,29 @@
WARNING: $TESTDATA_DIR$/signatureClash.kt: (26, 17) Parameter 'c' is never used
ERROR: $TESTDATA_DIR$/signatureClash.kt: (6, 5) Accidental override: The following declarations have the same JVM signature (getX()I):
WARNING: compiler/testData/cli/jvm/signatureClash.kt: (26, 17) Parameter 'c' is never used
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (6, 5) Accidental override: The following declarations have the same JVM signature (getX()I):
fun getX(): kotlin.Int
fun <get-x>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (8, 5) Platform declaration clash: The following declarations have the same JVM signature (getA()I):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (8, 5) Platform declaration clash: The following declarations have the same JVM signature (getA()I):
fun getA(): kotlin.Int
fun <get-a>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (9, 5) Platform declaration clash: The following declarations have the same JVM signature (getA()I):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (9, 5) Platform declaration clash: The following declarations have the same JVM signature (getA()I):
fun getA(): kotlin.Int
fun <get-a>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (12, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (12, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
fun <get-b>(): kotlin.Int
fun getB(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (13, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (13, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
fun <get-b>(): kotlin.Int
fun getB(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (16, 5) Platform declaration clash: The following declarations have the same JVM signature (getTr()I):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (16, 5) Platform declaration clash: The following declarations have the same JVM signature (getTr()I):
fun <get-tr>(): kotlin.Int
fun getTr(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (20, 5) Platform declaration clash: The following declarations have the same JVM signature (getTr()I):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (20, 5) Platform declaration clash: The following declarations have the same JVM signature (getTr()I):
fun <get-tr>(): kotlin.Int
fun getTr(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (24, 7) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (24, 7) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V):
fun f$b$0(c: C): kotlin.Unit
fun f(): kotlin.Unit
ERROR: $TESTDATA_DIR$/signatureClash.kt: (26, 5) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V):
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (26, 5) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V):
fun f$b$0(c: C): kotlin.Unit
fun f(): kotlin.Unit
COMPILATION_ERROR
@@ -1,5 +1,5 @@
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/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: $TESTDATA_DIR$/wrongAbiVersionLib/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$
WARNING: $TESTDATA_DIR$/wrongAbiVersion.kt: (3, 9) Parameter 'x' is never used
ERROR: $TESTDATA_DIR$/wrongAbiVersion.kt: (4, 3) Unresolved reference: bar
ERROR: compiler/testData/cli/jvm/wrongAbiVersionLib/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/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$
WARNING: compiler/testData/cli/jvm/wrongAbiVersion.kt: (3, 9) Parameter 'x' is never used
ERROR: compiler/testData/cli/jvm/wrongAbiVersion.kt: (4, 3) Unresolved reference: bar
COMPILATION_ERROR