Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


   
    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


          String curr= (String) this.removedImports.get(i);
          computer.removeImport(curr.substring(1), STATIC_PREFIX == curr.charAt(0));
        }
      }
       
      TextEdit result= computer.getResultingEdits(new SubProgressMonitor(monitor, 1));
      this.createdImports= computer.getCreatedImports();
      this.createdStaticImports= computer.getCreatedStaticImports();
      return result;
    } finally {
      monitor.done();
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

       
    ASTRewrite rewriter= sortCompilationUnit(ast, null);
    if (rewriter == null)
      return document.get();
   
    TextEdit edits = rewriter.rewriteAST(document, null);
   
    RangeMarker[] markers = null;
    if (this.positions != null) {
      markers = new RangeMarker[this.positions.length];
      for (int i = 0, max = this.positions.length; i < max; i++) {
        markers[i]= new RangeMarker(this.positions[i], 0);
        insert(edits, markers[i]);
      }
    }
    try {
      edits.apply(document, TextEdit.UPDATE_REGIONS);
      if (this.positions != null) {
        for (int i= 0, max = markers.length; i < max; i++) {
          this.positions[i]= markers[i].getOffset();
        }
      }
View Full Code Here

      return;
    }
    TextEdit[] children= parent.getChildren();
    // First dive down to find the right parent.
    for (int i= 0; i < children.length; i++) {
      TextEdit child= children[i];
      if (covers(child, edit)) {
        insert(child, edit);
        return;
      }
    }
    // We have the right parent. Now check if some of the children have to
    // be moved under the new edit since it is covering it.
    for (int i= children.length - 1; i >= 0; i--) {
      TextEdit child= children[i];
      if (covers(edit, child)) {
        parent.removeChild(i);
        edit.addChild(child);
      }
    }
View Full Code Here

    final char[] compilationUnitSource = string.toCharArray();
   
    this.scribe.initializeScanner(compilationUnitSource);

    TextEdit result = null;
    try {
      result = region.format(this.preferences.initial_indentation_level, true);
    } catch(AbortFormatting e){
      return failedToFormat();
    }
View Full Code Here

        System.out.println(Messages.bind(Messages.CommandLineFormatting, file.getAbsolutePath()));
      }
      String contents = new String(org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(file, null));
      // format the file (the meat and potatoes)
      doc.set(contents);
      TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, null);
      if (edit != null) {
        edit.apply(doc);
      } else {
        System.err.println(Messages.bind(Messages.FormatProblem, file.getAbsolutePath()));
        return;
      }
View Full Code Here

      Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$
    IDocument document = getDocument(cu);
    AST ast = astCU.getAST();
    ASTRewrite rewriter = ASTRewrite.create(ast);
    rewriter.remove(node, null);
     TextEdit edits = rewriter.rewriteAST(document, null);
     try {
       edits.apply(document);
     } catch (BadLocationException e) {
       throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
     }
  }
View Full Code Here

    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
   
    DefaultCodeFormatter defaultCodeFormatter = new DefaultCodeFormatter(newOptions);
    TextEdit textEdit = defaultCodeFormatter.format(org.aspectj.org.eclipse.jdt.core.formatter.CodeFormatter.K_UNKNOWN, string, 0, string.length(), indentLevel, lineSeparator);
    if (positions != null && textEdit != null) {
      // update positions
      TextEdit[] edits = textEdit.getChildren();
      int textEditSize = edits.length;
      int editsIndex = 0;
      int delta = 0;
      int originalSourceLength = string.length() - 1;
      if (textEditSize != 0) {
View Full Code Here

            CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
            AST ast = astCU.getAST();
            ASTRewrite rewrite = ASTRewrite.create(ast);
            updatePackageStatement(astCU, newFragName, rewrite);
            IDocument document = getDocument(cu);
            TextEdit edits = rewrite.rewriteAST(document, null);
            try {
              edits.apply(document);
            } catch (BadLocationException e) {
              throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
            }     
            cu.save(null, false);
          }
View Full Code Here

TOP

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

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.