use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.
the class XBreakpointUtil method toggleLineBreakpoint.
/**
* Toggle line breakpoint with editor support:
* - unfolds folded block on the line
* - if folded, checks if line breakpoints could be toggled inside folded text
*/
@NotNull
public static Promise<XLineBreakpoint> toggleLineBreakpoint(@NotNull Project project, @NotNull XSourcePosition position, @Nullable Editor editor, boolean temporary, boolean moveCaret, boolean canRemove) {
int lineStart = position.getLine();
VirtualFile file = position.getFile();
// for folded text check each line and find out type with the biggest priority
int linesEnd = lineStart;
if (editor != null) {
FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, lineStart);
if (region != null && !region.isExpanded()) {
linesEnd = region.getDocument().getLineNumber(region.getEndOffset());
}
}
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
XLineBreakpointType<?>[] lineTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
XLineBreakpointType<?> typeWinner = null;
int lineWinner = -1;
for (int line = lineStart; line <= linesEnd; line++) {
int maxPriority = 0;
for (XLineBreakpointType<?> type : lineTypes) {
maxPriority = Math.max(maxPriority, type.getPriority());
XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
if ((type.canPutAt(file, line, project) || breakpoint != null) && (typeWinner == null || type.getPriority() > typeWinner.getPriority())) {
typeWinner = type;
lineWinner = line;
}
}
// already found max priority type - stop
if (typeWinner != null && typeWinner.getPriority() == maxPriority) {
break;
}
}
if (typeWinner != null) {
XSourcePosition winPosition = (lineStart == lineWinner) ? position : XSourcePositionImpl.create(file, lineWinner);
if (winPosition != null) {
Promise<XLineBreakpoint> res = XDebuggerUtilImpl.toggleAndReturnLineBreakpoint(project, typeWinner, winPosition, temporary, editor, canRemove);
if (editor != null && lineStart != lineWinner) {
int offset = editor.getDocument().getLineStartOffset(lineWinner);
ExpandRegionAction.expandRegionAtOffset(project, editor, offset);
if (moveCaret) {
editor.getCaretModel().moveToOffset(offset);
}
}
return res;
}
}
return rejectedPromise();
}
use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.
the class XBreakpointItem method doUpdateDetailView.
@Override
public void doUpdateDetailView(DetailView panel, boolean editorOnly) {
XBreakpointBase breakpoint = (XBreakpointBase) myBreakpoint;
Project project = breakpoint.getProject();
//saveState();
if (myPropertiesPanel != null) {
myPropertiesPanel.dispose();
myPropertiesPanel = null;
}
if (!editorOnly) {
myPropertiesPanel = new XLightBreakpointPropertiesPanel(project, getManager(), breakpoint, true);
panel.setPropertiesPanel(myPropertiesPanel.getMainPanel());
}
XSourcePosition sourcePosition = myBreakpoint.getSourcePosition();
if (sourcePosition != null && sourcePosition.getFile().isValid()) {
showInEditor(panel, sourcePosition.getFile(), sourcePosition.getLine());
} else {
panel.clearEditor();
}
if (myPropertiesPanel != null) {
myPropertiesPanel.setDetailView(panel);
myPropertiesPanel.loadProperties();
myPropertiesPanel.getMainPanel().revalidate();
}
}
use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.
the class XBreakpointFileGroupingRule method getGroup.
public XBreakpointFileGroup getGroup(@NotNull final B breakpoint, @NotNull final Collection<XBreakpointFileGroup> groups) {
if (!(breakpoint instanceof XLineBreakpoint)) {
return null;
}
XSourcePosition position = ((XLineBreakpoint) breakpoint).getSourcePosition();
if (position == null)
return null;
VirtualFile file = position.getFile();
for (XBreakpointFileGroup group : groups) {
if (group.getFile().equals(file)) {
return group;
}
}
return new XBreakpointFileGroup(file);
}
use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.
the class XDebuggerEvaluateActionHandler method showDialog.
private static void showDialog(@NotNull XDebugSession session, VirtualFile file, XDebuggerEditorsProvider editorsProvider, XStackFrame stackFrame, XDebuggerEvaluator evaluator, @NotNull XExpression expression) {
if (expression.getLanguage() == null) {
Language language = null;
if (stackFrame != null) {
XSourcePosition position = stackFrame.getSourcePosition();
if (position != null) {
language = LanguageUtil.getFileLanguage(position.getFile());
}
}
if (language == null && file != null) {
language = LanguageUtil.getFileTypeLanguage(file.getFileType());
}
expression = new XExpressionImpl(expression.getExpression(), language, expression.getCustomInfo(), expression.getMode());
}
new XDebuggerEvaluationDialog(session, editorsProvider, evaluator, expression, stackFrame == null ? null : stackFrame.getSourcePosition()).show();
}
use of com.intellij.xdebugger.XSourcePosition in project intellij-community by JetBrains.
the class XToggleLineBreakpointActionHandler method isEnabled.
@Override
public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
XLineBreakpointType<?>[] breakpointTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
for (XSourcePosition position : XDebuggerUtilImpl.getAllCaretsPositions(project, event.getDataContext())) {
for (XLineBreakpointType<?> breakpointType : breakpointTypes) {
final VirtualFile file = position.getFile();
final int line = position.getLine();
if (breakpointType.canPutAt(file, line, project) || breakpointManager.findBreakpointAtLine(breakpointType, file, line) != null) {
return true;
}
}
}
return false;
}
Aggregations