Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.ReplaceEdit


            if (matcher.find()) {
                TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
                MultiTextEdit mte = new MultiTextEdit();
                change.setEdit(mte);
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), toReplace.length(), replaceWith);
                mte.addChild(replace);
                changes.add(change);
                refactoringContent.updateContent(drlFile, content.replace(toReplace, replaceWith));
            }
        }
View Full Code Here


  }

  private static TextEdit shifEdit(TextEdit oldEdit, int diff) {
    TextEdit newEdit;
    if (oldEdit instanceof ReplaceEdit) {
      ReplaceEdit edit= (ReplaceEdit) oldEdit;
      newEdit= new ReplaceEdit(edit.getOffset() - diff, edit.getLength(), edit.getText());
    } else if (oldEdit instanceof InsertEdit) {
      InsertEdit edit= (InsertEdit) oldEdit;
      newEdit= new InsertEdit(edit.getOffset() - diff,  edit.getText());
    } else if (oldEdit instanceof DeleteEdit) {
      DeleteEdit edit= (DeleteEdit) oldEdit;
      newEdit= new DeleteEdit(edit.getOffset() - diff,  edit.getLength());
    } else if (oldEdit instanceof MultiTextEdit) {
      newEdit= new MultiTextEdit();
    } else {
      return null; // not supported
    }
View Full Code Here

        IRegion region= tracker.getLineInformation(i);
        int offset= region.getOffset();
        String line= source.substring(offset, offset + region.getLength());
        int length= indexOfIndent(line, indentUnitsToRemove, tabWidth, indentWidth);
        if (length >= 0) {
          result.add(new ReplaceEdit(offset, length, newIndentString));
        } else {
          length= measureIndentUnits(line, tabWidth, indentWidth);
          result.add(new ReplaceEdit(offset, length, "")); //$NON-NLS-1$
        }
      }
    } catch (BadLocationException cannotHappen) {
      // can not happen
    }
View Full Code Here

        for (int i = 0, max = positions.length; i < max; i++) {
          int currentPosition = positions[i];
          if (currentPosition > originalSourceLength) {
            currentPosition = originalSourceLength;
          }
          ReplaceEdit currentEdit = (ReplaceEdit) edits[editsIndex];
          while (currentEdit.getOffset() <= currentPosition) {
            delta += currentEdit.getText().length() - currentEdit.getLength();
            editsIndex++;
            if (editsIndex < textEditSize) {
              currentEdit = (ReplaceEdit) edits[editsIndex];
            } else {
              break;
View Full Code Here

  }


  private final void doTextReplace(int offset, int len, String insertString, TextEditGroup editGroup) {
    if (len > 0 || insertString.length() > 0) {
      TextEdit edit= new ReplaceEdit(offset, len, insertString);
      addEdit(edit);
      if (editGroup != null) {
        addEditGroup(editGroup, edit);
      }
    }
View Full Code Here

    final StringBuilder builder = new StringBuilder();

    // Iterate over all edits and all untouched line ends.
    while (true) {
      ReplaceEdit replaceEdit;
      int nextEditPos = -1;
      { // Find next applicable edit. This is a potential cycle if we skip some changes.
        if (editListPos < editList.length) {
          if (editList[editListPos] instanceof ReplaceEdit == false) {
            throw new RuntimeException();
          }
          replaceEdit = (ReplaceEdit) editList[editListPos];
          nextEditPos = replaceEdit.getOffset();
        } else {
          replaceEdit = null;
        }
      }

      // Choose what comes first: line end or edit.
      boolean processLineEndNotEdit;
      if (nextEditPos == -1) {
        if (nextLineEndPos == -1) {
          break;
        } else {
          processLineEndNotEdit = true;
        }
      } else {
        if (nextLineEndPos == -1) {
          processLineEndNotEdit = false;
        } else {
          processLineEndNotEdit = nextLineEndPos < nextEditPos;
        }
      }
      if (processLineEndNotEdit) {
        // Process next line end.
        builder.append(sourceString.substring(sourceStringPos, nextLineEndPos + 1));
        origPos.line++;
        origPos.col = 0;
        dstPos.line++;
        dstPos.col = 0;
        sourceStringPos = nextLineEndPos + 1;
        nextLineEndPos = sourceString.indexOf(LINE_END_CHAR, sourceStringPos);
      } else {
        // Process next edit.
        builder.append(sourceString.substring(sourceStringPos, nextEditPos));
        origPos.col += nextEditPos - sourceStringPos;
        dstPos.col += nextEditPos - sourceStringPos;

        origPos.writeToArray(intBuffer);
        dstPos.writeToArray(intBuffer);

        // Count removed line ends.
        if (replaceEdit.getLength() > 0) {
          String removedString = sourceString.substring(replaceEdit.getOffset(),
              replaceEdit.getOffset() + replaceEdit.getLength());
          origPos.advanceToString(removedString);
        }
        // Count added line ends.
        builder.append(replaceEdit.getText());
        dstPos.advanceToString(replaceEdit.getText());

        origPos.writeToArray(intBuffer);
        dstPos.writeToArray(intBuffer);

        sourceStringPos = nextEditPos + replaceEdit.getLength();
        editListPos++;

        if (nextLineEndPos != -1 && nextLineEndPos < sourceStringPos) {
          nextLineEndPos = sourceString.indexOf(LINE_END_CHAR, sourceStringPos);
        }
View Full Code Here

      this.source = source;
      this.header = header;
    }

    void run() {
      result.addChild(new ReplaceEdit(0, 0, header));

      while (position < source.length()) {
        {
          char ch = source.charAt(position);
          switch (ch) {
View Full Code Here

      }
      currentState = LastSeenState.NON_SPACE;
    }

    private void insertNewLine() {
      result.addChild(new ReplaceEdit(position, 0, spaceCache.getSpace(currentNesting * 2)));
    }
View Full Code Here

      List<CommonToken> comments = tokenStream.getTokens(0, tokenStream.size(), bs);

      final String output = format(input, (ModuleDeclaration) md, comments, indent);
      if (output != null) {
        if (!input.equals(output)) {
          return new ReplaceEdit(0, source.length(), output);
          // return new ReplaceEdit(offset, length, output);
          // if (!equalsIgnoreBlanks(new StringReader(input), new StringReader(output))) {
          // // return new MultiTextEdit();
          // return new ReplaceEdit(offset, length, output);
          // } else {
View Full Code Here

      String value= variable.getDefaultValue();
      int[] offsets= variable.getOffsets();
      // update buffer to reflect new value
      for (int k= 0; k != offsets.length; k++)
        edits.add(new ReplaceEdit(offsets[k], variable.getInitialLength(), value));

        }

      IDocument document= new Document(buffer.getString());
        MultiTextEdit edit= new MultiTextEdit(0, document.getLength());
View Full Code Here

TOP

Related Classes of org.eclipse.text.edits.ReplaceEdit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.