Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.InsertEdit


      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


      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) {
          // 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 ? this.staticImportOnDemandThreshold : this.importOnDemandThreshold;

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

        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()) {
              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 (!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();
          } else if (doStarImport && !currDecl.isOnDemand()) {
            String simpleName = currDecl.getTypeQualifiedName();
            if (simpleName.indexOf('.') != -1) {
              String str= getNewImportString(currDecl.getElementName(), isStatic, lineDelim);
              if (stringsToInsert.indexOf(str) == -1) {
                stringsToInsert.add(str);
              }
            }
          }
        }
      }

      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

  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

                // edit object for the text replacement in the file, this is the only child
                ReplaceEdit rEdit = new ReplaceEdit(
                        (int) pair.first,
                        (int) pair.second,
                        "");
                InsertEdit iEdit = new InsertEdit(
                        (int) pair.first,
                        newName);
                fileChangeRootEdit.addChild(rEdit);
                fileChangeRootEdit.addChild(iEdit);
            }
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

        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

      if (!getTranslation().javaSpansMultipleJspPartitions(javaOffset, length))
        translatedTextEdit = new ReplaceEdit(jspOffset, length, ((ReplaceEdit) textEdit).getText());
    }
    else if (textEdit instanceof InsertEdit) {
      translatedTextEdit = new InsertEdit(jspOffset, ((InsertEdit) textEdit).getText());
    }
    else if (textEdit instanceof DeleteEdit) {
      translatedTextEdit = new DeleteEdit(jspOffset, length);
      TextEdit[] children = ((DeleteEdit) textEdit).getChildren();
      for (int i = 0; i < children.length; i++) {
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

    // calculate once and pass along
    boolean isXml = isXmlFormat(doc);
   
    int insertPosition = getInsertPosition(doc, isXml);
    String insertText = createImportDeclaration(doc, isXml);
    InsertEdit insert = new InsertEdit(insertPosition, insertText);
    try {
      insert.apply(doc);
    }
    catch (MalformedTreeException e) {
      Logger.logException(e);
    }
    catch (BadLocationException e) {
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.