public void setBreakpointEnabled(@NotNull final Breakpoint breakpoint, final boolean enabled) {
   if (breakpoint.isEnabled() != enabled) {
     breakpoint.setEnabled(enabled);
     // fireBreakpointChanged(breakpoint);
     // breakpoint.updateUI();
   }
 }
  public void reloadBreakpoints() {
    ApplicationManager.getApplication().assertIsDispatchThread();

    for (Breakpoint breakpoint : getBreakpoints()) {
      breakpoint.reload();
    }
  }
 public void fireBreakpointChanged(Breakpoint breakpoint) {
   breakpoint.reload();
   breakpoint.updateUI();
   RequestManagerImpl.updateRequests(breakpoint);
   if (myAllowMulticasting) {
     // can be invoked from non-AWT thread
     myAlarm.cancelAllRequests();
     final Runnable runnable =
         new Runnable() {
           @Override
           public void run() {
             myAlarm.addRequest(
                 new Runnable() {
                   @Override
                   public void run() {
                     myDispatcher.getMulticaster().breakpointsChanged();
                   }
                 },
                 100);
           }
         };
     if (ApplicationManager.getApplication().isDispatchThread()) {
       runnable.run();
     } else {
       SwingUtilities.invokeLater(runnable);
     }
   }
 }
  private void removeInvalidBreakpoints() {
    ArrayList<Breakpoint> toDelete = new ArrayList<Breakpoint>();

    for (Breakpoint breakpoint : getBreakpoints()) {
      if (!breakpoint.isValid()) {
        toDelete.add(breakpoint);
      }
    }

    for (final Breakpoint aToDelete : toDelete) {
      removeBreakpoint(aToDelete);
    }
  }
  /**
   * @return breakpoints of one of the category: LINE_BREAKPOINTS, EXCEPTION_BREAKPOINTS,
   *     FIELD_BREAKPOINTS, METHOD_BREAKPOINTS
   */
  public <T extends Breakpoint> Breakpoint[] getBreakpoints(@NotNull final Key<T> category) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    removeInvalidBreakpoints();

    final ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
    for (Breakpoint breakpoint : getBreakpoints()) {
      if (category.equals(breakpoint.getCategory())) {
        breakpoints.add(breakpoint);
      }
    }

    return breakpoints.toArray(new Breakpoint[breakpoints.size()]);
  }
 /** @param category breakpoint category, null if the category does not matter */
 @Nullable
 public <T extends BreakpointWithHighlighter> T findBreakpoint(
     final Document document, final int offset, @Nullable final Key<T> category) {
   for (final Breakpoint breakpoint : getBreakpoints()) {
     if (breakpoint instanceof BreakpointWithHighlighter
         && ((BreakpointWithHighlighter) breakpoint).isAt(document, offset)) {
       if (category == null || category.equals(breakpoint.getCategory())) {
         //noinspection CastConflictsWithInstanceof,unchecked
         return (T) breakpoint;
       }
     }
   }
   return null;
 }
 public void enableBreakpoints(final DebugProcessImpl debugProcess) {
   final List<Breakpoint> breakpoints = getBreakpoints();
   if (!breakpoints.isEmpty()) {
     for (Breakpoint breakpoint : breakpoints) {
       breakpoint.markVerified(false); // clean cached state
       breakpoint.createRequest(debugProcess);
     }
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             updateBreakpointsUI();
           }
         });
   }
 }
 protected Icon getDisplayIcon() {
   return myBreakpoint instanceof BreakpointWithHighlighter
       ? myBreakpoint.ENABLED
           ? ((BreakpointWithHighlighter) myBreakpoint).getSetIcon(false)
           : ((BreakpointWithHighlighter) myBreakpoint).getDisabledIcon(false)
       : myBreakpoint.getIcon();
 }
  private synchronized void onBreakpointRemoved(@Nullable final XBreakpoint xBreakpoint) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (xBreakpoint == null) {
      return;
    }

    Breakpoint breakpoint = myBreakpoints.remove(xBreakpoint);
    if (breakpoint != null) {
      // updateBreakpointRules(breakpoint);
      myBreakpointsListForIteration = null;
      // we delete breakpoints inside release, so gutter will not fire events to deleted breakpoints
      breakpoint.delete();

      RequestManagerImpl.deleteRequests(breakpoint);
      myDispatcher.getMulticaster().breakpointsChanged();
    }
  }
 // interaction with RequestManagerImpl
 public void disableBreakpoints(@NotNull final DebugProcessImpl debugProcess) {
   final List<Breakpoint> breakpoints = getBreakpoints();
   if (!breakpoints.isEmpty()) {
     final RequestManagerImpl requestManager = debugProcess.getRequestsManager();
     for (Breakpoint breakpoint : breakpoints) {
       breakpoint.markVerified(requestManager.isVerified(breakpoint));
       requestManager.deleteRequest(breakpoint);
     }
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             updateBreakpointsUI();
           }
         });
   }
 }
 public boolean equals(final Object o) {
   if (this == o) {
     return true;
   }
   if (o == null || getClass() != o.getClass()) {
     return false;
   }
   final BreakpointDescriptor breakpointDescriptor = (BreakpointDescriptor) o;
   return myBreakpoint.equals(breakpointDescriptor.myBreakpoint);
 }
    public CheckedTreeNode append(CheckedTreeNode node) {
      final TreeDescriptor descriptor = getDescriptor(node);
      if (!(descriptor instanceof BreakpointDescriptor)) {
        return node;
      }

      final Breakpoint breakpoint = ((BreakpointDescriptor) descriptor).getBreakpoint();
      final String packageName;
      if (breakpoint instanceof ExceptionBreakpoint) {
        packageName = breakpoint.getPackageName();
      } else if (breakpoint instanceof BreakpointWithHighlighter) {
        packageName = breakpoint.getPackageName();
      } else {
        packageName = null;
      }
      if (packageName == null) {
        return node;
      }
      return attachNodeToParent(new PackageDescriptor(packageName), node);
    }
    public CheckedTreeNode append(CheckedTreeNode node) {
      if (!myGroupByClasses) {
        return node;
      }
      final TreeDescriptor descriptor = getDescriptor(node);
      if (!(descriptor instanceof BreakpointDescriptor)) {
        return node;
      }

      final Breakpoint breakpoint = ((BreakpointDescriptor) descriptor).getBreakpoint();
      final String className = breakpoint.getShortClassName();
      if (className == null) {
        return node;
      }
      final String packageName = breakpoint.getPackageName();
      if (packageName == null) {
        return node;
      }
      return attachNodeToParent(new ClassDescriptor(className, packageName), node);
    }
 public void addBreakpoint(final Breakpoint breakpoint) {
   myBreakpoints.add(breakpoint);
   breakpoint.updateUI(
       new Runnable() {
         public void run() {
           rebuildTree();
         }
       });
   rebuildTree();
   selectBreakpoint(breakpoint);
 }
 @SuppressWarnings({"HardCodedStringLiteral"})
 public void writeExternal(Element parentNode) throws WriteExternalException {
   super.writeExternal(parentNode);
   parentNode.setAttribute(JDOM_LABEL, "true");
   if (myClassPattern != null) {
     parentNode.setAttribute("class_name", myClassPattern);
   }
   if (myMethodName != null) {
     parentNode.setAttribute("method_name", myMethodName);
   }
 }
 // used in Fabrique
 public synchronized void addBreakpoint(@NotNull Breakpoint breakpoint) {
   myBreakpoints.put(breakpoint.myXBreakpoint, breakpoint);
   myBreakpointsListForIteration = null;
   breakpoint.updateUI();
   RequestManagerImpl.createRequests(breakpoint);
   myDispatcher.getMulticaster().breakpointsChanged();
   if (breakpoint instanceof MethodBreakpoint || breakpoint instanceof WildcardMethodBreakpoint) {
     XDebugSessionImpl.NOTIFICATION_GROUP
         .createNotification(
             "Method breakpoints may dramatically slow down debugging", MessageType.WARNING)
         .notify(myProject);
   }
 }
  @Override
  public void readExternal(@NotNull Element breakpointNode) throws InvalidDataException {
    super.readExternal(breakpointNode);
    //noinspection HardCodedStringLiteral
    // final String url = breakpointNode.getAttributeValue("url");

    //noinspection HardCodedStringLiteral
    final String className = breakpointNode.getAttributeValue("class");
    if (className != null) {
      myClassName = className;
    }

    //noinspection HardCodedStringLiteral
    final String packageName = breakpointNode.getAttributeValue("package");
    if (packageName != null) {
      myPackageName = packageName;
    }

    // VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url);
    // if (vFile == null) {
    //  throw new InvalidDataException(DebuggerBundle.message("error.breakpoint.file.not.found",
    // url));
    // }
    // final Document doc = FileDocumentManager.getInstance().getDocument(vFile);
    // if (doc == null) {
    //  throw new InvalidDataException(DebuggerBundle.message("error.cannot.load.breakpoint.file",
    // url));
    // }
    //
    //// line number
    // final int line;
    // try {
    //  //noinspection HardCodedStringLiteral
    //  line = Integer.parseInt(breakpointNode.getAttributeValue("line"));
    // }
    // catch (Exception e) {
    //  throw new InvalidDataException("Line number is invalid for breakpoint");
    // }
    // if (line < 0) {
    //  throw new InvalidDataException("Line number is invalid for breakpoint");
    // }
    //
    // RangeHighlighter highlighter = createHighlighter(myProject, doc, line);
    //
    // if (highlighter == null) {
    //  throw new InvalidDataException("");
    // }
    //
    // myHighlighter = highlighter;
    // reload();
  }
  public void readExternal(Element parentNode) throws InvalidDataException {
    super.readExternal(parentNode);

    //noinspection HardCodedStringLiteral
    String className = parentNode.getAttributeValue("class_name");
    myClassPattern = className;

    //noinspection HardCodedStringLiteral
    String methodName = parentNode.getAttributeValue("method_name");
    myMethodName = methodName;

    if (className == null || methodName == null) {
      throw new InvalidDataException();
    }
  }
 public void setBreakpointDefaults(
     Key<? extends Breakpoint> category, BreakpointDefaults defaults) {
   Class typeCls = null;
   if (LineBreakpoint.CATEGORY.toString().equals(category.toString())) {
     typeCls = JavaLineBreakpointType.class;
   } else if (MethodBreakpoint.CATEGORY.toString().equals(category.toString())) {
     typeCls = JavaMethodBreakpointType.class;
   } else if (FieldBreakpoint.CATEGORY.toString().equals(category.toString())) {
     typeCls = JavaFieldBreakpointType.class;
   } else if (ExceptionBreakpoint.CATEGORY.toString().equals(category.toString())) {
     typeCls = JavaExceptionBreakpointType.class;
   }
   if (typeCls != null) {
     XBreakpointType<XBreakpoint<?>, ?> type =
         XDebuggerUtil.getInstance().findBreakpointType(typeCls);
     ((XBreakpointManagerImpl) getXBreakpointManager())
         .getBreakpointDefaults(type)
         .setSuspendPolicy(Breakpoint.transformSuspendPolicy(defaults.getSuspendPolicy()));
   }
   // myBreakpointDefaults.put(category, defaults);
 }
  public void applyThreadFilter(
      @NotNull final DebugProcessImpl debugProcess, @Nullable ThreadReference newFilterThread) {
    final RequestManagerImpl requestManager = debugProcess.getRequestsManager();
    final ThreadReference oldFilterThread = requestManager.getFilterThread();
    if (Comparing.equal(newFilterThread, oldFilterThread)) {
      // the filter already added
      return;
    }
    requestManager.setFilterThread(newFilterThread);
    if (newFilterThread == null || oldFilterThread != null) {
      final List<Breakpoint> breakpoints = getBreakpoints();
      for (Breakpoint breakpoint : breakpoints) {
        if (LineBreakpoint.CATEGORY.equals(breakpoint.getCategory())
            || MethodBreakpoint.CATEGORY.equals(breakpoint.getCategory())) {
          requestManager.deleteRequest(breakpoint);
          breakpoint.createRequest(debugProcess);
        }
      }
    } else {
      // important! need to add filter to _existing_ requests, otherwise Requestor->Request mapping
      // will be lost
      // and debugger trees will not be restored to original state
      abstract class FilterSetter<T extends EventRequest> {
        void applyFilter(@NotNull final List<T> requests, final ThreadReference thread) {
          for (T request : requests) {
            try {
              final boolean wasEnabled = request.isEnabled();
              if (wasEnabled) {
                request.disable();
              }
              addFilter(request, thread);
              if (wasEnabled) {
                request.enable();
              }
            } catch (InternalException e) {
              LOG.info(e);
            }
          }
        }

        protected abstract void addFilter(final T request, final ThreadReference thread);
      }

      final EventRequestManager eventRequestManager = requestManager.getVMRequestManager();

      new FilterSetter<BreakpointRequest>() {
        @Override
        protected void addFilter(
            @NotNull final BreakpointRequest request, final ThreadReference thread) {
          request.addThreadFilter(thread);
        }
      }.applyFilter(eventRequestManager.breakpointRequests(), newFilterThread);

      new FilterSetter<MethodEntryRequest>() {
        @Override
        protected void addFilter(
            @NotNull final MethodEntryRequest request, final ThreadReference thread) {
          request.addThreadFilter(thread);
        }
      }.applyFilter(eventRequestManager.methodEntryRequests(), newFilterThread);

      new FilterSetter<MethodExitRequest>() {
        @Override
        protected void addFilter(
            @NotNull final MethodExitRequest request, final ThreadReference thread) {
          request.addThreadFilter(thread);
        }
      }.applyFilter(eventRequestManager.methodExitRequests(), newFilterThread);
    }
  }
 public String getDisplayString() {
   return myBreakpoint.getDisplayName();
 }
 public int hashCode() {
   return myBreakpoint.hashCode();
 }
 public void updateBreakpointsUI() {
   ApplicationManager.getApplication().assertIsDispatchThread();
   for (Breakpoint breakpoint : getBreakpoints()) {
     breakpoint.updateUI();
   }
 }