Search in sources :

Example 1 with XBreakpoint

use of com.intellij.xdebugger.breakpoints.XBreakpoint in project intellij-community by JetBrains.

the class JavaExceptionBreakpointType method addBreakpoint.

//public Key<ExceptionBreakpoint> getBreakpointCategory() {
//  return ExceptionBreakpoint.CATEGORY;
//}
@Nullable
@Override
public XBreakpoint<JavaExceptionBreakpointProperties> addBreakpoint(final Project project, JComponent parentComponent) {
    final PsiClass throwableClass = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_THROWABLE, GlobalSearchScope.allScope(project));
    TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser(DebuggerBundle.message("add.exception.breakpoint.classchooser.title"), GlobalSearchScope.allScope(project), throwableClass, true, true, null);
    chooser.showDialog();
    final PsiClass selectedClass = chooser.getSelected();
    final String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass);
    if (qName != null && qName.length() > 0) {
        return ApplicationManager.getApplication().runWriteAction(new Computable<XBreakpoint<JavaExceptionBreakpointProperties>>() {

            @Override
            public XBreakpoint<JavaExceptionBreakpointProperties> compute() {
                return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint(JavaExceptionBreakpointType.this, new JavaExceptionBreakpointProperties(qName, ((PsiClassOwner) selectedClass.getContainingFile()).getPackageName()));
            }
        });
    }
    return null;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) JavaExceptionBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with XBreakpoint

use of com.intellij.xdebugger.breakpoints.XBreakpoint in project intellij-community by JetBrains.

the class XBreakpointGroupingByClassRule method getGroup.

@Override
public XBreakpointClassGroup getGroup(@NotNull B b, @NotNull Collection<XBreakpointClassGroup> groups) {
    if (b instanceof XBreakpoint) {
        Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint((XBreakpoint) b);
        if (javaBreakpoint == null) {
            return null;
        }
        String className = javaBreakpoint.getShortClassName();
        String packageName = javaBreakpoint.getPackageName();
        if (className == null) {
            return null;
        }
        for (XBreakpointClassGroup group : groups) {
            if (group.getClassName().equals(className) && group.getPackageName().equals(packageName)) {
                return group;
            }
        }
        return new XBreakpointClassGroup(packageName, className);
    }
    return null;
}
Also used : Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint)

Example 3 with XBreakpoint

use of com.intellij.xdebugger.breakpoints.XBreakpoint in project intellij-community by JetBrains.

the class DebuggerUIUtil method showXBreakpointEditorBalloon.

public static void showXBreakpointEditorBalloon(final Project project, @Nullable final Point point, final JComponent component, final boolean showAllOptions, final XBreakpoint breakpoint) {
    final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
    final XLightBreakpointPropertiesPanel propertiesPanel = new XLightBreakpointPropertiesPanel(project, breakpointManager, (XBreakpointBase) breakpoint, showAllOptions);
    final Ref<Balloon> balloonRef = Ref.create(null);
    final Ref<Boolean> isLoading = Ref.create(Boolean.FALSE);
    final Ref<Boolean> moreOptionsRequested = Ref.create(Boolean.FALSE);
    propertiesPanel.setDelegate(() -> {
        if (!isLoading.get()) {
            propertiesPanel.saveProperties();
        }
        if (!balloonRef.isNull()) {
            balloonRef.get().hide();
        }
        showXBreakpointEditorBalloon(project, point, component, true, breakpoint);
        moreOptionsRequested.set(true);
    });
    isLoading.set(Boolean.TRUE);
    propertiesPanel.loadProperties();
    isLoading.set(Boolean.FALSE);
    if (moreOptionsRequested.get()) {
        return;
    }
    Runnable showMoreOptions = () -> {
        propertiesPanel.saveProperties();
        propertiesPanel.dispose();
        BreakpointsDialogFactory.getInstance(project).showDialog(breakpoint);
    };
    final JComponent mainPanel = propertiesPanel.getMainPanel();
    final Balloon balloon = showBreakpointEditor(project, mainPanel, point, component, showMoreOptions, breakpoint);
    balloonRef.set(balloon);
    final XBreakpointListener<XBreakpoint<?>> breakpointListener = new XBreakpointAdapter<XBreakpoint<?>>() {

        @Override
        public void breakpointRemoved(@NotNull XBreakpoint<?> removedBreakpoint) {
            if (removedBreakpoint.equals(breakpoint)) {
                balloon.hide();
            }
        }
    };
    balloon.addListener(new JBPopupListener.Adapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            propertiesPanel.saveProperties();
            propertiesPanel.dispose();
            breakpointManager.removeBreakpointListener(breakpointListener);
        }
    });
    breakpointManager.addBreakpointListener(breakpointListener);
    ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.findInstance().requestFocus(mainPanel, true));
}
Also used : XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XLightBreakpointPropertiesPanel(com.intellij.xdebugger.impl.breakpoints.ui.XLightBreakpointPropertiesPanel) NotNull(org.jetbrains.annotations.NotNull) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) XBreakpointAdapter(com.intellij.xdebugger.breakpoints.XBreakpointAdapter)

Example 4 with XBreakpoint

use of com.intellij.xdebugger.breakpoints.XBreakpoint in project intellij-community by JetBrains.

the class XBreakpointManagerTest method testSerialize.

public void testSerialize() {
    XLineBreakpoint<MyBreakpointProperties> breakpoint = addLineBreakpoint(myBreakpointManager, "myurl", 239, new MyBreakpointProperties("z1"));
    breakpoint.setCondition("cond");
    breakpoint.setLogExpression("log");
    breakpoint.setSuspendPolicy(SuspendPolicy.NONE);
    breakpoint.setLogMessage(true);
    addBreakpoint(myBreakpointManager, new MyBreakpointProperties("z2"));
    reload();
    List<XBreakpoint<?>> breakpoints = getAllBreakpoints();
    assertEquals("Expected 3 breakpoints, actual: " + breakpoints, 3, breakpoints.size());
    assertTrue(myBreakpointManager.isDefaultBreakpoint(breakpoints.get(0)));
    assertEquals("default", assertInstanceOf(breakpoints.get(0).getProperties(), MyBreakpointProperties.class).myOption);
    assertTrue(breakpoints.get(0).isEnabled());
    XLineBreakpoint lineBreakpoint = assertInstanceOf(breakpoints.get(1), XLineBreakpoint.class);
    assertEquals(239, lineBreakpoint.getLine());
    assertEquals("myurl", lineBreakpoint.getFileUrl());
    assertEquals("z1", assertInstanceOf(lineBreakpoint.getProperties(), MyBreakpointProperties.class).myOption);
    assertEquals("cond", lineBreakpoint.getCondition());
    assertEquals("log", lineBreakpoint.getLogExpression());
    assertTrue(lineBreakpoint.isLogMessage());
    assertEquals(SuspendPolicy.NONE, lineBreakpoint.getSuspendPolicy());
    assertEquals("z2", assertInstanceOf(breakpoints.get(2).getProperties(), MyBreakpointProperties.class).myOption);
    assertEquals(SuspendPolicy.ALL, breakpoints.get(2).getSuspendPolicy());
    assertFalse(breakpoints.get(2).isLogMessage());
}
Also used : XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 5 with XBreakpoint

use of com.intellij.xdebugger.breakpoints.XBreakpoint in project intellij-community by JetBrains.

the class DebugProcessEvents method processLocatableEvent.

