/**
  * Resolves the {@link IBreakpoint} from the given editor and ruler information. Returns <code>
  * null</code> if no breakpoint exists or the operation fails.
  *
  * @param editor the editor
  * @param info the current ruler information
  * @return the {@link IBreakpoint} from the current editor position or <code>null</code>
  */
 protected IBreakpoint getBreakpointFromEditor(ITextEditor editor, IVerticalRulerInfo info) {
   IAnnotationModel annotationModel =
       editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
   IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
   if (annotationModel != null) {
     @SuppressWarnings("unchecked")
     Iterator<Annotation> iterator = annotationModel.getAnnotationIterator();
     while (iterator.hasNext()) {
       Object object = iterator.next();
       if (object instanceof SimpleMarkerAnnotation) {
         SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object;
         IMarker marker = markerAnnotation.getMarker();
         try {
           if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) {
             Position position = annotationModel.getPosition(markerAnnotation);
             int line = document.getLineOfOffset(position.getOffset());
             if (line == info.getLineOfLastMouseButtonActivity()) {
               IBreakpoint breakpoint =
                   DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
               if (breakpoint != null) {
                 return breakpoint;
               }
             }
           }
         } catch (CoreException e) {
         } catch (BadLocationException e) {
         }
       }
     }
   }
   return null;
 }
 private Annotation findAnnotation(IMarker marker) {
   for (Iterator<Annotation> it = getAnnotationIterator(false); it.hasNext(); ) {
     SimpleMarkerAnnotation a = (SimpleMarkerAnnotation) it.next();
     if (a.getMarker().equals(marker)) {
       return a;
     }
   }
   return null;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result =
       prime * result + ((markerAnnotation == null) ? 0 : markerAnnotation.getText().hashCode());
   return result;
 }
 private static void collectMarkerProposals(
     SimpleMarkerAnnotation annotation, Collection<IDartCompletionProposal> proposals) {
   IMarker marker = annotation.getMarker();
   IMarkerResolution[] res = IDE.getMarkerHelpRegistry().getResolutions(marker);
   if (res.length > 0) {
     for (int i = 0; i < res.length; i++) {
       proposals.add(new MarkerResolutionProposal(res[i], marker));
     }
   }
 }
 /*
  * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
  */
 @Override
 public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
   Annotation a = findAnnotation(breakpoint.getMarker());
   if (a != null) {
     if (a instanceof SimpleMarkerAnnotation) {
       ((SimpleMarkerAnnotation) a).update();
     }
     synchronized (getLockObject()) {
       getAnnotationModelEvent().annotationChanged(a);
     }
     fireModelChanged();
   } else {
     addBreakpointAnnotation(breakpoint, true);
   }
 }
    private void populateDataModelForAnnotation(SimpleMarkerAnnotation annotation) {
      // grab the local resolutions first
      IMarker marker = annotation.getMarker();
      if (!fResMap.containsKey(marker)) {
        ArrayList<IMarkerResolution> resolutions = new ArrayList<>(5);
        IMarkerResolution[] localResolutions = fGenerator.getResolutions(marker);
        resolutions.addAll(Arrays.asList(localResolutions));

        // grab the contributed resolutions
        IMarkerResolution[] contributedResolutions =
            IDE.getMarkerHelpRegistry().getResolutions(marker);
        for (int i = 0; i < contributedResolutions.length; i++) {
          IMarkerResolution resolution = contributedResolutions[i];
          // only add contributed marker resolutions if they don't come from PDE
          if (!(resolution instanceof AbstractPDEMarkerResolution)
              && !resolutions.contains(contributedResolutions[i]))
            resolutions.add(contributedResolutions[i]);
        }
        if (resolutions.size() > 0) {
          fResMap.put(marker, resolutions.toArray(new IMarkerResolution[resolutions.size()]));
        }
      }
    }
    @Override
    public ICompletionProposal[] computeQuickAssistProposals(
        IQuickAssistInvocationContext invocationContext) {
      IAnnotationModel amodel = invocationContext.getSourceViewer().getAnnotationModel();
      IDocument doc = invocationContext.getSourceViewer().getDocument();

      int offset = invocationContext.getOffset();
      Iterator<?> it = amodel.getAnnotationIterator();
      TreeSet<ICompletionProposal> proposalSet =
          new TreeSet<>(
              new Comparator<Object>() {

                @Override
                public int compare(Object o1, Object o2) {
                  if (o1 instanceof ICompletionProposal && o2 instanceof ICompletionProposal) {
                    ICompletionProposal proposal1 = (ICompletionProposal) o1;
                    ICompletionProposal proposal2 = (ICompletionProposal) o2;
                    return proposal1
                        .getDisplayString()
                        .compareToIgnoreCase(proposal2.getDisplayString());
                  }
                  return 0;
                }
              });
      while (it.hasNext()) {
        Object key = it.next();
        if (!(key instanceof SimpleMarkerAnnotation)) {
          if (key instanceof SpellingAnnotation) {
            SpellingAnnotation annotation = (SpellingAnnotation) key;
            if (amodel.getPosition(annotation).overlapsWith(offset, 1)) {
              ICompletionProposal[] proposals = annotation.getSpellingProblem().getProposals();
              for (ICompletionProposal proposal : proposals) {
                proposalSet.add(proposal);
              }
            }
          }
          continue;
        }

        SimpleMarkerAnnotation annotation = (SimpleMarkerAnnotation) key;
        populateDataModelForAnnotation(annotation);
        IMarker marker = annotation.getMarker();

        IMarkerResolution[] mapping = fResMap.get(marker);
        if (mapping != null) {
          Position pos = amodel.getPosition(annotation);
          try {
            int line = doc.getLineOfOffset(pos.getOffset());
            int start = pos.getOffset();
            String delim = doc.getLineDelimiter(line);
            int delimLength = delim != null ? delim.length() : 0;
            int end = doc.getLineLength(line) + start - delimLength;
            if (offset >= start && offset <= end) {
              for (IMarkerResolution markerResolution : mapping) {
                PDECompletionProposal proposal =
                    new PDECompletionProposal(markerResolution, pos, marker);
                if (!proposalSet.contains(proposal)) {
                  proposalSet.add(proposal);
                }
              }
            }
          } catch (BadLocationException e) {
          }
        }
      }

      return proposalSet.toArray(new ICompletionProposal[proposalSet.size()]);
    }