better location diagnostic of internal errors

This commit is contained in:
Alex Tkachman
2012-01-18 21:27:03 +01:00
parent 86a33f8b16
commit 9b0ff6b4d8
2 changed files with 30 additions and 0 deletions
@@ -73,6 +73,9 @@ public abstract class ClassBodyCodegen {
else if (declaration instanceof JetNamedFunction) {
try {
genNamedFunction((JetNamedFunction) declaration, functionCodegen);
}
catch(CompilationException e) {
throw e;
} catch (RuntimeException e) {
throw new RuntimeException("Error generating method " + myClass.getName() + "." + declaration.getName() + " in " + context, e);
}
@@ -1,7 +1,15 @@
package org.jetbrains.jet.codegen;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import org.objectweb.asm.Label;
import static com.intellij.openapi.compiler.CompilerMessageCategory.ERROR;
/**
* @author alex.tkachman
@@ -17,4 +25,23 @@ public class CompilationException extends RuntimeException {
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;
}
return "Internal error: (" + (line+1) + "," + col + ") " + getCause().toString();
}
}