Package org.eclipse.text.edits

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


      try {
        if (document instanceof IStructuredDocument) {
          IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
          if (model != null) {
            try {
              TextEdit edit = formatter.format(model, fRegion.getOffset(), fRegion.getLength());
              if (edit != null) {
                try {
                  model.aboutToChangeModel();
                  edit.apply(document);
                }
                finally {
                  model.changedModel();
                }
              }
View Full Code Here

    getFormatter().setProgressMonitor(new NullProgressMonitor() {
      public boolean isCanceled() {
        return fProgressMonitor != null && fProgressMonitor.isCanceled();
      }
    });
    TextEdit edit = getFormatter().format(structuredModel, start, length);
    if(fProgressMonitor != null)
      fProgressMonitor.worked(1);
   
    try {
      structuredModel.aboutToChangeModel();
      edit.apply(structuredDocument);
      if(fProgressMonitor != null)
        fProgressMonitor.worked(1);
    }
    catch (Exception e) {
      Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
View Full Code Here

             *     if set to <code>null</code>, then the platform default one will be used.
             * @return the text edit
             * @throws IllegalArgumentException if offset is lower than 0, length is lower than 0 or
             * length is greater than source length.
             */
            TextEdit edit = getCodeFormatter().format(org.eclipse.wst.jsdt.core.formatter.CodeFormatter.K_JAVASCRIPT_UNIT, text, startOffset, endOffset - startOffset, 0, lineSeparator);
            if (edit != null) {
                edit.apply(doc);
            } else {
                throw new RuntimeException(
                        Notifier.FORMATTING_FAILED_PROBABLY_DUE_TO_NOT_COMPILABLE_CODE_OR_WRONG_CONFIG_FILE);
            }

View Full Code Here

             * @return the text edit
             * @throws IllegalArgumentException if offset is lower than 0, length is lower than 0 or
             * length is greater than source length.
             */

            TextEdit edit = getCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, text,
                    startOffset, endOffset - startOffset, 0, lineSeparator);
            if (edit != null) {
                edit.apply(doc);
            } else {
                throw new RuntimeException(Notifier.FORMATTING_FAILED_PROBABLY_DUE_TO_NOT_COMPILABLE_CODE_OR_WRONG_CONFIG_FILE);
            }
            return doc.get();
        } catch (BadLocationException e) {
View Full Code Here

        bufferManager.connect(path, null);

        ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
        IDocument document = textFileBuffer.getDocument();

        TextEdit edit = cu.rewrite(document, javaProject.getOptions(true));
        TextFileChange dc = new TextFileChange(path.toString(), (IFile) cu.getJavaElement().getResource());
        dc.setTextType("java"); //$NON-NLS-1$
        dc.setEdit(edit);
        dc.setSaveMode(TextFileChange.FORCE_SAVE);
View Full Code Here

      try {
        IDocument document = new org.eclipse.jface.text.Document(documentIJ.getText());
        Properties javaFormattingPrefs = settings.getJavaProperties().get();
        Properties properties = settings.getJSProperties().get();

        TextEdit formatEdit = JsniFormattingUtil.format(document, javaFormattingPrefs, properties, range);
        formatEdit.apply(document);
        documentIJ.setText(document.get());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
View Full Code Here

        int i2 = INPUT.indexOf("-*/");
        TypedPosition partition = new TypedPosition(i, i2 - i + 3, "");
        HashMap<String, String> jsMap = TestUtils.getJSProperties();

        IDocument document = new Document(INPUT);
        TextEdit format1 = JsniFormattingUtil.format(document, partition, javaFormattingPrefs, jsMap, null);
//        TextEdit format1 = JsniFormattingUtil.format(document,javaFormattingPrefs, jsMap, null);
        format1.apply(document);
        Assert.assertEquals(FORMATTED, document.get());
        System.err.println(FORMATTED);
    }
View Full Code Here

       * @throws IllegalArgumentException
       *             if offset is lower than 0, length is lower than 0 or length is greater than source length.
       */

      LOG.debug("#starting to format by eclipse formatter");
      TextEdit edit = getCodeFormatter().format(
          CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, text, startOffset,
          endOffset - startOffset, 0, Settings.LINE_SEPARATOR);
      if (edit != null) {
        LOG.debug("reformatting done");
        edit.apply(doc);
      } else {
        throw new FormattingFailedException();
      }
      return doc.get();
    } catch (BadLocationException e) {
View Full Code Here


        IDocument document = new Document(createString(getTestClasses()));

        // Apply the formatting and test the result
        TextEdit formatEdit = JsniFormattingUtil.format(document, javaPrefs, javaScriptPrefs, new Range(0, document.get().length(), true));
        formatEdit.apply(document);
        Assert.assertEquals(getFormattedDocument(), document.get());
        System.err.println("---------------------------");
        System.err.println(getFormattedDocument());
        System.err.println("---------------------------");
        System.err.println(document.get());
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.