Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit.apply()


        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


      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

    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

            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

    Util.setReadOnly(destFile, false);
    ICompilationUnit destCU = dest.getCompilationUnit(destName);
    IDocument document = getDocument(destCU);
    TextEdit edits = rewrite.rewriteAST(document, null);
    try {
      edits.apply(document);
    } catch (BadLocationException e) {
      throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
    }
    destCU.save(getSubProgressMonitor(1), this.force);
  }
View Full Code Here

    initializeDefaultPosition();
  }
  protected void apply(ASTRewrite rewriter, IDocument document, Map options) throws JavaModelException {
    TextEdit edits = rewriter.rewriteAST(document, options);
     try {
       edits.apply(document);
     } catch (BadLocationException e) {
       throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
     }
  }
  /**
 
View Full Code Here

    options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE);

    CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    TextEdit format = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
    IDocument document = new Document(text);
    format.apply(document);
    return document.get();
  }

  static Pattern EMPLINE = Pattern.compile("\\s*;?// line [0-9]+.*");

 
View Full Code Here

     
        TextEdit text = ToolFactory.createCodeFormatter(null).format(CodeFormatter.K_COMPILATION_UNIT, builderSource, 0, builderSource.length(), 0, "\n");
        // text is null if source cannot be formatted
        if (text != null) {
          Document simpleDocument = new Document(builderSource);
          text.apply(simpleDocument);
          buffer.setContents(simpleDocument.get());
        }
      } else {
        buffer.replace(pos, 0, sw.toString())
      }
View Full Code Here

    try {
      String contents = new String(org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(file, null));
      doc.set(contents);
      TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, null);
      if (edit != null) {
        edit.apply(doc);
      } else {       
        return false; // most likely syntax errror
      }

      // write the file
View Full Code Here

      Name name = ast.newName(cName);
      Type interfaceType = ast.newSimpleType(name);
      list.add(interfaceType);
      TextEdit edits = cunit.rewrite(document, icunit.getJavaProject()
          .getOptions(true));
      edits.apply(document);
      String newSource = document.get();
      icunit.getBuffer().setContents(newSource);
    } catch (Exception e) {
      ParserPlugin.getLogger().error(e);
    }
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.