Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.ReplaceEdit


    // if not already correctly indented
    if (!newLineAndIndent.equals(whitespaceRun)) {
      if (getFormattingPreferences().getClearAllBlankLines()) {
        if (whitespaceRun != null) {
          // replace existing whitespace run
          indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), newLineAndIndent);
        }
        else {
          // just insert correct indent
          indentation = new InsertEdit(indentStartOffset, newLineAndIndent);
        }
      }
      // Keep the empty lines
      else {
        // just insert correct indent
        if(whitespaceRun == null)
          indentation = new InsertEdit(indentStartOffset, newLineAndIndent);
        // Need to preserve the number of empty lines, but still indent on the current line properly
        else {
          String existingDelimiters = extractLineDelimiters(whitespaceRun, currentRegion);
          if(existingDelimiters != null && existingDelimiters.length() > 0) {
            String formatted = existingDelimiters + indentString;
            // Don't perform a replace if the formatted string is the same as the existing whitespaceRun
            if(!formatted.equals(whitespaceRun))
              indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), formatted);
          }
          // No blank lines to preserve - correct the indent
          else
            indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), newLineAndIndent);
        }
      }
    }
   
    if(indentation != null)
View Full Code Here


  private void addReplace(MultiTextEdit mte, String descrClassName, String content, int start, int end) {
    if (className.equals(descrClassName)) {
      String text = content.substring(start-1, end+1);
      Matcher matcher = classPattern.matcher(text);
      while (matcher.find()) {
        mte.addChild(new ReplaceEdit(matcher.start() + start - 1, currentName.length(), newName));
      }
    }
  }
View Full Code Here

                // rename the field name
                Pattern pattern = Pattern.compile(FIELD_NAME.replaceAll("FIELD_NAME", currentName));
                matcher = pattern.matcher(content);
                while (matcher.find()) {
                    ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
                    mte.addChild(replace);
                }

                // search all the variables of the type to replace the getters/setters
                pattern = Pattern.compile(VARIABLE_ASSIGNED.replace("TYPE", typeName));
View Full Code Here

    }

    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

            TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
            MultiTextEdit mte = new MultiTextEdit();
            change.setEdit(mte);
            while (matcher.find()) {
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
                mte.addChild(replace);
            }
            if (change.getEdit().getChildrenSize() > 0)
                changes.add(change);
        }
View Full Code Here

            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 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

      List<CommonToken> comments = (List<CommonToken>) 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

        while (offset > -1) {
            offset = document.search(offset, variableName, true, true, true);
            if (offset == -1) {
                break;
            }
            ReplaceEdit replaceEdit = new ReplaceEdit(offset, len, replacement);
            multiEdit.addChild(replaceEdit);
            offset += len; // to avoid overlapping
        }

        if (multiEdit.getChildrenSize() > 0) {
View Full Code Here

            }
            offset = document.search(offset, variableName, true, true, true);
            if (offset == -1) {
                break;
            }
            ReplaceEdit replaceEdit = new ReplaceEdit(offset, len, replacement);
            multiEdit.addChild(replaceEdit);
            offset += len; // to avoid overlapping
        }
       
        if (multiEdit.getChildrenSize() > 0) {
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.