Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.InsertEdit


        if (initialIndentationLevel > 0) {
            // at least correct the indent
            String indentString = createIndentString(initialIndentationLevel);
        ReplaceEdit[] edits = IndentManipulation.getChangeIndentEdits(unformatted, 0, this.tabWidth, this.indentWidth, indentString);
        edit= new MultiTextEdit();
        edit.addChild(new InsertEdit(0, indentString));
        edit.addChildren(edits);
        } else {
           return unformatted;
        }
    }
View Full Code Here


    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

      int currPos= importsStart;
      MultiTextEdit resEdit= new MultiTextEdit();
     
      if ((this.flags & F_NEEDS_LEADING_DELIM) != 0) {
        // new import container
        resEdit.addChild(new InsertEdit(currPos, lineDelim));
      }
     
      PackageEntry lastPackage= null;
     
      Set onDemandConflicts= null;
      if (this.findAmbiguousImports) {
        onDemandConflicts= evaluateStarImportConflicts(monitor);
      }
     
      int spacesBetweenGroups= getSpacesBetweenImportGroups();
     
      ArrayList stringsToInsert= new ArrayList();
     
      int nPackageEntries= this.packageEntries.size();
      for (int i= 0; i < nPackageEntries; i++) {
        PackageEntry pack= (PackageEntry) this.packageEntries.get(i);
        int nImports= pack.getNumberOfImports();
 
        if (this.filterImplicitImports && !pack.isStatic() && isImplicitImport(pack.getName(), this.compilationUnit)) {
          pack.removeAllNew(onDemandConflicts);
          nImports= pack.getNumberOfImports();
        }
        if (nImports == 0) {
          continue;
        }
       

        if (spacesBetweenGroups > 0) {
          // add a space between two different groups by looking at the two adjacent imports
          if (lastPackage != null && !pack.isComment() && !pack.isSameGroup(lastPackage)) {
            ImportDeclEntry last= lastPackage.getImportAt(lastPackage.getNumberOfImports() - 1);
            ImportDeclEntry first= pack.getImportAt(0);
            if (!lastPackage.isComment() && (last.isNew() || first.isNew())) {
              for (int k= spacesBetweenGroups; k > 0; k--) {
                stringsToInsert.add(lineDelim);
              }
            }
          }
        }
        lastPackage= pack;
       
        boolean isStatic= pack.isStatic();
        int threshold= isStatic ? staticImportOnDemandThreshold : importOnDemandThreshold;
       
        boolean doStarImport= pack.hasStarImport(threshold, onDemandConflicts);
        if (doStarImport && (pack.find("*") == null)) { //$NON-NLS-1$
          String starImportString= pack.getName() + ".*"; //$NON-NLS-1$
          String str= getNewImportString(starImportString, isStatic, lineDelim);
          stringsToInsert.add(str);
        }
       
        for (int k= 0; k < nImports; k++) {
          ImportDeclEntry currDecl= pack.getImportAt(k);
          IRegion region= currDecl.getSourceRange();
         
          if (region == null) { // new entry
            if (!doStarImport || currDecl.isOnDemand() || (onDemandConflicts != null && onDemandConflicts.contains(currDecl.getSimpleName()))) {
              String str= getNewImportString(currDecl.getElementName(), isStatic, lineDelim);
              stringsToInsert.add(str);
            }
          } else {
            if (!doStarImport || currDecl.isOnDemand() || onDemandConflicts == null || onDemandConflicts.contains(currDecl.getSimpleName())) {
              int offset= region.getOffset();
              removeAndInsertNew(buffer, currPos, offset, stringsToInsert, resEdit);
              stringsToInsert.clear();
              currPos= offset + region.getLength();
            }
          }
        }
      }
     
      int end= importsStart + importsLen;
      removeAndInsertNew(buffer, currPos, end, stringsToInsert, resEdit);
     
      if (importsLen == 0) {
        if (!this.importsCreated.isEmpty() || !this.staticImportsCreated.isEmpty()) { // new import container
          if ((this.flags & F_NEEDS_TRAILING_DELIM) != 0) {
            resEdit.addChild(new InsertEdit(currPos, lineDelim));
          }
        } else {
          return new MultiTextEdit(); // no changes
        }
      }
View Full Code Here

        if (idx != pos) {
          resEdit.addChild(new DeleteEdit(pos, idx - pos));
        }
        pos= idx + curr.length();
      } else {
        resEdit.addChild(new InsertEdit(pos, curr));
      }
    }
    if (pos < contentEnd) {
      resEdit.addChild(new DeleteEdit(pos, contentEnd - pos));
    }
View Full Code Here

            result = createReplaceEdit(diff.getAddedStart(), diff.getAddedEnd(),
                    diff.getDeletedStart(), diff.getDeletedEnd());
        }
        // insert
        else if (diff.getAddedEnd() != -1 && diff.getDeletedEnd() == -1) {
            result = new InsertEdit(diff.getDeletedStart(), getString(
                    diff.getAddedStart(), diff.getAddedEnd()));
        }

        return result;
    }
View Full Code Here

        final int addedLength = addedEnd - addedStart + 1;
        final int deletedLength = deletedEnd - deletedStart + 1;
        final int minLength = Math.min(addedLength, deletedLength);

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

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

        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 advance the
        // index.
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

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.