Properly positioning compilation exceptions in the IDE

This commit is contained in:
Andrey Breslav
2012-04-25 12:25:00 +04:00
parent 3eb6b3d0f5
commit d0bd5cf9c6
5 changed files with 60 additions and 14 deletions
@@ -24,6 +24,9 @@ public interface CompilationErrorHandler {
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
@Override
public void reportException(Throwable exception, String fileUrl) {
if (exception instanceof RuntimeException) {
throw (RuntimeException)exception;
}
throw new IllegalStateException(exception);
}
};
@@ -23,20 +23,22 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
/**
* @author alex.tkachman
* @author abreslav
*/
public class CompilationException extends RuntimeException {
private PsiElement element;
private final PsiElement element;
CompilationException(@NotNull String message, @Nullable Throwable cause, @NotNull PsiElement element) {
super(message, cause);
this.element = element;
}
@Override
public String toString() {
return getMessage();
@NotNull
public PsiElement getElement() {
return element;
}
private String where() {
Throwable cause = getCause();
Throwable throwable = cause != null ? cause : this;
@@ -56,7 +58,7 @@ public class CompilationException extends RuntimeException {
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());
message.append("The root cause was thrown at: ").append(where());
return message.toString();
}