Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


        return (CompilationUnit) parser.createAST(monitor);
    }

    private void rewriteCompilationUnit(ASTRewrite rewrite, IDocument doc, ICompilationUnit originalUnit)
            throws JavaModelException, BadLocationException {
        TextEdit edits = rewrite.rewriteAST(doc, originalUnit.getJavaProject().getOptions(true));
        edits.apply(doc);

        originalUnit.getBuffer().setContents(doc.get());
        originalUnit.commitWorkingCopy(false, monitor);
    }
View Full Code Here


      // retrieve the buffer
      IDocument document = bufferManager.getTextFileBuffer(path)
          .getDocument();

      // ask the textEditProvider for the change information
      TextEdit edit = textEditProvider.getTextEdit(document);

      // apply the changes to the document
      edit.apply(document);

    } catch (MalformedTreeException e) {
      e.printStackTrace();
    } catch (BadLocationException e) {
      e.printStackTrace();
View Full Code Here

      String contents = javaClass.toString();

      IDocument doc = new Document(contents);
      try
      {
         TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, null);
         if (edit != null)
         {
            edit.apply(doc);
         }
         else
         {
            return contents;
         }
View Full Code Here

   {
      Document document = new Document(this.document.get());

      try
      {
         TextEdit edit = unit.rewrite(document, null);
         edit.apply(document);
      }
      catch (Exception e)
      {
         throw new ParserException("Could not modify source: " + unit.toString(), e);
      }
View Full Code Here

      // TODO was in previous version
      // TextEdit edit =
      // codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, contents,
      // 0, contents.length(), 0, null);

      TextEdit edit = codeFormatter.format(
          CodeFormatter.K_COMPILATION_UNIT
              | CodeFormatter.F_INCLUDE_COMMENTS, 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

          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
              | CodeFormatter.F_INCLUDE_COMMENTS, contents, 0,
          contents.length(), 0, lineSeparator );
      if( edit != null )
      {
        edit.apply( doc );
      } else
      {
        throw new RuntimeException( Messages.bind(
            Messages.FormatProblem, file.getAbsolutePath() ) );
      }
View Full Code Here

    IDocument doc = new Document();
    try
    {
      doc.set( contents );
      TextEdit edit = codeFormatter.format(
          CodeFormatter.K_COMPILATION_UNIT
              | CodeFormatter.F_INCLUDE_COMMENTS, contents,
          startOffset, endOffset, 0, lineSeparator );
      if( edit != null )
      {
        edit.apply( doc );
      } else
      {
        throw new RuntimeException(
            "formatting failed, probably due to not compilable code or wrong config file" );
      }
View Full Code Here

     * @return A text edit that when applied to the document, will format the jsni methods.
     */
    @SuppressWarnings("unchecked")
    public static TextEdit format(IDocument document, Map javaFormattingPrefs, Map javaScriptFormattingPrefs,
                                  Range range) {
        TextEdit combinedEdit = new MultiTextEdit();
        ITypedRegion[] regions = computePartitioning(document, range);

        // Format all JSNI blocks in the document
        int i = 0;
        for (ITypedRegion region : regions) {
            if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
                String originalJsniMethod = null;
                TextEdit edit = format(document, new TypedPosition(region), javaFormattingPrefs,
                        javaScriptFormattingPrefs, originalJsniMethod);
                if (edit != null) {
                    combinedEdit.addChild(edit);
                }
                i++;
View Full Code Here

            // with place holder values
            JsniJavaRefReplacementResult replacementResults = replaceJsniJavaRefs(body);
            body = replacementResults.getJsni();
            CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(javaScriptFormattingPrefs);

            TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_STATEMENTS, body, 0, body.length(),
                    methodIndentLevel + 1, lineDelimiter);

            if (formatEdit != null) {

                body = restoreJsniJavaRefs(replacementResults);

                Document d = new Document(body);
                formatEdit.apply(d);

                formattedJs = d.get();

                if (!formattedJs.startsWith(lineDelimiter)) {
                    formattedJs = lineDelimiter + formattedJs;
View Full Code Here

    if (FileUtils.isJavaScript(file) && settings.isEnableJSProcessor()) {
      try {
        String text = documentIJ.getText();
        IDocument document = new org.eclipse.jface.text.Document(text);

        TextEdit formatEdit = format(document, range);


        formatEdit.apply(document);
        documentIJ.setText(document.get());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
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.