Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


  }

  public TextEdit format(IStructuredModel model, int start, int length, XMLFormattingPreferences preferences) {
    setFormattingPreferences(preferences);

    TextEdit edit = new MultiTextEdit();
    IStructuredDocument document = model.getStructuredDocument();
    // get initial document region
    IStructuredDocumentRegion currentRegion = document.getRegionAtCharacterOffset(start);
    if (currentRegion != null) {
      int startOffset = currentRegion.getStartOffset();
View Full Code Here


    int availableLineWidth;
    String indentString = getIndentString(indentLevel);
    String lineDelimiter = getLineDelimiter(currentRegion);
    String newLineAndIndent = lineDelimiter + indentString;
   
    TextEdit indentation = null;
   
    // if not already correctly indented
    if (!newLineAndIndent.equals(whitespaceRun)) {
      if (getFormattingPreferences().getClearAllBlankLines()) {
        if (whitespaceRun != null) {
View Full Code Here

     
      if (formatSource) {
        buffer.replace(pos, 0, sw.toString());
        String builderSource = buffer.getContents();
     
        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

  public boolean formatFile(File file) throws ExporterException {
    IDocument doc = new Document();
    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

        if (!success)
          return null;
        removeRemovedComponent(root, monitor, unit, type);
        createPreferredLnf(root, monitor, type, imports);
        if (success) {
          TextEdit edit = imports.rewriteImports(monitor);
          JavaUtil.applyEdit(copy, edit, true, monitor);
        }
        if (copy.isWorkingCopy()) {
          copy.commitWorkingCopy(true, monitor);
          copy.discardWorkingCopy();
View Full Code Here

      TypeDeclaration typeDec = (TypeDeclaration) cunit.types().get(0);
      List list = typeDec.superInterfaceTypes();
      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

        DefaultCodeFormatterConstants.TRUE);

    // instantiate the default code formatter with the given options
    final CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(options);
    final TextEdit editCode = codeFormatter.format(
        CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, source, 0,
        source.length(), 0, System.getProperty("line.separator"));

    IDocument document = new Document(source);

    if (icu != null && document != null && editCode != null) {
      try {
        editCode.apply(document);
      } catch (MalformedTreeException e) {
        CrashReporter.reportException(e);
      } catch (BadLocationException e) {
        CrashReporter.reportException(e);
      }
View Full Code Here

        DefaultCodeFormatterConstants.TRUE);

    // instantiate the default code formatter with the given options
    final CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(options);
    final TextEdit editCode = codeFormatter.format(
        CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, source, 0,
        source.length(), 0, System.getProperty("line.separator"));

    IDocument document = new Document(source);

    if (icu != null && document != null && editCode != null) {
      try {
        editCode.apply(document);
      } catch (MalformedTreeException e) {
        e.printStackTrace();
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
View Full Code Here

        DefaultCodeFormatterConstants.TRUE);

    // instantiate the default code formatter with the given options
    final CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(options);
    final TextEdit editCode = codeFormatter.format(
        CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, source, 0,
        source.length(), 0, System.getProperty("line.separator"));

    IDocument document = new Document(source);

    if (icu != null && document != null && editCode != null) {
      try {
        editCode.apply(document);
      } catch (MalformedTreeException e) {
        e.printStackTrace();
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
View Full Code Here

      String source = icu.getSource();
      Document document = new Document(source);

      // computation of the text edits
      TextEdit edits = rewrite.rewriteAST(document, icu.getJavaProject()
          .getOptions(true));

      // computation of the new source code
      if (edits != null) {
        edits.apply(document);
      }

      String newSource = document.get();

      // update of the compilation unit
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.