public static int collectQuickFixableAnnotations(
      ITextEditor editor,
      int invocationLocation,
      boolean goToClosest,
      ArrayList resultingAnnotations)
      throws BadLocationException {
    IAnnotationModel model =
        JavaScriptUI.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
    if (model == null) {
      return invocationLocation;
    }

    ensureUpdatedAnnotations(editor);

    Iterator iter = model.getAnnotationIterator();
    if (goToClosest) {
      IRegion lineInfo = getRegionOfInterest(editor, invocationLocation);
      if (lineInfo == null) {
        return invocationLocation;
      }
      int rangeStart = lineInfo.getOffset();
      int rangeEnd = rangeStart + lineInfo.getLength();

      ArrayList allAnnotations = new ArrayList();
      ArrayList allPositions = new ArrayList();
      int bestOffset = Integer.MAX_VALUE;
      while (iter.hasNext()) {
        Annotation annot = (Annotation) iter.next();
        if (JavaCorrectionProcessor.isQuickFixableType(annot)) {
          Position pos = model.getPosition(annot);
          if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) { // inside our range?
            allAnnotations.add(annot);
            allPositions.add(pos);
            bestOffset = processAnnotation(annot, pos, invocationLocation, bestOffset);
          }
        }
      }
      if (bestOffset == Integer.MAX_VALUE) {
        return invocationLocation;
      }
      for (int i = 0; i < allPositions.size(); i++) {
        Position pos = (Position) allPositions.get(i);
        if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) {
          resultingAnnotations.add(allAnnotations.get(i));
        }
      }
      return bestOffset;
    } else {
      while (iter.hasNext()) {
        Annotation annot = (Annotation) iter.next();
        if (JavaCorrectionProcessor.isQuickFixableType(annot)) {
          Position pos = model.getPosition(annot);
          if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) {
            resultingAnnotations.add(annot);
          }
        }
      }
      return invocationLocation;
    }
  }
 private ICompletionProposal findCorrection(
     String id,
     boolean isAssist,
     ITextSelection selection,
     ICompilationUnit cu,
     IAnnotationModel model) {
   AssistContext context =
       new AssistContext(
           cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength());
   Collection<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(10);
   if (isAssist) {
     if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) {
       return getLocalRenameProposal(context); // shortcut for local rename
     }
     JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals);
   } else {
     try {
       boolean goToClosest = selection.getLength() == 0;
       Annotation[] annotations = getAnnotations(selection.getOffset(), goToClosest);
       JavaCorrectionProcessor.collectProposals(
           context, model, annotations, true, false, proposals);
     } catch (BadLocationException e) {
       return null;
     }
   }
   for (Iterator<IJavaCompletionProposal> iter = proposals.iterator(); iter.hasNext(); ) {
     Object curr = iter.next();
     if (curr instanceof ICommandAccess) {
       if (id.equals(((ICommandAccess) curr).getCommandId())) {
         return (ICompletionProposal) curr;
       }
     }
   }
   return null;
 }
 private static int processAnnotation(
     Annotation annot, Position pos, int invocationLocation, int bestOffset) {
   int posBegin = pos.offset;
   int posEnd = posBegin + pos.length;
   if (isInside(invocationLocation, posBegin, posEnd)) { // covers invocation location?
     return invocationLocation;
   } else if (bestOffset != invocationLocation) {
     int newClosestPosition = computeBestOffset(posBegin, invocationLocation, bestOffset);
     if (newClosestPosition != -1) {
       if (newClosestPosition != bestOffset) { // new best
         if (JavaCorrectionProcessor.hasCorrections(
             annot)) { // only jump to it if there are proposals
           return newClosestPosition;
         }
       }
     }
   }
   return bestOffset;
 }