@NotNull public static List<Pair<Breakpoint, Event>> getEventDescriptors( SuspendContextImpl suspendContext) { DebuggerManagerThreadImpl.assertIsManagerThread(); if (suspendContext == null) { return Collections.emptyList(); } final EventSet events = suspendContext.getEventSet(); if (events == null) { return Collections.emptyList(); } final List<Pair<Breakpoint, Event>> eventDescriptors = new SmartList<Pair<Breakpoint, Event>>(); final RequestManagerImpl requestManager = suspendContext.getDebugProcess().getRequestsManager(); for (final Event event : events) { final Requestor requestor = requestManager.findRequestor(event.request()); if (requestor instanceof Breakpoint) { eventDescriptors.add(Pair.create((Breakpoint) requestor, event)); } } return eventDescriptors; }
private static Pair<Set<String>, Set<TextWithImports>> findReferencedVars( Set<String> visibleVars, SourcePosition position) { final int line = position.getLine(); if (line < 0) { return Pair.create(Collections.<String>emptySet(), Collections.<TextWithImports>emptySet()); } final PsiFile positionFile = position.getFile(); if (!positionFile.getLanguage().isKindOf(JavaLanguage.INSTANCE)) { return Pair.create(visibleVars, Collections.<TextWithImports>emptySet()); } final VirtualFile vFile = positionFile.getVirtualFile(); final Document doc = vFile != null ? FileDocumentManager.getInstance().getDocument(vFile) : null; if (doc == null || doc.getLineCount() == 0 || line > (doc.getLineCount() - 1)) { return Pair.create(Collections.<String>emptySet(), Collections.<TextWithImports>emptySet()); } final TextRange limit = calculateLimitRange(positionFile, doc, line); int startLine = Math.max(limit.getStartOffset(), line - 1); startLine = Math.min(startLine, limit.getEndOffset()); while (startLine > limit.getStartOffset() && shouldSkipLine(positionFile, doc, startLine)) { startLine--; } final int startOffset = doc.getLineStartOffset(startLine); int endLine = Math.min(line + 2, limit.getEndOffset()); while (endLine < limit.getEndOffset() && shouldSkipLine(positionFile, doc, endLine)) { endLine++; } final int endOffset = doc.getLineEndOffset(endLine); final TextRange lineRange = new TextRange(startOffset, endOffset); if (!lineRange.isEmpty()) { final int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), doc.getLineStartOffset(line), " \t"); PsiElement element = positionFile.findElementAt(offset); if (element != null) { PsiMethod method = PsiTreeUtil.getNonStrictParentOfType(element, PsiMethod.class); if (method != null) { element = method; } else { PsiField field = PsiTreeUtil.getNonStrictParentOfType(element, PsiField.class); if (field != null) { element = field; } else { final PsiClassInitializer initializer = PsiTreeUtil.getNonStrictParentOfType(element, PsiClassInitializer.class); if (initializer != null) { element = initializer; } } } //noinspection unchecked if (element instanceof PsiCompiledElement) { return Pair.create(visibleVars, Collections.<TextWithImports>emptySet()); } else { VariablesCollector collector = new VariablesCollector(visibleVars, adjustRange(element, lineRange)); element.accept(collector); return Pair.create(collector.getVars(), collector.getExpressions()); } } } return Pair.create(Collections.<String>emptySet(), Collections.<TextWithImports>emptySet()); }
// copied from DebuggerTree private void buildVariablesThreadAction( DebuggerContextImpl debuggerContext, XValueChildrenList children, XCompositeNode node) { try { final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext(); if (evaluationContext == null) { return; } if (!debuggerContext.isEvaluationPossible()) { node.setErrorMessage(MessageDescriptor.EVALUATION_NOT_POSSIBLE.getLabel()); // myChildren.add(myNodeManager.createNode(MessageDescriptor.EVALUATION_NOT_POSSIBLE, // evaluationContext)); } final Location location = myDescriptor.getLocation(); final ObjectReference thisObjectReference = myDescriptor.getThisObject(); if (thisObjectReference != null) { ValueDescriptorImpl thisDescriptor = myNodeManager.getThisDescriptor(null, thisObjectReference); children.add(JavaValue.create(thisDescriptor, evaluationContext, myNodeManager)); } else if (location != null) { StaticDescriptorImpl staticDecriptor = myNodeManager.getStaticDescriptor(myDescriptor, location.declaringType()); if (staticDecriptor.isExpandable()) { children.addTopGroup( new JavaStaticGroup(staticDecriptor, evaluationContext, myNodeManager)); } } DebugProcessImpl debugProcess = debuggerContext.getDebugProcess(); if (debugProcess == null) { return; } // add last method return value if any final Pair<Method, Value> methodValuePair = debugProcess.getLastExecutedMethod(); if (methodValuePair != null) { ValueDescriptorImpl returnValueDescriptor = myNodeManager.getMethodReturnValueDescriptor( myDescriptor, methodValuePair.getFirst(), methodValuePair.getSecond()); children.add(JavaValue.create(returnValueDescriptor, evaluationContext, myNodeManager)); } // add context exceptions for (Pair<Breakpoint, Event> pair : DebuggerUtilsEx.getEventDescriptors(debuggerContext.getSuspendContext())) { final Event debugEvent = pair.getSecond(); if (debugEvent instanceof ExceptionEvent) { final ObjectReference exception = ((ExceptionEvent) debugEvent).exception(); if (exception != null) { final ValueDescriptorImpl exceptionDescriptor = myNodeManager.getThrownExceptionObjectDescriptor(myDescriptor, exception); children.add(JavaValue.create(exceptionDescriptor, evaluationContext, myNodeManager)); } } } try { buildVariables( debuggerContext, evaluationContext, debugProcess, children, thisObjectReference, location); // if (classRenderer.SORT_ASCENDING) { // Collections.sort(myChildren, NodeManagerImpl.getNodeComparator()); // } } catch (EvaluateException e) { node.setErrorMessage(e.getMessage()); // myChildren.add(myNodeManager.createMessageNode(new MessageDescriptor(e.getMessage()))); } } catch (InvalidStackFrameException e) { LOG.info(e); // myChildren.clear(); // notifyCancelled(); } catch (InternalException e) { if (e.errorCode() == 35) { node.setErrorMessage(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())); // myChildren.add( // myNodeManager.createMessageNode(new // MessageDescriptor(DebuggerBundle.message("error.corrupt.debug.info", e.getMessage())))); } else { throw e; } } }