Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.ReplaceEdit


    }

    private void createFieldRenameChanges(MultiTextEdit mte, String content, String regexp, String currentName, String newName) {
        Pattern pattern = Pattern.compile(regexp);
        Matcher setterMatcher = pattern.matcher(content);
        ReplaceEdit replace = null;
        while (setterMatcher.find()) {
            replace = new ReplaceEdit(setterMatcher.start(), currentName.length(), newName);
            mte.addChild(replace);
        }
    }
View Full Code Here


    for (int i= 0, max = this.editsIndex; i < max; i++) {
      OptimizedReplaceEdit currentEdit = this.edits[i];
      if (currentEdit.offset >= 0 && currentEdit.offset <= this.scannerEndPosition) {
        if (currentEdit.length == 0 || (currentEdit.offset != this.scannerEndPosition && isMeaningfulEdit(currentEdit))) {
          try {
            edit.addChild(new ReplaceEdit(currentEdit.offset, currentEdit.length, currentEdit.replacement));
          }
          catch (MalformedTreeException ex) {
            // log exception in case of error
            CommentFormatterUtil.log(ex);
             throw ex;
View Full Code Here

        link = String.format("<a href=\"%s\">%s</a>", url, description); //$NON-NLS-1$
      } else {
        link = handleLinks(Arrays.asList(new TypeReference(0, 0, url)))
            .toString();
      }
      replaceLinks.add(new ReplaceEdit(m.start(), m.end() - m.start(),
          link));
    }

    for (int i = replaceLinks.size() - 1; i >= 0; i--) {
      ReplaceEdit replaceLink = replaceLinks.get(i);
      fBuf.replace(replaceLink.getOffset(), replaceLink.getOffset()
          + replaceLink.getLength(), replaceLink.getText());
    }
  }
View Full Code Here

        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

      final int start = Math.max(offset - edit.getOffset(), 0);
      final int end = Math.min(endOffset(region) - offset, replacement.length());
      if (end <= start) {
        return new DeleteEdit(offset, length);
      }
      return new ReplaceEdit(offset, length, replacement.substring(start, end));
    } else {
      throw new IllegalArgumentException("Unexpected edit type: " + edit.getClass().getSimpleName()); //$NON-NLS-1$
    }
  }
View Full Code Here

    source.apply(document, TextEdit.NONE);
    text = document.get();
    if (target.getLength() == 0) {
      return new InsertEdit(target.getOffset(), text);
    } else {
      return new ReplaceEdit(target.getOffset(), target.getLength(), text);
    }
  }
View Full Code Here

      final int endOffset = offset + fileLocation.getNodeLength();
      final String lineSeparator = writer.getScribe().getLineSeparator();
      if (code.endsWith(lineSeparator)) {
        code = code.substring(0, code.length() - lineSeparator.length());
      }
      addChildEdit(new ReplaceEdit(offset, endOffset - offset, code));
      if ((node instanceof IASTStatement) || (node instanceof IASTDeclaration)) {
        // Include trailing comments in the area to be replaced.
        final int commentEnd = getEndOffsetIncludingTrailingComments(node);
        if (commentEnd > endOffset) {
          addChildEdit(new DeleteEdit(endOffset, commentEnd - endOffset));
View Full Code Here

    final List<ASTModification> modifications = getModifications(node, ModificationKind.APPEND_CHILD);
    if (modifications.isEmpty()) {
      return;
    }
    final ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
    final ReplaceEdit anchor = getAppendAnchor(node);
    Assert.isNotNull(anchor);
    IASTNode precedingNode = getLastNodeBeforeAppendPoint(node);
    for (final ASTModification modification : modifications) {
      final IASTNode newNode = modification.getNewNode();
      if (precedingNode != null) {
        if (ASTWriter.requireBlankLineInBetween(precedingNode, newNode)) {
          writer.newLine();
        }
      } else if (node instanceof ICPPASTNamespaceDefinition) {
        writer.newLine();
      }
      precedingNode = null;
      newNode.accept(writer);
    }
    if (node instanceof ICPPASTNamespaceDefinition) {
      writer.newLine();
    }
    addToRootEdit(node);
    final String code = writer.toString();
    if (!code.isEmpty()) {
      addChildEdit(new InsertEdit(anchor.getOffset(), code));
    }
    addChildEdit(new ReplaceEdit(anchor.getOffset(), anchor.getLength(), anchor.getText()));
    processedOffset = endOffset(node);
  }
View Full Code Here

    final int len = code.endsWith("}") ? 1 : 0; //$NON-NLS-1$
    final int insertPos = code.length() - len;
    final int startOfLine = skipPrecedingBlankLines(code, insertPos);
    if (startOfLine == insertPos) {
      // Include the closing brace in the region that will be reformatted.
      return new ReplaceEdit(pos - len, len, code.substring(insertPos));
    }
    return new ReplaceEdit(location.getNodeOffset() + startOfLine, insertPos - startOfLine, ""); //$NON-NLS-1$
  }
View Full Code Here

     *
     * @param offset the offset marking the place where the replace should happen.
     * @return a TextEdit correponding to a rename.
     */
    protected TextEdit createRenameEdit(int offset) {
        return new ReplaceEdit(offset, initialName.length(), inputName);
    }
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.