Esempio n. 1
0
 @Override
 public int getLength() {
   if (this.group.isEmpty()) {
     return this.node.getLength();
   }
   IRegion coverage = TextEdit.getCoverage(this.group.getTextEdits());
   if (coverage == null) {
     return this.node.getLength();
   }
   return coverage.getLength();
 }
Esempio n. 2
0
 @Override
 public int getStartPosition() {
   if (this.group.isEmpty()) {
     return this.node.getOffset();
   }
   IRegion coverage = TextEdit.getCoverage(this.group.getTextEdits());
   if (coverage == null) {
     return this.node.getOffset();
   }
   return coverage.getOffset();
 }
  private static IRegion getCorrespondingEditChangeRange(
      SearchMatch searchResult, TextChangeManager manager) {
    TextChange change = getTextChange(searchResult, manager);
    if (change == null) return null;

    IRegion oldMatchRange = createTextRange(searchResult);
    TextEditChangeGroup[] editChanges = change.getTextEditChangeGroups();
    for (int i = 0; i < editChanges.length; i++) {
      if (oldMatchRange.equals(editChanges[i].getRegion()))
        return TextEdit.getCoverage(change.getPreviewEdits(editChanges[i].getTextEdits()));
    }
    return null;
  }
  /**
   * @param change
   * @return Map &lt;Integer oldOffset, Integer updatedOffset&gt;
   */
  private static Map<Integer, Integer> getEditChangeOffsetUpdates(TextChange change) {
    TextEditChangeGroup[] editChanges = change.getTextEditChangeGroups();
    Map<Integer, Integer> offsetUpdates = new HashMap<>(editChanges.length);
    for (int i = 0; i < editChanges.length; i++) {
      TextEditChangeGroup editChange = editChanges[i];
      IRegion oldRegion = editChange.getRegion();
      if (oldRegion == null) continue;
      IRegion updatedRegion =
          TextEdit.getCoverage(change.getPreviewEdits(editChange.getTextEdits()));
      if (updatedRegion == null) continue;

      offsetUpdates.put(new Integer(oldRegion.getOffset()), new Integer(updatedRegion.getOffset()));
    }
    return offsetUpdates;
  }