Examples of InsertEdit


Examples of org.eclipse.text.edits.InsertEdit

      wodElement.writeWodFormat(wodWriter, false);
      String wodString = wodWriter.toString();
      if (insertOffset > 0) {
        wodString = "\n" + wodString;
      }
      wodEdits.add(new InsertEdit(insertOffset, wodString));
      WodDocumentUtils.applyEdits(wodDocument, wodEdits);
    }
  }
View Full Code Here

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

Examples of org.eclipse.text.edits.InsertEdit

    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

Examples of org.eclipse.text.edits.InsertEdit

  final void doTextInsert(int offset, String insertString, TextEditGroup editGroup) {
    if (insertString.length() > 0) {
      // bug fix for 95839: problem with inserting at the end of a line comment
      if (this.lineCommentEndOffsets.isEndOfLineComment(offset, this.content)) {
        if (!insertString.startsWith(getLineDelimiter())) {
          TextEdit edit= new InsertEdit(offset, getLineDelimiter())// add a line delimiter
          addEdit(edit);
          if (editGroup != null) {
            addEditGroup(editGroup, edit);
          }
        }
        this.lineCommentEndOffsets.remove(offset); // only one line delimiter per line comment required
      }
      TextEdit edit= new InsertEdit(offset, insertString);
      addEdit(edit);
      if (editGroup != null) {
        addEditGroup(editGroup, edit);
      }
    }
View Full Code Here

Examples of org.eclipse.text.edits.InsertEdit

      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);
        if (this.filterImplicitImports && !pack.isStatic() && isImplicitImport(pack.getName())) {
          pack.filterImplicitImports(this.useContextToFilterImplicitImports);
        }
        int nImports= pack.getNumberOfImports();
        if (nImports == 0) {
          continue;
        }

        if (spacesBetweenGroups > 0 && lastPackage != null) {
          // add a space between two different groups by looking at the two adjacent imports
          if (!lastPackage.isComment() && !pack.isComment() && !pack.isSameGroup(lastPackage)) {
            for (int k= spacesBetweenGroups; k > 0; k--) {
              stringsToInsert.add(lineDelim);
            }
          } else if (lastPackage.isComment() && pack.isSameGroup(lastPackage)) {
            // the last pack may be a dummy for a comment which doesn't belong to any extended range
            stringsToInsert.add(lineDelim);
          }
        }
        lastPackage= pack;

        boolean isStatic= pack.isStatic();
        int threshold= isStatic ? this.staticImportOnDemandThreshold : this.importOnDemandThreshold;

        boolean doStarImport= pack.hasStarImport(threshold, onDemandConflicts);
        boolean allImportsAddedToStar = false;
        if (doStarImport && (pack.find("*") == null)) { //$NON-NLS-1$
          String[] imports = getNewImportStrings(buffer, pack, isStatic, lineDelim);
          for (int j = 0, max = imports.length; j < max; j++) {
            stringsToInsert.add(imports[j]);
          }
          allImportsAddedToStar = true; // may still need to handle onDemandConflicts below
        }

        for (int k= 0; k < nImports; k++) {
          ImportDeclEntry currDecl= pack.getImportAt(k);
          IRegion region= currDecl.getSourceRange();
          boolean isConflict = !currDecl.isComment() && onDemandConflicts != null && onDemandConflicts.contains(currDecl.getSimpleName());
          boolean addRegularToStar = doStarImport && !currDecl.isOnDemand();
         
          if (region == null) { // new entry
            if (!addRegularToStar || isConflict) {
              IRegion rangeBefore = currDecl.getPrecedingCommentRange();
              IRegion rangeAfter = currDecl.getTrailingCommentRange();
              if (rangeBefore != null) {
                stringsToInsert.add(buffer.getText(rangeBefore.getOffset(), rangeBefore.getLength()));
              }
             
              String trailingComment = null;
              if (rangeAfter != null) {
                trailingComment = buffer.getText(rangeAfter.getOffset(), rangeAfter.getLength());
              }
              String str= getNewImportString(currDecl.getElementName(), isStatic, trailingComment, lineDelim);
              stringsToInsert.add(str);
            } else if (addRegularToStar && !allImportsAddedToStar) {
              String simpleName = currDecl.getTypeQualifiedName();
              if (simpleName.indexOf('.') != -1) {
                String str= getNewImportString(currDecl.getElementName(), isStatic, lineDelim);
                if (stringsToInsert.indexOf(str) == -1) {
                  stringsToInsert.add(str);
                }
              }
            }
          } else if (!addRegularToStar || isConflict) {
            int offset= region.getOffset();
            IRegion rangeBefore = currDecl.getPrecedingCommentRange();
            if (rangeBefore != null && currPos > rangeBefore.getOffset()) {
              // moved ahead of the leading comments, bring the currPos back
              currPos = rangeBefore.getOffset();
            }
            if (rangeBefore != null) {
              stringsToInsert.add(buffer.getText(rangeBefore.getOffset(), rangeBefore.getLength()));
            }
            removeAndInsertNew(buffer, currPos, offset, stringsToInsert, resEdit);
            stringsToInsert.clear();
            currPos= offset + region.getLength();
          } else if (addRegularToStar && !allImportsAddedToStar && !currDecl.isComment()) {
            String simpleName = currDecl.getTypeQualifiedName();
            if (simpleName.indexOf('.') != -1) {
              IRegion rangeBefore = currDecl.getPrecedingCommentRange();
              if (rangeBefore != null && currPos > rangeBefore.getOffset()) {
                // moved ahead of the leading comments, bring the currPos back
                currPos = rangeBefore.getOffset();
              }
              if (rangeBefore != null) {
                stringsToInsert.add(buffer.getText(rangeBefore.getOffset(), rangeBefore.getLength()));
              }
              IRegion rangeAfter = currDecl.getTrailingCommentRange();
              String trailingComment = null;
              if (rangeAfter != null) {
                trailingComment = buffer.getText(rangeAfter.getOffset(), rangeAfter.getLength());
              }
              String str= getNewImportString(currDecl.getElementName(), isStatic, trailingComment, lineDelim);
              if (stringsToInsert.indexOf(str) == -1) {
                stringsToInsert.add(str);
              }
            }
          }
        }
      }

      // insert back all existing imports comments since existing imports were not preserved
      if (this.preserveExistingCommentsRanges != null) {
        for (int i = 0, max = this.preserveExistingCommentsRanges.length; (i < max && this.preserveExistingCommentsRanges[i] != null); i++) {
          IRegion region = this.preserveExistingCommentsRanges[i];
          String text = buffer.getText(region.getOffset(), region.getLength());
          // remove preceding whitespaces
          int index = 0;
          int length = text.length();
          loop: while (index < length) {
            if (Character.isWhitespace(text.charAt(index))) {
              index++;
            } else {
              break loop;
            }
          }
          if (index != 0) {
            text = text.substring(index);
          }
          if (!text.endsWith(lineDelim)) {
            text += lineDelim;
          }
          stringsToInsert.add(text);
        }
      }
      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

Examples of org.eclipse.text.edits.InsertEdit

        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

Examples of org.eclipse.text.edits.InsertEdit

        super(req);
    }

    @Override
    public InsertEdit getEdit() throws MisconfigurationException {
        return new InsertEdit(getOffset(), getFormattedNode());
    }
View Full Code Here

Examples of org.eclipse.text.edits.InsertEdit

      int end = imprt.getStartPosition() + imprt.getLength() + lineDelim.length();
      if (next != null &&
          end == next.getStartPosition() &&
          !ImportUtils.importsInSameGroup(separationLevel, imprt, next))
      {
        edit.addChild(new InsertEdit(end, lineDelim));
      }
      next = imprt;
    }

    return edit.getChildrenSize() > 0 ? edit : null;
View Full Code Here

Examples of org.eclipse.text.edits.InsertEdit

  private void addLineDelim(
      CompilationUnit astRoot, MultiTextEdit edit, int offset, String lineDelim)
  {
    ASTNode node = NodeFinder.perform(astRoot, offset, 1);
    if (node != null && node.getNodeType() == ASTNode.IMPORT_DECLARATION){
      edit.addChild(new InsertEdit(offset, lineDelim));
    }
  }
View Full Code Here

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