use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.
the class JvmSmartStepIntoActionHandler method isEnabled.
public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
final DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
DebuggerSession debuggerSession = context.getDebuggerSession();
final boolean isPaused = debuggerSession != null && debuggerSession.isPaused();
final SuspendContextImpl suspendContext = context.getSuspendContext();
final boolean hasCurrentThread = suspendContext != null && suspendContext.getThread() != null;
return isPaused && hasCurrentThread;
}
use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.
the class ThreadDumpAction method update.
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
Project project = e.getProject();
if (project == null) {
presentation.setEnabled(false);
return;
}
DebuggerSession debuggerSession = (DebuggerManagerEx.getInstanceEx(project)).getContext().getDebuggerSession();
presentation.setEnabled(debuggerSession != null && debuggerSession.isAttached());
}
use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.
the class ToggleFieldBreakpointAction method getPlace.
@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null) {
return null;
}
if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
if (psiElement instanceof PsiField) {
return SourcePosition.createFromElement(psiElement);
}
return null;
}
final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess != null) {
// if there is an active debug session
final Ref<SourcePosition> positionRef = new Ref<>(null);
debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
@Override
public void threadAction() {
ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
}
});
final SourcePosition sourcePosition = positionRef.get();
if (sourcePosition != null) {
return sourcePosition;
}
}
}
if (DebuggerAction.isContextView(event)) {
DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
if (tree != null && tree.getSelectionPath() != null) {
DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
if (psiClass != null) {
psiClass = (PsiClass) psiClass.getNavigationElement();
final PsiField psiField = psiClass.findFieldByName(field.name(), true);
if (psiField != null) {
return SourcePosition.createFromElement(psiField);
}
}
}
}
return null;
}
Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
}
if (editor != null) {
final Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
if (field != null) {
return SourcePosition.createFromElement(field);
}
}
}
}
return null;
}
use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.
the class EditSourceAction method getSourcePosition.
private static SourcePosition getSourcePosition(DebuggerTreeNodeImpl selectedNode, DebuggerContextImpl debuggerContext) {
final DebuggerContextImpl context = debuggerContext;
if (selectedNode == null || context == null) {
return null;
}
final Project project = selectedNode.getProject();
final DebuggerSession debuggerSession = context.getDebuggerSession();
if (debuggerSession == null) {
return null;
}
NodeDescriptorImpl nodeDescriptor = selectedNode.getDescriptor();
if (nodeDescriptor instanceof WatchItemDescriptor) {
Modifier modifier = ((WatchItemDescriptor) nodeDescriptor).getModifier();
if (modifier == null) {
return null;
}
nodeDescriptor = (NodeDescriptorImpl) modifier.getInspectItem(project);
}
final NodeDescriptorImpl nodeDescriptor1 = nodeDescriptor;
return ApplicationManager.getApplication().runReadAction(new Computable<SourcePosition>() {
public SourcePosition compute() {
return SourcePositionProvider.getSourcePosition(nodeDescriptor1, project, context);
}
});
}
use of com.intellij.debugger.impl.DebuggerSession in project intellij-community by JetBrains.
the class ExportThreadsAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return;
}
DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
final DebuggerSession session = context.getDebuggerSession();
if (session != null && session.isAttached()) {
final DebugProcessImpl process = context.getDebugProcess();
if (process != null) {
process.getManagerThread().invoke(new DebuggerCommandImpl() {
protected void action() throws Exception {
final List<ThreadState> threads = ThreadDumpAction.buildThreadStates(process.getVirtualMachineProxy());
ApplicationManager.getApplication().invokeLater(() -> ExportToTextFileAction.export(project, ThreadDumpPanel.createToFileExporter(project, threads)), ModalityState.NON_MODAL);
}
});
}
}
}
Aggregations