/**
   * @param resource may be the file open in the editor or the workspace root (if it is an external
   *     file)
   * @param document is the document opened in the editor
   * @param externalFileEditorInput is not-null if this is an external file
   * @param info is the vertical ruler info (only used if this is not an external file)
   * @param onlyIncludeLastLineActivity if only the markers that are in the last mouse-click should
   *     be included
   * @return the markers that correspond to the markers from the current editor.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static List<Tuple<IMarker, IBreakpoint>> getMarkersAndBreakpointsFromEditorResource(
      IResource resource,
      IDocument document,
      IEditorInput externalFileEditorInput,
      int lastLineActivity,
      boolean onlyIncludeLastLineActivity,
      IAnnotationModel annotationModel) {
    List<Tuple<IMarker, IBreakpoint>> breakpoints = new ArrayList<Tuple<IMarker, IBreakpoint>>();

    try {
      List<IMarker> markers = new ArrayList<IMarker>();
      boolean isExternalFile = false;

      markers.addAll(
          Arrays.asList(
              resource.findMarkers(PyBreakpoint.PY_BREAK_MARKER, true, IResource.DEPTH_INFINITE)));
      markers.addAll(
          Arrays.asList(
              resource.findMarkers(
                  PyBreakpoint.PY_CONDITIONAL_BREAK_MARKER, true, IResource.DEPTH_INFINITE)));

      if (!(resource instanceof IFile)) {
        // it was created from an external file
        isExternalFile = true;
      }

      IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
      for (IMarker marker : markers) {
        if (marker == null) {
          continue;
        }
        IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker);
        if (breakpoint != null && breakpointManager.isRegistered(breakpoint)) {
          Position pos = PyMarkerUtils.getMarkerPosition(document, marker, annotationModel);

          if (!isExternalFile) {
            if (!onlyIncludeLastLineActivity) {
              breakpoints.add(new Tuple(marker, breakpoint));
            } else if (includesRulerLine(pos, document, lastLineActivity)) {
              breakpoints.add(new Tuple(marker, breakpoint));
            }
          } else {

            if (isInSameExternalEditor(marker, externalFileEditorInput)) {
              if (!onlyIncludeLastLineActivity) {
                breakpoints.add(new Tuple(marker, breakpoint));
              } else if (includesRulerLine(pos, document, lastLineActivity)) {
                breakpoints.add(new Tuple(marker, breakpoint));
              }
            }
          }
        }
      }
    } catch (CoreException x) {
      PydevDebugPlugin.log(IStatus.ERROR, "Unexpected getMarkers error (recovered properly)", x);
    }
    return breakpoints;
  }
Beispiel #2
0
  /**
   * Adds the breakpoints associated with a container.
   *
   * @param container the container we're interested in (usually workspace root)
   */
  private void addBreakpointsFor(IContainer container) {
    try {
      IMarker[] markers =
          container.findMarkers(PyBreakpoint.PY_BREAK_MARKER, true, IResource.DEPTH_INFINITE);
      IMarker[] condMarkers =
          container.findMarkers(
              PyBreakpoint.PY_CONDITIONAL_BREAK_MARKER, true, IResource.DEPTH_INFINITE);
      IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();

      for (IMarker marker : markers) {
        PyBreakpoint brk = (PyBreakpoint) breakpointManager.getBreakpoint(marker);
        breakpointAdded(brk);
      }

      for (IMarker marker : condMarkers) {
        PyBreakpoint brk = (PyBreakpoint) breakpointManager.getBreakpoint(marker);
        breakpointAdded(brk);
      }
    } catch (Throwable t) {
      PydevDebugPlugin.errorDialog("Error setting breakpoints", t);
    }
  }
