package jetbrains.mps.debug.api; /*Generated by MPS */ import com.intellij.openapi.project.Project; import jetbrains.mps.debug.api.programState.IStackFrame; import java.util.List; import org.jetbrains.annotations.NotNull; import jetbrains.mps.debug.api.source.PositionProvider; import org.jetbrains.annotations.NonNls; import jetbrains.mps.debug.api.programState.GenericSourceCodeLocation; import jetbrains.mps.util.EqualUtil; import jetbrains.mps.debug.api.source.SourcePosition; public class DebuggableFramesSelector implements IDebuggableFramesSelector { private final Project myProject; private AbstractDebugSession mySession; public DebuggableFramesSelector(Project project, AbstractDebugSession session) { myProject = project; mySession = session; } @Override public IStackFrame findDeepestDebuggableFrame(List<IStackFrame> frames) { for (IStackFrame frame : frames) { if (isDebuggableFrame(frame)) { return frame; } } if (frames.isEmpty()) { return null; } return frames.get(0); } @Override public int findDeepestDebuggableFrameIndex(List<IStackFrame> frames) { int index = 0; for (IStackFrame frame : frames) { if (isDebuggableFrame(frame)) { return index; } index++; } if (frames.isEmpty()) { return AbstractUiState.NO_FRAME; } return 0; } @Override public boolean isDebuggableFrame(@NotNull IStackFrame frame) { return PositionProvider.getInstance(myProject).getPosition(frame.getLocation(), mySession) != null; } @Override public boolean isDebuggablePosition(@NonNls String unitName, @NonNls String fileName, int position) { return PositionProvider.getInstance(myProject).getPosition(new GenericSourceCodeLocation(unitName, fileName, position), mySession) != null; } @Override public boolean isSamePosition(String lastUnitName, String lastFileName, int lastLineNumber, int lastFrameCount, String nextUnitName, String nextFileName, int nextLineNumber, int nextFrameCount) { if (EqualUtil.equals(lastUnitName, nextUnitName) && lastLineNumber == nextLineNumber && lastFrameCount == nextFrameCount) { return true; } PositionProvider posProvider = PositionProvider.getInstance(myProject); SourcePosition lastPointer = posProvider.getPosition(new GenericSourceCodeLocation(lastUnitName, lastFileName, lastLineNumber), mySession); SourcePosition nextPointer = posProvider.getPosition(new GenericSourceCodeLocation(nextUnitName, nextFileName, nextLineNumber), mySession); return eq_xhry8p_a0e0h(lastPointer, nextPointer); } private static boolean eq_xhry8p_a0e0h(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } }