@Nullable
 private static DebugProcessImpl getCurrentDebugProcess(@Nullable Project project) {
   if (project != null) {
     XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
     if (session != null) {
       XDebugProcess process = session.getDebugProcess();
       if (process instanceof JavaDebugProcess) {
         return ((JavaDebugProcess) process).getDebuggerSession().getProcess();
       }
     }
   }
   return null;
 }
  protected JavaDebugProcess(
      @NotNull final XDebugSession session, final DebuggerSession javaSession) {
    super(session);
    myJavaSession = javaSession;
    myEditorsProvider = new JavaDebuggerEditorsProvider();
    final DebugProcessImpl process = javaSession.getProcess();

    List<XBreakpointHandler> handlers = new ArrayList<XBreakpointHandler>();
    handlers.add(new JavaBreakpointHandler.JavaLineBreakpointHandler(process));
    handlers.add(new JavaBreakpointHandler.JavaExceptionBreakpointHandler(process));
    handlers.add(new JavaBreakpointHandler.JavaFieldBreakpointHandler(process));
    handlers.add(new JavaBreakpointHandler.JavaMethodBreakpointHandler(process));
    handlers.add(new JavaBreakpointHandler.JavaWildcardBreakpointHandler(process));

    for (JavaBreakpointHandlerFactory factory :
        Extensions.getExtensions(JavaBreakpointHandlerFactory.EP_NAME)) {
      handlers.add(factory.createHandler(process));
    }

    myBreakpointHandlers = handlers.toArray(new XBreakpointHandler[handlers.size()]);

    myJavaSession
        .getContextManager()
        .addListener(
            new DebuggerContextListener() {
              @Override
              public void changeEvent(
                  @NotNull final DebuggerContextImpl newContext, DebuggerSession.Event event) {
                if (event == DebuggerSession.Event.PAUSE
                    || event == DebuggerSession.Event.CONTEXT
                    || event == DebuggerSession.Event.REFRESH && myJavaSession.isPaused()) {
                  final SuspendContextImpl newSuspendContext = newContext.getSuspendContext();
                  if (newSuspendContext != null && shouldApplyContext(newContext)) {
                    process
                        .getManagerThread()
                        .schedule(
                            new SuspendContextCommandImpl(newSuspendContext) {
                              @Override
                              public void contextAction() throws Exception {
                                newSuspendContext.initExecutionStacks(newContext.getThreadProxy());

                                List<Pair<Breakpoint, Event>> descriptors =
                                    DebuggerUtilsEx.getEventDescriptors(newSuspendContext);
                                if (!descriptors.isEmpty()) {
                                  Breakpoint breakpoint = descriptors.get(0).getFirst();
                                  XBreakpoint xBreakpoint = breakpoint.getXBreakpoint();
                                  if (xBreakpoint != null) {
                                    ((XDebugSessionImpl) getSession())
                                        .breakpointReachedNoProcessing(
                                            xBreakpoint, newSuspendContext);
                                    unsetPausedIfNeeded(newContext);
                                    return;
                                  }
                                }
                                getSession().positionReached(newSuspendContext);
                                unsetPausedIfNeeded(newContext);
                              }
                            });
                  }
                } else if (event == DebuggerSession.Event.ATTACHED) {
                  getSession().rebuildViews(); // to refresh variables views message
                }
              }
            });

    myNodeManager =
        new NodeManagerImpl(session.getProject(), null) {
          @Override
          public DebuggerTreeNodeImpl createNode(
              final NodeDescriptor descriptor, EvaluationContext evaluationContext) {
            return new DebuggerTreeNodeImpl(null, descriptor);
          }

          @Override
          public DebuggerTreeNodeImpl createMessageNode(MessageDescriptor descriptor) {
            return new DebuggerTreeNodeImpl(null, descriptor);
          }

          @Override
          public DebuggerTreeNodeImpl createMessageNode(String message) {
            return new DebuggerTreeNodeImpl(null, new MessageDescriptor(message));
          }
        };
    session.addSessionListener(
        new XDebugSessionAdapter() {
          @Override
          public void sessionPaused() {
            saveNodeHistory();
            showAlternativeNotification(session.getCurrentStackFrame());
          }

          @Override
          public void stackFrameChanged() {
            XStackFrame frame = session.getCurrentStackFrame();
            if (frame instanceof JavaStackFrame) {
              showAlternativeNotification(frame);
              StackFrameProxyImpl frameProxy = ((JavaStackFrame) frame).getStackFrameProxy();
              DebuggerContextUtil.setStackFrame(javaSession.getContextManager(), frameProxy);
              saveNodeHistory(frameProxy);
            }
          }

          private void showAlternativeNotification(@Nullable XStackFrame frame) {
            if (frame != null) {
              XSourcePosition position = frame.getSourcePosition();
              if (position != null) {
                VirtualFile file = position.getFile();
                if (!AlternativeSourceNotificationProvider.fileProcessed(file)) {
                  EditorNotifications.getInstance(session.getProject()).updateNotifications(file);
                }
              }
            }
          }
        });
  }