use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class DebuggerContextUtil method findNearest.
public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiElement psi, @NotNull PsiFile file) {
if (psi instanceof PsiCompiledElement) {
// it makes no sense to compute text range of compiled element
return null;
}
final DebuggerSession session = context.getDebuggerSession();
if (session != null) {
try {
final XDebugSession debugSession = session.getXDebugSession();
if (debugSession != null) {
final XSourcePosition position = debugSession.getCurrentPosition();
Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true);
//final Editor editor = fileEditor instanceof TextEditorImpl ? ((TextEditorImpl)fileEditor).getEditor() : null;
if (editor != null && position != null && position.getFile().equals(file.getOriginalFile().getVirtualFile())) {
PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false);
final Collection<TextRange> ranges = IdentifierHighlighterPass.getUsages(psi, method != null ? method : file, false);
final int breakPointLine = position.getLine();
int bestLine = -1;
int bestOffset = -1;
for (TextRange range : ranges) {
final int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
if (line > bestLine && line < breakPointLine) {
bestLine = line;
bestOffset = range.getStartOffset();
} else if (line == breakPointLine) {
bestOffset = range.getStartOffset();
break;
}
}
if (bestOffset > -1) {
return SourcePosition.createFromOffset(file, bestOffset);
}
}
}
} catch (Exception ignore) {
}
}
return null;
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class CodeFragmentFactoryContextWrapper method wrapContext.
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
if (project.isDefault())
return originalContext;
//TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
return originalContext;
}
PsiElement context = originalContext;
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session != null) {
XValueMarkers<?, ?> markers = ((XDebugSessionImpl) session).getValueMarkers();
Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
//final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
if (!ContainerUtil.isEmpty(markupMap)) {
final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
int offset = markupVariables.getFirst().length() - 1;
final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
codeFragment.accept(new JavaRecursiveElementVisitor() {
public void visitLocalVariable(PsiLocalVariable variable) {
final String name = variable.getName();
variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
}
});
final PsiElement newContext = codeFragment.findElementAt(offset);
if (newContext != null) {
context = newContext;
}
}
}
return context;
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class ShowTypesAction method update.
@Override
public void update(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project != null) {
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session != null && session.getDebugProcess() instanceof JavaDebugProcess) {
e.getPresentation().setEnabledAndVisible(true);
super.update(e);
return;
}
}
e.getPresentation().setEnabledAndVisible(false);
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class ThreadDumpAction 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();
process.getManagerThread().invoke(new DebuggerCommandImpl() {
protected void action() throws Exception {
final VirtualMachineProxyImpl vm = process.getVirtualMachineProxy();
vm.suspend();
try {
final List<ThreadState> threads = buildThreadStates(vm);
ApplicationManager.getApplication().invokeLater(() -> {
XDebugSession xSession = session.getXDebugSession();
if (xSession != null) {
DebuggerUtilsEx.addThreadDump(project, threads, xSession.getUI(), session);
}
}, ModalityState.NON_MODAL);
} finally {
vm.resume();
}
}
});
}
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class XsltBreakpointHandler method registerBreakpoint.
@Override
public void registerBreakpoint(@NotNull XLineBreakpoint<XBreakpointProperties> breakpoint) {
final XSourcePosition sourcePosition = breakpoint.getSourcePosition();
if (sourcePosition == null || !sourcePosition.getFile().exists() || !sourcePosition.getFile().isValid()) {
// ???
return;
}
final VirtualFile file = sourcePosition.getFile();
final Project project = myXsltDebugProcess.getSession().getProject();
final String fileURL = getFileURL(file);
final int lineNumber = getActualLineNumber(breakpoint, project);
if (lineNumber == -1) {
final XDebugSession session = myXsltDebugProcess.getSession();
session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, "Unsupported breakpoint position");
return;
}
try {
final BreakpointManager manager = myXsltDebugProcess.getBreakpointManager();
Breakpoint bp;
if ((bp = manager.getBreakpoint(fileURL, lineNumber)) != null) {
bp.setEnabled(true);
} else {
manager.setBreakpoint(fileURL, lineNumber);
}
} catch (DebuggerStoppedException ignore) {
} catch (VMPausedException e) {
final XDebugSession session = myXsltDebugProcess.getSession();
session.reportMessage("Target VM is not responding. Breakpoint can not be set", MessageType.ERROR);
session.updateBreakpointPresentation(breakpoint, AllIcons.Debugger.Db_invalid_breakpoint, "Target VM is not responding. Breakpoint can not be set");
}
}
Aggregations