private void processLocatableEvent(final SuspendContextImpl suspendContext, final LocatableEvent event) {
    ThreadReference thread = event.thread();
    //LOG.assertTrue(thread.isSuspended());
    preprocessEvent(suspendContext, thread);
    //we use schedule to allow processing other events during processing this one
    //this is especially necessary if a method is breakpoint condition
    getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {

        @Override
        public void contextAction() throws Exception {
            final SuspendManager suspendManager = getSuspendManager();
            SuspendContextImpl evaluatingContext = SuspendManagerUtil.getEvaluatingContext(suspendManager, suspendContext.getThread());
            if (evaluatingContext != null && !DebuggerSession.enableBreakpointsDuringEvaluation()) {
                // is inside evaluation, so ignore any breakpoints
                suspendManager.voteResume(suspendContext);
                return;
            }
            final LocatableEventRequestor requestor = (LocatableEventRequestor) getRequestsManager().findRequestor(event.request());
            boolean resumePreferred = requestor != null && DebuggerSettings.SUSPEND_NONE.equals(requestor.getSuspendPolicy());
            boolean requestHit;
            try {
                requestHit = (requestor != null) && requestor.processLocatableEvent(this, event);
            } catch (final LocatableEventRequestor.EventProcessingException ex) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(ex.getMessage());
                }
                final boolean[] considerRequestHit = new boolean[] { true };
                DebuggerInvocationUtil.invokeAndWait(getProject(), () -> {
                    final String displayName = requestor instanceof Breakpoint ? ((Breakpoint) requestor).getDisplayName() : requestor.getClass().getSimpleName();
                    final String message = DebuggerBundle.message("error.evaluating.breakpoint.condition.or.action", displayName, ex.getMessage());
                    considerRequestHit[0] = Messages.showYesNoDialog(getProject(), message, ex.getTitle(), Messages.getQuestionIcon()) == Messages.YES;
                }, ModalityState.NON_MODAL);
                requestHit = considerRequestHit[0];
                resumePreferred = !requestHit;
            }
            if (requestHit && requestor instanceof Breakpoint) {
                // if requestor is a breakpoint and this breakpoint was hit, no matter its suspend policy
                ApplicationManager.getApplication().runReadAction(() -> {
                    XDebugSession session = getSession().getXDebugSession();
                    if (session != null) {
                        XBreakpoint breakpoint = ((Breakpoint) requestor).getXBreakpoint();
                        if (breakpoint != null) {
                            ((XDebugSessionImpl) session).processDependencies(breakpoint);
                        }
                    }
                });
            }
            if (!requestHit || resumePreferred) {
                suspendManager.voteResume(suspendContext);
            } else {
                if (myReturnValueWatcher != null) {
                    myReturnValueWatcher.disable();
                }
                //if (suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_ALL) {
                //  // there could be explicit resume as a result of call to voteSuspend()
                //  // e.g. when breakpoint was considered invalid, in that case the filter will be applied _after_
                //  // resuming and all breakpoints in other threads will be ignored.
                //  // As resume() implicitly cleares the filter, the filter must be always applied _before_ any resume() action happens
                //  myBreakpointManager.applyThreadFilter(DebugProcessEvents.this, event.thread());
                //}
                suspendManager.voteSuspend(suspendContext);
                showStatusText(DebugProcessEvents.this, event);
            }
        }
    });
}
Also used : StackCapturingLineBreakpoint(com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) XDebugSession(com.intellij.xdebugger.XDebugSession) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) ThreadReference(com.sun.jdi.ThreadReference) LocatableEventRequestor(com.intellij.debugger.engine.requests.LocatableEventRequestor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) InternalException(com.sun.jdi.InternalException)

Aggregations

XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)11 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)2 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)2 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)1 LocatableEventRequestor (com.intellij.debugger.engine.requests.LocatableEventRequestor)1 StackCapturingLineBreakpoint (com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint)1 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 PsiClass (com.intellij.psi.PsiClass)1 SmartList (com.intellij.util.SmartList)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 XBreakpointAdapter (com.intellij.xdebugger.breakpoints.XBreakpointAdapter)1 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)1 XBreakpointType (com.intellij.xdebugger.breakpoints.XBreakpointType)1 XBreakpointBase (com.intellij.xdebugger.impl.breakpoints.XBreakpointBase)1 XLightBreakpointPropertiesPanel (com.intellij.xdebugger.impl.breakpoints.ui.XLightBreakpointPropertiesPanel)1 PyClass (com.jetbrains.python.psi.PyClass)1 InternalException (com.sun.jdi.InternalException)1 ThreadReference (com.sun.jdi.ThreadReference)1