CLI: output relative paths in diagnostic messages
This commit is contained in:
+31
-6
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user