Beispiel #3
0
 protected void collectBrakePoint(IResource resource) throws CoreException {
   fBreakpoints = new BucketMap<IResource, IBreakpoint>(6);
   fBreakpointAttributes = new HashMap<IBreakpoint, Map<String, Object>>(6);
   final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
   IMarker[] markers =
       resource.findMarkers(IBreakpoint.LINE_BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
   for (IMarker marker : markers) {
     IResource markerResource = marker.getResource();
     IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker);
     if (breakpoint != null) {
       fBreakpoints.add(markerResource, breakpoint);
       fBreakpointAttributes.put(breakpoint, breakpoint.getMarker().getAttributes());
     }
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ui.texteditor.IMarkerUpdater#updateMarker(org.eclipse.core
  * .resources.IMarker, org.eclipse.jface.text.IDocument,
  * org.eclipse.jface.text.Position)
  */
 public boolean updateMarker(
     final IMarker marker, final IDocument document, final Position position) {
   if (position.isDeleted()) {
     return false;
   }
   try {
     final int line = MarkerUtilities.getLineNumber(marker);
     final int newLine = document.getLineOfOffset(position.getOffset()) + 1;
     if (line == newLine) {
       return true;
     }
     final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
     final IBreakpoint breakpoint = manager.getBreakpoint(marker);
     if (breakpoint == null) {
       return false;
     }
     if (breakpoint instanceof ErlangLineBreakpoint) {
       final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) breakpoint;
       final ErlangDebugTarget target = erlangLineBreakpoint.getTarget();
       erlangLineBreakpoint.remove(target);
       MarkerUtilities.setLineNumber(marker, newLine);
       erlangLineBreakpoint.install(target);
       return true;
     }
     // if there exists a breakpoint on the line remove this one
     if (isLineBreakpointMarker(marker)) {
       ensureRanges(document, marker, line);
       return lineBreakpointExists(marker.getResource(), line, marker) == null;
     }
     // if the line info is a valid location with an invalid line
     // number,
     // a line breakpoint must be removed
     if (isLineBreakpointMarker(marker) && line == -1) {
       return false;
     }
     MarkerUtilities.setLineNumber(marker, line);
     if (isLineBreakpointMarker(marker)) {
       ensureRanges(document, marker, line);
     }
     return true;
   } catch (final BadLocationException e) {
     ErlLogger.error(e);
   } catch (final CoreException e) {
     ErlLogger.error(e);
   }
   return false;
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.action.IAction#run()
  */
 public void run() {
   try {
     /*
      * Test if there are any markers at the current position.
      * if there are any, remove breakpointmarker, otherwise create a
      * new one.
      */
     List list = getMarkers();
     if (list.isEmpty()) {
       // create new markers
       IDocument document = getDocument();
       int lineNumber = getVerticalRulerInfo().getLineOfLastMouseButtonActivity();
       if (lineNumber >= document.getNumberOfLines()) {
         return;
       }
       try {
         IRegion line = document.getLineInformation(lineNumber);
         ITextSelection selection =
             new TextSelection(document, line.getOffset(), line.getLength());
         // fBreakpointAdapter.toggleLineBreakpoints(fTextEditor, selection);
         fBreakpointAdapter.toggleBreakpoints(fTextEditor, selection);
       } catch (BadLocationException e) {
         // likely document is folded so you cannot get the line information of the folded line
       }
     } else {
       // remove existing breakpoints of any type
       IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
       Iterator iterator = list.iterator();
       while (iterator.hasNext()) {
         IMarker marker = (IMarker) iterator.next();
         IBreakpoint breakpoint = manager.getBreakpoint(marker);
         if (breakpoint != null) {
           breakpoint.delete();
         }
       }
     }
   } catch (CoreException e) {
     // JDIDebugUIPlugin.errorDialog(ActionMessages.getString("ManageBreakpointRulerAction.error.adding.message1"), e); //$NON-NLS-1$
     // JDIDebugUIPlugin.errorDialog(ActionMessages.ManageBreakpointRulerAction_error_adding_message1, e);
     // This message may not make sense FIXME
     JDIDebugUIPlugin.errorDialog(
         ActionMessages.ManageMethodBreakpointActionDelegate_methodNonAvailable, e);
   }
 }
  /**
   * Returns a list of markers that exist at the current ruler location.
   *
   * @return a list of markers that exist at the current ruler location
   */
  protected List getMarkers() {

    List breakpoints = new ArrayList();

    IResource resource = getResource();
    IDocument document = getDocument();
    AbstractMarkerAnnotationModel model = getAnnotationModel();

    if (model != null) {
      try {

        IMarker[] markers = null;
        if (resource instanceof IFile)
          markers =
              resource.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
        else {
          IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
          markers = root.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
        }

        if (markers != null) {
          IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
          for (int i = 0; i < markers.length; i++) {
            IBreakpoint breakpoint = breakpointManager.getBreakpoint(markers[i]);
            if (breakpoint != null
                && breakpointManager.isRegistered(breakpoint)
                && includesRulerLine(model.getMarkerPosition(markers[i]), document))
              breakpoints.add(markers[i]);
          }
        }
      } catch (CoreException x) {
        JDIDebugUIPlugin.log(x.getStatus());
      }
    }
    return breakpoints;
  }
 /* (non-Javadoc)
  * @see org.eclipse.ui.texteditor.IMarkerUpdater#updateMarker(org.eclipse.core.resources.IMarker, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position)
  */
 public boolean updateMarker(IMarker marker, IDocument document, Position position) {
   if (position.isDeleted()) {
     return false;
   }
   IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
   IBreakpoint breakpoint = manager.getBreakpoint(marker);
   if (breakpoint == null) {
     return false;
   }
   IFile file = (IFile) marker.getResource();
   if (JavaScriptCore.isJavaScriptLikeFileName(file.getName())) {
     IJavaScriptUnit unit = JavaScriptCore.createCompilationUnitFrom(file);
     if (unit == null) {
       return false;
     }
     JavaScriptUnit jsunit =
         JavaScriptPlugin.getDefault().getASTProvider().getAST(unit, ASTProvider.WAIT_YES, null);
     try {
       BreakpointLocationFinder finder =
           new BreakpointLocationFinder(
               jsunit, document.getLineOfOffset(position.getOffset()) + 1, true);
       jsunit.accept(finder);
       if (finder.getLocation() == BreakpointLocationFinder.UNKNOWN) {
         return false;
       }
       int line = finder.getLineNumber();
       if (MarkerUtilities.getLineNumber(marker) == line) {
         // if there exists a breakpoint on the line remove this one
         if (isLineBreakpoint(marker)) {
           ensureRanges(document, marker, line);
           return lineBreakpointExists(
                   marker.getResource(),
                   ((IJavaScriptLineBreakpoint) breakpoint).getScriptPath(),
                   line,
                   marker,
                   true)
               == null;
         }
         return true;
       }
       if (isLineBreakpoint(marker) & line == -1) {
         return false;
       }
       if (lineBreakpointExists(
               marker.getResource(),
               ((IJavaScriptLineBreakpoint) breakpoint).getScriptPath(),
               line,
               marker,
               false)
           != null) {
         return false;
       }
       MarkerUtilities.setLineNumber(marker, line);
       if (isLineBreakpoint(marker)) {
         ensureRanges(document, marker, line);
       }
       return true;
     } catch (BadLocationException ble) {
       JavaScriptDebugUIPlugin.log(ble);
     } catch (CoreException e) {
       JavaScriptDebugUIPlugin.log(e);
     }
   }
   return true;
 }