private void addFoldingRegions(
     Set<Position> regions, IDocumentElementNode[] nodes, IDocument document)
     throws BadLocationException {
   for (int i = 0; i < nodes.length; i++) {
     IDocumentElementNode element = nodes[i];
     int startLine = document.getLineOfOffset(element.getOffset());
     int endLine = document.getLineOfOffset(element.getOffset() + element.getLength());
     if (startLine < endLine) {
       int start = document.getLineOffset(startLine);
       int end = document.getLineOffset(endLine) + document.getLineLength(endLine);
       Position position = new Position(start, end - start);
       regions.add(position);
       fPositionToElement.put(position, element);
     }
     IDocumentElementNode[] children = element.getChildNodes();
     if (children != null) {
       addFoldingRegions(regions, children, document);
     }
   }
 }
 void fix(IDocument document) {
   getFixes();
   if (!Common.isEmptyArray(mFixes)) {
     try {
       for (int i = 0; i < mFixes.length; i++) {
         INILine line = mFixes[i].getLine();
         if (line == null) {
           mFixes[i].setPosition(new Position(0, 0));
         } else {
           mFixes[i].setPosition(line.getParent().getChildPosition(line));
         }
       }
       Arrays.sort(mFixes, cReversePositionComparator);
       for (int i = 0; i < mFixes.length; i++) {
         Position position = mFixes[i].getPosition();
         document.replace(position.offset, position.length, mFixes[i].getText());
       }
     } catch (BadLocationException e) {
       e.printStackTrace();
     }
   }
 }
    @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()]);
    }