stepping in debugger actually works now

This commit is contained in:
Dmitry Jemerov
2011-07-14 13:36:01 +02:00
parent 252086263c
commit 15f5ccce2d
2 changed files with 46 additions and 5 deletions
@@ -63,6 +63,8 @@ public class ExpressionCodegen extends JetVisitor {
private final Stack<Label> myBreakTargets = new Stack<Label>();
private final Stack<StackValue> myStack = new Stack<StackValue>();
private int myLastLineNumber = -1;
private static final String[] PRIMITIVE_TYPE_INFO_FIELDS = {
null,
"BOOL_TYPE_INFO",
@@ -116,7 +118,7 @@ public class ExpressionCodegen extends JetVisitor {
}
private void gen(JetElement expr) {
if (expr == null) throw new CompilationException();
markLineNumber(expr);
expr.accept(this);
}
@@ -582,7 +584,6 @@ public class ExpressionCodegen extends JetVisitor {
for (int i = 0, statementsSize = statements.size(); i < statementsSize; i++) {
JetElement statement = statements.get(i);
markLineNumber(statement);
if (i == statements.size() - 1) {
gen(statement);
}
@@ -609,10 +610,15 @@ public class ExpressionCodegen extends JetVisitor {
private void markLineNumber(JetElement statement) {
final Document document = statement.getContainingFile().getViewProvider().getDocument();
if (document != null) {
int lineNumber = document.getLineNumber(statement.getTextRange().getStartOffset());
int lineNumber = document.getLineNumber(statement.getTextRange().getStartOffset()); // 0-based
if (lineNumber == myLastLineNumber) {
return;
}
myLastLineNumber = lineNumber;
Label label = new Label();
v.visitLabel(label);
v.visitLineNumber(lineNumber, label);
v.visitLineNumber(lineNumber+1, label); // 1-based
}
}
@@ -5,8 +5,11 @@ import com.intellij.debugger.PositionManager;
import com.intellij.debugger.SourcePosition;
import com.intellij.debugger.engine.DebugProcess;
import com.intellij.debugger.requests.ClassPrepareRequestor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.ProjectScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.Location;
@@ -37,11 +40,41 @@ public class JetPositionManager implements PositionManager {
@Override
@Nullable
public SourcePosition getSourcePosition(@Nullable Location location) throws NoDataException {
if (location == null) {
throw new NoDataException();
}
PsiFile psiFile = getPsiFileByLocation(location);
int lineNumber;
try {
lineNumber = location.lineNumber() - 1;
} catch (InternalError e) {
lineNumber = -1;
}
if (lineNumber >= 0) {
return SourcePosition.createFromLine(psiFile, lineNumber);
}
throw new NoDataException();
}
private PsiFile getPsiFileByLocation(Location location) {
private PsiFile getPsiFileByLocation(Location location) throws NoDataException {
try {
final String sourceName = location.sourceName();
final Project project = myDebugProcess.getProject();
final PsiFile[] files = FilenameIndex.getFilesByName(project, sourceName, ProjectScope.getAllScope(project));
if (files.length == 1 && files[0] instanceof JetFile) {
return files[0];
}
} catch (AbsentInformationException e) {
throw new NoDataException();
}
/* TODO
final ReferenceType referenceType = location.declaringType();
if (referenceType == null) {
return null;
@@ -49,6 +82,8 @@ public class JetPositionManager implements PositionManager {
// TODO
return null;
*/
throw new NoDataException();
}
@NotNull