private void runAction(final EvaluationContextImpl context, LocatableEvent event) { if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { if (LOG_ENABLED) { buf.append(getEventMessage(event)); buf.append("\n"); } final DebugProcessImpl debugProcess = context.getDebugProcess(); final TextWithImports expressionToEvaluate = getLogMessage(); if (LOG_EXPRESSION_ENABLED && expressionToEvaluate != null && !"".equals(expressionToEvaluate.getText())) { if (!debugProcess.isAttached()) { return; } try { ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction( getProject(), new EvaluatingComputable<ExpressionEvaluator>() { public ExpressionEvaluator compute() throws EvaluateException { return EvaluatorBuilderImpl.build( expressionToEvaluate, ContextUtil.getContextElement(context), ContextUtil.getSourcePosition(context)); } }); final Value eval = evaluator.evaluate(context); final String result = eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval); buf.append(result); } catch (EvaluateException e) { buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression")); buf.append(" \""); buf.append(expressionToEvaluate); buf.append("\""); buf.append(" : "); buf.append(e.getMessage()); } buf.append("\n"); } if (buf.length() > 0) { debugProcess.printToConsole(buf.toString()); } } finally { StringBuilderSpinAllocator.dispose(buf); } } }
/** updates the state of breakpoint and all the related UI widgets etc */ @Override public final void updateUI() { if (ApplicationManager.getApplication().isUnitTestMode()) { return; } final Project project = getProject(); DebuggerInvocationUtil.swingInvokeLater( project, new Runnable() { @Override public void run() { if (!isValid()) { return; } DebuggerContextImpl context = DebuggerManagerEx.getInstanceEx(project).getContext(); final DebugProcessImpl debugProcess = context.getDebugProcess(); if (debugProcess == null || !debugProcess.isAttached()) { updateCaches(null); updateGutter(); } else { debugProcess .getManagerThread() .invoke( new DebuggerCommandImpl() { @Override protected void action() throws Exception { ApplicationManager.getApplication() .runReadAction( new Runnable() { @Override public void run() { updateCaches(debugProcess); } }); DebuggerInvocationUtil.swingInvokeLater( project, new Runnable() { @Override public void run() { updateGutter(); } }); } }); } } }); }
protected void createBreakpointInHelloWorld() { DebuggerInvocationUtil.invokeAndWait( myProject, () -> { BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager(); PsiClass psiClass = JavaPsiFacade.getInstance(myProject) .findClass("HelloWorld", GlobalSearchScope.allScope(myProject)); assertNotNull(psiClass); Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()); breakpointManager.addLineBreakpoint(document, 3); }, ApplicationManager.getApplication().getDefaultModalityState()); }
/** called by BreakpointManager when destroying the breakpoint */ @Override public void delete() { if (isVisible()) { final RangeHighlighter highlighter = getHighlighter(); if (highlighter != null) { DebuggerInvocationUtil.invokeLater( getProject(), new Runnable() { @Override public void run() { highlighter.dispose(); // we should delete it here, so gutter will not fire events to deleted breakpoint BreakpointWithHighlighter.super.delete(); } }); } } }