Examples of ReplaceEdit


Examples of org.eclipse.text.edits.ReplaceEdit

                if (s.sourceStart() >= enclosingElementSourceStart && s.sourceEnd() <= enclosingElementSourceEnd
                    && s.getName().equals(modelElement.getElementName())
                    && s.sourceStart() != declarationSourceRange.getOffset()) {
                  IModelElement sourceElement = PDTModelUtils.getSourceElement(cu, s.sourceStart(), s.matchLength());
                  if (sourceElement != null && sourceElement.equals(modelElement)) {
                    addTextEdit(changeManager.get(cu), getProcessorName(), new ReplaceEdit(s.sourceStart(), getCurrentElementName().length(), getNewElementName()));
                  }
                }

                return true;
              }
View Full Code Here

Examples of org.eclipse.text.edits.ReplaceEdit

        if (deletedLength < addedLength) {
            result.addChild(new InsertEdit(deletedStart + minLength, getString(addedStart
                    + minLength, addedEnd)));
        }

        result.addChild(new ReplaceEdit(deletedStart, minLength, getString(addedStart,
                addedStart + minLength - 1)));

        if (addedLength < deletedLength) {
            result.addChild(new DeleteEdit(deletedStart + minLength, deletedLength
                    - minLength));
View Full Code Here

Examples of org.eclipse.text.edits.ReplaceEdit

    for(int i = 0; i < buff.length(); i++) {
      buff.setCharAt(i, ' '); //$NON-NLS-1$
    }
    String replacementString = buff.toString();
    if (!replacementString.equals(whitespaceRun)) {
      ReplaceEdit replaceEdit = new ReplaceEdit(spaceStartOffset, whitespaceRun.length(), replacementString);
      textEdit.addChild(replaceEdit);
    }
    return availableLineWidth;
  }
View Full Code Here

Examples of org.eclipse.text.edits.ReplaceEdit

    String lineDelimiters = null;
    if (!getFormattingPreferences().getClearAllBlankLines()) {
      lineDelimiters = extractLineDelimiters(whitespaceRun, currentRegion);
      String formattedLine = lineDelimiters + getIndentString(indentLevel);
      if(lineDelimiters.length() > 0 && !formattedLine.equals(whitespaceRun)) {
        textEdit.addChild(new ReplaceEdit(spaceStartOffset, whitespaceRun.length(), formattedLine));
        availableLineWidth = getFormattingPreferences().getMaxLineWidth() - indentLevel;
      }
    }
    if (lineDelimiters == null || lineDelimiters.length() == 0) {
      availableLineWidth = collapseSpaces(textEdit, spaceStartOffset, availableLineWidth, whitespaceRun);
View Full Code Here

Examples of org.eclipse.text.edits.ReplaceEdit

          onOwnLine = true;

          // Compress any whitespace before the line delimiter
          if (start != end) {
            int replaceLength = end - start;
            textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, EMPTY));
            start = end = i;
          }
        }
      }
      else {
        // Transitioned to a new word
        if (start != end) {
          int replaceLength = end - start;
          if (onOwnLine) {
            // If content is on its own line, replace leading whitespace with proper indent
            textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, indent));
            resultLength -= (replaceLength - indent.length());
            onOwnLine = false;
          }
          else if (!(replaceLength == 1 && text.charAt(start) == ' ')) {
            textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, SPACE));
            resultLength -= (replaceLength - 1);
          }
          start = end = i;
          // Make sure the word starts on a new line
          if (resultLength > lineWidth) {
            lineWidth = fPreferences.getMaxLineWidth();
            resultLength = 0;
            textEdit.addChild(new InsertEdit(start + startOffset, getLineDelimiter(region) + indent));
          }
        }
        // Word is immediately after line delimiters, indent appropriately
        if (onOwnLine) {
          textEdit.addChild(new InsertEdit(i + startOffset, indent));
          onOwnLine = false;
        }
        resultLength++;
      }
    }

    // Clean up any dangling whitespace
    int replaceLength = end - start;
    indent = getIndentString(indentLevel);
    if (replaceLength == 0) { // No trailing whitespace
      textEdit.addChild(new InsertEdit(length + startOffset, (onOwnLine) ? indent : SPACE));
    }
    else {
      String whitespace = text.substring(start);
      String replacement = (onOwnLine) ? indent : SPACE;
      if (!whitespace.equals(replacement)) {
        textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, replacement));
      }
    }
  }
View Full Code Here

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

Examples of org.eclipse.text.edits.ReplaceEdit

  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

Examples of org.eclipse.text.edits.ReplaceEdit

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

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

Examples of org.eclipse.text.edits.ReplaceEdit

            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
TOP
Copyright © 2018 www.massapi.com. 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.