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);