Examples of TextEdit


Examples of org.eclipse.text.edits.TextEdit

     * @param deletedEnd
     * @return
     */
    private static TextEdit createReplaceEdit(final int addedStart, final int addedEnd,
            final int deletedStart, final int deletedEnd) {
        final TextEdit result = new MultiTextEdit();

        final int addedLength = addedEnd - addedStart + 1;
        final int deletedLength = deletedEnd - deletedStart + 1;
        final int minLength = Math.min(addedLength, deletedLength);

        if (deletedLength < addedLength) {
            result.addChild(new InsertEdit(deletedStart + minLength, getString(addedStart
                    + minLength, addedEnd)));
        }

        result.addChild(new ReplaceEdit(deletedStart, minLength, getString(addedStart,
                addedStart + minLength - 1)));

        if (addedLength < deletedLength) {
            result.addChild(new DeleteEdit(deletedStart + minLength, deletedLength
                    - minLength));
        }

        return result;
    }
View Full Code Here

Examples of org.eclipse.text.edits.TextEdit

  public TextEdit format(IDocument document, int start, int length) {
    return format(document, start, length, new XMLFormattingPreferences());
  }

  public TextEdit format(IDocument document, int start, int length, XMLFormattingPreferences preferences) {
    TextEdit edit = null;
    if (document instanceof IStructuredDocument) {
      IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
      if (model != null) {
        try {
          edit = format(model, start, length, preferences);
View Full Code Here

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

Examples of org.eclipse.text.edits.TextEdit

    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

Examples of org.eclipse.text.edits.TextEdit

     
      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

Examples of org.eclipse.text.edits.TextEdit

  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

Examples of org.eclipse.text.edits.TextEdit

        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

Examples of org.eclipse.text.edits.TextEdit

      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

Examples of org.eclipse.text.edits.TextEdit

        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

Examples of org.eclipse.text.edits.TextEdit

        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
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.