Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.MultiTextEdit


    }
    return Util.EMPTY_STRING;
  }
 
  public TextEdit getRootEdit() {
    MultiTextEdit edit = null;
    int length = this.textRegionEnd - this.textRegionStart + 1;
    if (this.textRegionStart <= 0) {
      if (length <= 0) {
        edit = new MultiTextEdit(0, 0);
      } else {
        edit = new MultiTextEdit(0, this.textRegionEnd + 1);
      }
    } else {
      edit = new MultiTextEdit(this.textRegionStart, this.textRegionEnd - this.textRegionStart + 1);
    }
    for (int i= 0, max = this.editsIndex; i < max; i++) {
      OptimizedReplaceEdit currentEdit = edits[i];
      if (isValidEdit(currentEdit)) {
        edit.addChild(new ReplaceEdit(currentEdit.offset, currentEdit.length, currentEdit.replacement));
      }
    }
    this.edits = null;
    return edit;
  }
View Full Code Here


      final CommentRegion region = createRegion(kind, new Document(source), new Position(offset, length), this.newCodeFormatter);
      if (region != null) {
        return this.newCodeFormatter.format(source, region);
      }
    }
    return new MultiTextEdit();
  }
View Full Code Here

    if (edit == null) {
        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

      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
    }
    TextEdit[] children= oldEdit.getChildren();
    for (int i= 0; i < children.length; i++) {
View Full Code Here

      throw new IllegalArgumentException();
    }
   
    ASTNode rootNode= getRootNode();
    if (rootNode == null) {
      return new MultiTextEdit(); // no changes
    }
     
    char[] content= document.get().toCharArray();
    LineInformation lineInfo= LineInformation.create(document);
    String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
View Full Code Here

   * @since 3.2
   */
  public TextEdit rewriteAST() throws JavaModelException, IllegalArgumentException {
    ASTNode rootNode= getRootNode();
    if (rootNode == null) {
      return new MultiTextEdit(); // no changes
    }
   
    ASTNode root= rootNode.getRoot();
    if (!(root instanceof CompilationUnit)) {
      throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit or class file"); //$NON-NLS-1$
View Full Code Here

   
    return internalRewriteAST(content, lineInfo, lineDelim, astRoot.getCommentList(), options, rootNode);
  }
 
  private TextEdit internalRewriteAST(char[] content, LineInformation lineInfo, String lineDelim, List commentNodes, Map options, ASTNode rootNode) {
    TextEdit result= new MultiTextEdit();
    //validateASTNotModified(rootNode);
   
    TargetSourceRangeComputer sourceRangeComputer= getExtendedSourceRangeComputer();
    this.eventStore.prepareMovedNodes(sourceRangeComputer);
   
View Full Code Here

    try {
      monitor.beginTask(Messages.bind(Messages.importRewrite_processDescription), 2);
      if (!hasRecordedChanges()) {
        this.createdImports= CharOperation.NO_STRINGS;
        this.createdStaticImports= CharOperation.NO_STRINGS;
        return new MultiTextEdit();
      }
     
      CompilationUnit usedAstRoot= this.astRoot;
      if (usedAstRoot == null) {
        ASTParser parser= ASTParser.newParser(AST.JLS3);
View Full Code Here

   * @param options options
   * @throws IllegalArgumentException if the rewrite fails
   * @return Returns the edit describing the text changes.
   */
  public TextEdit rewriteAST(IDocument document, Map options) {
    TextEdit result = new MultiTextEdit();
   
    final CompilationUnit rootNode = getRootNode();
    if (rootNode != null) {
      TargetSourceRangeComputer xsrComputer = new TargetSourceRangeComputer() {
        /**
 
View Full Code Here

         
      String lineDelim= this.compilationUnit.findRecommendedLineSeparator();
      IBuffer buffer= this.compilationUnit.getBuffer();
                 
      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
        }
      }
      return resEdit;
    } finally {
      monitor.done();
View Full Code Here

TOP

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

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.