Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.InsertEdit


        if (isImport(javaPositions[i].getOffset()) && replaceText.lastIndexOf("import ") != -1) { //$NON-NLS-1$
          replaceText = newJavaText.substring(deltas[i].postOffset, deltas[i].postOffset + deltas[i].postLength);
          String importText = replaceText.substring(replaceText.lastIndexOf("import "), replaceText.indexOf(";")); //$NON-NLS-1$ //$NON-NLS-2$
          // evenutally need to check if it's XML-JSP
          importText = "<%@page import=\"" + importText + "\" %>\n"; //$NON-NLS-1$ //$NON-NLS-2$
          jspEdits.add(new InsertEdit(0, importText));
        }
      }
    }
    TextEdit allJspEdits = createMultiTextEdit((TextEdit[]) jspEdits.toArray(new TextEdit[jspEdits.size()]));
View Full Code Here


      // delete all whitespace and insert new one
      // collapse whitespace by deleting whitespace
      DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset, whitespaceRun.length());
      textEdit.addChild(deleteEdit);
      // then insert one space
      InsertEdit insertEdit = new InsertEdit(spaceStartOffset, SPACE);
      textEdit.addChild(insertEdit);
    }
    // remember to account for space added
    --availableLineWidth;
    return availableLineWidth;
View Full Code Here

          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)) {
View Full Code Here

          // 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;
View Full Code Here

      String whitespaceRun = fullTagName.substring(textLength, regionLength);
      collapseSpaces(textEdit, spacesStartOffset, availableLineWidth, whitespaceRun);
    }
    else {
      // insert a space
      InsertEdit insertEdit = new InsertEdit(spacesStartOffset, SPACE);
      textEdit.addChild(insertEdit);
    }
  }
View Full Code Here

                defaultValue = ""; //$NON-NLS-1$
              String nameAndDefaultValue = " "; //$NON-NLS-1$
              if (i == 0 && lastRegion.getLength() > lastRegion.getTextLength())
                nameAndDefaultValue = ""; //$NON-NLS-1$
              nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
              multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));
              // BUG3381: MultiTextEdit applies all child
              // TextEdit's basing on offsets
              //          in the document before the first TextEdit, not
              // after each
              //          child TextEdit. Therefore, do not need to
View Full Code Here

      // insert new element
      MultiTextEdit multiTextEdit = new MultiTextEdit();
      // element tag name cannot be DBCS, do not translate "<element>"
      // and "</element>"
      final String startElement = "<" + ELEMENT_NAME + ">"; //$NON-NLS-1$ //$NON-NLS-2$
      multiTextEdit.addChild(new InsertEdit(startTagOffset, startElement));
      multiTextEdit.addChild(new InsertEdit(endTagOffset, "</"+ELEMENT_NAME +">")); //$NON-NLS-1$ //$NON-NLS-2$
      multiTextEdit.apply(viewer.getDocument());
      Position start = new Position(startTagOffset);
      Position end = new Position(endTagOffset + startElement.length());

      try {
View Full Code Here

  private static void removeInsertEdits_forSubString(TextEdit edit, String subString) {
    if (edit instanceof MultiTextEdit) {
      MultiTextEdit multiTextEdit = (MultiTextEdit) edit;
      for (TextEdit child : multiTextEdit.getChildren()) {
        if (child instanceof InsertEdit) {
          InsertEdit insertEdit = (InsertEdit) child;
          if (insertEdit.getText().indexOf(subString) != -1) {
            multiTextEdit.removeChild(insertEdit);
          }
        } else {
          removeInsertEdits_forSubString(child, subString);
        }
View Full Code Here

  private static void removeInsertEdits_forNewLine(TextEdit edit) {
    if (edit instanceof MultiTextEdit) {
      MultiTextEdit multiTextEdit = (MultiTextEdit) edit;
      for (TextEdit child : multiTextEdit.getChildren()) {
        if (child instanceof InsertEdit) {
          InsertEdit insertEdit = (InsertEdit) child;
          if (insertEdit.getText().equals("\n")) {
            multiTextEdit.removeChild(insertEdit);
          }
        } else {
          removeInsertEdits_forNewLine(child);
        }
View Full Code Here

          buffer.append("\"");

          IDocument htmlDocument = _cache.getHtmlEntry().getDocument();
          if (htmlDocument != null) {
            List<TextEdit> htmlEdits = new LinkedList<TextEdit>();
            htmlEdits.add(new InsertEdit(newBindingOffset, buffer.toString()));
            WodDocumentUtils.applyEdits(htmlDocument, htmlEdits);
          }
        }
        else {
          buffer.append(" = ");
          buffer.append(_newValue);
          buffer.append(";");
          buffer.append("\n");

          IDocument wodDocument = _cache.getWodEntry().getDocument();
          if (wodDocument != null) {
            List<TextEdit> wodEdits = new LinkedList<TextEdit>();
            wodEdits.add(new InsertEdit(newBindingOffset, buffer.toString()));
            WodDocumentUtils.applyEdits(wodDocument, wodEdits);
          }
        }
      }
      else {
View Full Code Here

TOP

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

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.