提交 993bf650 编写于 作者: A Andrey Breslav

Providing reasonable information about compilation exceptions

Self message, cause message and both position in the file under compilation and the executed file position are reported
上级 f7d9ecaf
......@@ -16,10 +16,10 @@
package org.jetbrains.jet.codegen;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
/**
* @author alex.tkachman
......@@ -27,37 +27,14 @@ import com.intellij.psi.PsiFile;
public class CompilationException extends RuntimeException {
private PsiElement element;
CompilationException(String message, Throwable cause, PsiElement element) {
CompilationException(@NotNull String message, @Nullable Throwable cause, @NotNull PsiElement element) {
super(message, cause);
this.element = element;
}
public PsiElement getElement() {
return element;
}
@Override
public String toString() {
PsiFile psiFile = element.getContainingFile();
TextRange textRange = element.getTextRange();
Document document = psiFile.getViewProvider().getDocument();
int line;
int col;
if (document != null) {
line = document.getLineNumber(textRange.getStartOffset());
col = textRange.getStartOffset() - document.getLineStartOffset(line) + 1;
}
else {
line = -1;
col = -1;
}
String s2 = "";
Throwable cause = getCause();
if (cause != null) {
s2 = cause.getMessage() != null ? cause.getMessage() : cause.toString();
}
return "Internal error: (" + (line+1) + "," + col + ") " + s2 + "\n@" + where();
return getMessage();
}
private String where() {
......@@ -67,13 +44,20 @@ public class CompilationException extends RuntimeException {
if (stackTrace != null && stackTrace.length > 0) {
return stackTrace[0].getFileName() + ":" + stackTrace[0].getLineNumber();
}
else {
return "unknown";
}
return "unknown";
}
@Override
public String getMessage() {
return this.toString();
StringBuilder message = new StringBuilder("Back-end (JVM) Internal error: ").append(super.getMessage()).append("\n");
Throwable cause = getCause();
if (cause != null) {
String causeMessage = cause.getMessage();
message.append("Cause: ").append(causeMessage == null ? cause.toString() : causeMessage).append("\n");
}
message.append("File being compiled and position: ").append(DiagnosticUtils.atLocation(element)).append("\n");
message.append("The root cause was thrown from: ").append(where());
return message.toString();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册