diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java index 017b499e327..4c7627c8ed6 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java @@ -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(); } }