Drop CompilerMessageLocation.NO_LOCATION, use null everywhere instead
This commit is contained in:
@@ -77,7 +77,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
Usage.print(errStream, createArguments(), false);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
errStream.println(messageRenderer.render(EXCEPTION, OutputMessageUtil.renderException(t), CompilerMessageLocation.NO_LOCATION));
|
||||
errStream.println(messageRenderer.render(EXCEPTION, OutputMessageUtil.renderException(t), null));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.messages;
|
||||
|
||||
import kotlin.io.FilesKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.utils.fileUtils.FileUtilsKt;
|
||||
@@ -36,7 +35,7 @@ public interface MessageRenderer {
|
||||
};
|
||||
|
||||
MessageRenderer PLAIN_FULL_PATHS = new PlainTextMessageRenderer() {
|
||||
@Nullable
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPath(@NotNull CompilerMessageLocation location) {
|
||||
return location.getPath();
|
||||
@@ -44,20 +43,18 @@ public interface MessageRenderer {
|
||||
};
|
||||
|
||||
MessageRenderer PLAIN_RELATIVE_PATHS = new PlainTextMessageRenderer() {
|
||||
@NotNull
|
||||
private final File cwd = new File(".").getAbsoluteFile();
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPath(@NotNull CompilerMessageLocation location) {
|
||||
String path = location.getPath();
|
||||
return path == null ? path : FileUtilsKt.descendantRelativeTo(new File(path), cwd).getPath();
|
||||
return FileUtilsKt.descendantRelativeTo(new File(location.getPath()), cwd).getPath();
|
||||
}
|
||||
};
|
||||
|
||||
String renderPreamble();
|
||||
|
||||
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
|
||||
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location);
|
||||
|
||||
String renderConclusion();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MessageUtil {
|
||||
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public static CompilerMessageLocation psiFileToMessageLocation(
|
||||
@NotNull PsiFile file,
|
||||
@Nullable String defaultValue,
|
||||
|
||||
+5
-7
@@ -57,16 +57,14 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(
|
||||
@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location
|
||||
) {
|
||||
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int line = location.getLine();
|
||||
int column = location.getColumn();
|
||||
String lineContent = location.getLineContent();
|
||||
int line = location != null ? location.getLine() : -1;
|
||||
int column = location != null ? location.getColumn() : -1;
|
||||
String lineContent = location != null ? location.getLineContent() : null;
|
||||
|
||||
String path = getPath(location);
|
||||
String path = location != null ? getPath(location) : null;
|
||||
if (path != null) {
|
||||
result.append(path);
|
||||
result.append(":");
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
|
||||
hasErrors |= severity.isError();
|
||||
|
||||
errStream.println(messageRenderer.render(severity, message, location != null ? location : CompilerMessageLocation.NO_LOCATION));
|
||||
errStream.println(messageRenderer.render(severity, message, location));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.cli.common.messages;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class XmlMessageRenderer implements MessageRenderer {
|
||||
@Override
|
||||
@@ -26,11 +27,11 @@ public class XmlMessageRenderer implements MessageRenderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
||||
public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @Nullable CompilerMessageLocation location) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
String tagName = severity.getPresentableName();
|
||||
out.append("<").append(tagName);
|
||||
if (location.getPath() != null) {
|
||||
if (location != null) {
|
||||
out.append(" path=\"").append(e(location.getPath())).append("\"");
|
||||
out.append(" line=\"").append(location.getLine()).append("\"");
|
||||
out.append(" column=\"").append(location.getColumn()).append("\"");
|
||||
|
||||
Reference in New Issue
Block a user