private static boolean equalSourcePositions( @Nullable final XSourcePosition position1, @Nullable final XSourcePosition position2) { return position1 != null && position2 != null && position1.getFile().equals(position2.getFile()) && position1.getLine() == position2.getLine(); }
private static void removeJSBreakpointsInDartFiles(final Project project) { final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager(); final Collection<XBreakpoint<?>> toRemove = new ArrayList<XBreakpoint<?>>(); for (XBreakpoint<?> breakpoint : breakpointManager.getAllBreakpoints()) { final XSourcePosition position = breakpoint.getSourcePosition(); if (position != null && position.getFile().getFileType() == DartFileType.INSTANCE && !(breakpoint.getType() instanceof DartLineBreakpointType)) { toRemove.add(breakpoint); } } if (!toRemove.isEmpty()) { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { for (XBreakpoint<?> breakpoint : toRemove) { breakpointManager.removeBreakpoint(breakpoint); } } }); } }
@Nullable public String getMethodName() { XSourcePosition position = myXBreakpoint.getSourcePosition(); if (position != null) { int offset = position.getOffset(); return findOwnerMethod(getPsiFile(), offset); } return null; }
protected void runToLine(int line) throws InvocationTargetException, InterruptedException { XDebugSession currentSession = XDebuggerManager.getInstance(getProject()).getCurrentSession(); XSourcePosition position = currentSession.getCurrentPosition(); currentSession.runToPosition( XDebuggerUtil.getInstance().createPosition(position.getFile(), line), false); waitForPause(); }
private ExpressionComboBoxPanel( Project project, String historyId, XSourcePosition sourcePosition) { myComboBox = new DebuggerExpressionComboBox(project, historyId); if (sourcePosition != null) { PsiElement element = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project); myComboBox.setContext(element); } else { myComboBox.setContext(null); } }
@Override public String toString() { if (myXSourcePosition != null) { return "JavaFrame " + myXSourcePosition.getFile().getName() + ":" + myXSourcePosition.getLine(); } else { return "JavaFrame position unknown"; } }
@Override public void reload() { ApplicationManager.getApplication().assertReadAccessAllowed(); final XSourcePosition position = myXBreakpoint.getSourcePosition(); try { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(position.getFile()); mySourcePosition = SourcePosition.createFromOffset(psiFile, position.getOffset()); } catch (Exception e) { mySourcePosition = null; } reload(BreakpointManager.getPsiFile(myXBreakpoint, myProject)); }
@Override public void reload() { ApplicationManager.getApplication().assertReadAccessAllowed(); XSourcePosition position = myXBreakpoint.getSourcePosition(); PsiFile psiFile = getPsiFile(); if (position != null && psiFile != null) { mySourcePosition = SourcePosition.createFromLine(psiFile, position.getLine()); reload(psiFile); } else { mySourcePosition = null; } }
@Nullable public PsiFile getPsiFile() { ApplicationManager.getApplication().assertReadAccessAllowed(); XSourcePosition position = myXBreakpoint.getSourcePosition(); if (position != null) { VirtualFile file = position.getFile(); if (file.isValid()) { return PsiManager.getInstance(myProject).findFile(file); } } return null; }
public void perform(@NotNull final Project project, final AnActionEvent event) { Editor editor = event.getData(CommonDataKeys.EDITOR); // do not toggle more than once on the same line Set<Integer> processedLines = new HashSet<Integer>(); for (XSourcePosition position : XDebuggerUtilImpl.getAllCaretsPositions(project, event.getDataContext())) { if (processedLines.add(position.getLine())) { XBreakpointUtil.toggleLineBreakpoint( project, position.getFile(), editor, position.getLine(), myTemporary, true); } } }
public void addBreakpoint( @NotNull final String isolateId, @Nullable final XSourcePosition position, @NotNull final VmServiceConsumers.BreakpointConsumerWrapper consumer) { if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) { consumer.sourcePositionNotApplicable(); return; } addRequest( () -> { final int line = position.getLine() + 1; for (String uri : myDebugProcess.getUrisForFile(position.getFile())) { myVmService.addBreakpointWithScriptUri(isolateId, uri, line, consumer); } }); }
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; }
public void addBreakpoint( @NotNull final String isolateId, @NotNull final XLineBreakpoint<XBreakpointProperties> xBreakpoint, @NotNull final VmServiceConsumers.BreakpointConsumerWrapper consumer) { final XSourcePosition position = xBreakpoint.getSourcePosition(); if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) { consumer.sourcePositionNotApplicable(); return; } addRequest( new Runnable() { @Override public void run() { final String uri = myDebugProcess.getUriForFile(position.getFile()); final int line = position.getLine() + 1; myVmService.addBreakpointWithScriptUri(isolateId, uri, line, consumer); } }); }
@Override @NotNull public List<PySmartStepIntoVariant> computeSmartStepVariants(@NotNull XSourcePosition position) { final Document document = FileDocumentManager.getInstance().getDocument(position.getFile()); final List<PySmartStepIntoVariant> variants = Lists.newArrayList(); final Set<PyCallExpression> visitedCalls = Sets.newHashSet(); final int line = position.getLine(); XDebuggerUtil.getInstance() .iterateLine( mySession.getProject(), document, line, psiElement -> { addVariants(document, line, psiElement, variants, visitedCalls); return true; }); return variants; }
public void doUpdateDetailView(DetailView panel, boolean editorOnly) { Project project = ((XBreakpointBase) myBreakpoint).getProject(); XSourcePosition sourcePosition = myBreakpoint.getSourcePosition(); if (sourcePosition != null) { if (!showInEditor(panel, sourcePosition.getFile(), sourcePosition.getLine())) { return; } } else { panel.clearEditor(); } if (!editorOnly) { XLightBreakpointPropertiesPanel<XBreakpoint<?>> propertiesPanel = new XLightBreakpointPropertiesPanel<XBreakpoint<?>>( project, getManager(), myBreakpoint, true); propertiesPanel.loadProperties(); panel.setDetailPanel(propertiesPanel.getMainPanel()); } }
protected String getFileName() { XSourcePosition sourcePosition = myXBreakpoint.getSourcePosition(); return sourcePosition != null ? sourcePosition.getFile().getName() : ""; }
public int getLineIndex() { XSourcePosition sourcePosition = myXBreakpoint.getSourcePosition(); return sourcePosition != null ? sourcePosition.getLine() : -1; }
public boolean isAt(@NotNull Document document, int offset) { final VirtualFile file = FileDocumentManager.getInstance().getFile(document); int line = document.getLineNumber(offset); XSourcePosition position = myXBreakpoint.getSourcePosition(); return position != null && position.getLine() == line && position.getFile().equals(file); }
@Nullable @Override public EditorNotificationPanel createNotificationPanel( @NotNull VirtualFile file, @NotNull FileEditor fileEditor) { XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession(); if (session == null) { FILE_PROCESSED_KEY.set(file, null); return null; } XSourcePosition position = session.getCurrentPosition(); if (position == null || !file.equals(position.getFile())) { FILE_PROCESSED_KEY.set(file, null); return null; } if (file.getFileType() == JavaClassFileType.INSTANCE) return null; final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); if (psiFile == null) return null; if (!(psiFile instanceof PsiJavaFile)) return null; PsiClass[] classes = ((PsiJavaFile) psiFile).getClasses(); if (classes.length == 0) return null; PsiClass baseClass = classes[0]; String name = baseClass.getQualifiedName(); if (name == null) return null; if (DumbService.getInstance(myProject).isDumb()) return null; ArrayList<PsiClass> alts = ContainerUtil.newArrayList( JavaPsiFacade.getInstance(myProject) .findClasses(name, GlobalSearchScope.allScope(myProject))); ContainerUtil.removeDuplicates(alts); FILE_PROCESSED_KEY.set(file, true); if (alts.size() > 1) { for (PsiClass cls : alts) { if (cls.equals(baseClass) || cls.getNavigationElement().equals(baseClass)) { alts.remove(cls); break; } } alts.add(0, baseClass); ComboBoxClassElement[] elems = ContainerUtil.map2Array( alts, ComboBoxClassElement.class, new Function<PsiClass, ComboBoxClassElement>() { @Override public ComboBoxClassElement fun(PsiClass psiClass) { return new ComboBoxClassElement(psiClass); } }); return new AlternativeSourceNotificationPanel(elems, baseClass, myProject, file); } return null; }
/** * 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 toggleLineBreakpoint( @NotNull Project project, @NotNull XSourcePosition position, @Nullable Editor editor, boolean temporary, boolean moveCarret) { 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()); final XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line); if (breakpoint != null && temporary && !breakpoint.isTemporary()) { breakpoint.setTemporary(true); } else if (type.canPutAt(file, line, project) || breakpoint != null) { if (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); if (editor != null && lineStart != lineWinner) { int offset = editor.getDocument().getLineStartOffset(lineWinner); ExpandRegionAction.expandRegionAtOffset(project, editor, offset); if (moveCarret) { editor.getCaretModel().moveToOffset(offset); } } return res; } } return PromiseKt.rejectedPromise(); }