Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


        }
       
        bodyDeclarations.removeAll(declarationsToDelete);
       
        // computation of the text edits
        TextEdit edits = astRoot.rewrite(document, asyncContents.getJavaProject().getOptions(true));

        // computation of the new source code
        edits.apply(document);
        String newSource = document.get();

        // update of the compilation unit     
        clientPackage.createCompilationUnit(remoteServiceAsyncName+".java", newSource, true, monitor); //$NON-NLS-1$
       
View Full Code Here


   */
  public void beforeWriteAndClose(final FileHandle info) {
    if (info.getAbsolutePath().endsWith("pp")) {

      IDocument doc = new Document(info.getBuffer().toString());
      TextEdit edit = getCodeFormatter().format(CodeFormatter.K_STATEMENTS, doc.get(), 0, doc.get().length(), 0,
          null);

      // check if text formatted successfully
      if (edit != null) {
        try {
          edit.apply(doc);
          info.setBuffer(new StringBuffer(doc.get()));
        } catch (MalformedTreeException e) {
          log.warn("Error during code formatting. Illegal code edit tree (" + e.getMessage() + ").");
        } catch (BadLocationException e) {
          log.warn("Error during code formatting. Bad location (" + e.getMessage() + ").");
View Full Code Here

    }

    bodyDeclarations.removeAll(declarationsToDelete);

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

    // computation of the new source code
    edits.apply(document);
    String newSource = document.get();

    // update of the compilation unit
    clientPackage.createCompilationUnit(remoteServiceAsyncName + ".java", newSource, true, monitor); //$NON-NLS-1$
  }
View Full Code Here

        }
       
        bodyDeclarations.removeAll(declarationsToDelete);
       
        // computation of the text edits
        TextEdit edits = astRoot.rewrite(document, asyncContents.getJavaProject().getOptions(true));

        // computation of the new source code
        edits.apply(document);
        String newSource = document.get();

        // update of the compilation unit     
        clientPackage.createCompilationUnit(remoteServiceAsyncName+".java", newSource, true, monitor); //$NON-NLS-1$
       
View Full Code Here

          importText = "<%@page import=\"" + importText + "\" %>\n"; //$NON-NLS-1$ //$NON-NLS-2$
          jspEdits.add(new InsertEdit(0, importText));
        }
      }
    }
    TextEdit allJspEdits = createMultiTextEdit((TextEdit[]) jspEdits.toArray(new TextEdit[jspEdits.size()]));

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105632
    // undo the java edit
    // (so the underlying Java document still represents what's in the
    // editor)
View Full Code Here

  public JSPTranslationUtil(IDocument document) {
    fDocument = document;
  }

  public TextEdit translateTextEdit(TextEdit textEdit) {
    TextEdit translatedTextEdit = null;

    int javaOffset = textEdit.getOffset();
    int jspOffset = getTranslation().getJspOffset(textEdit.getOffset());
    int length = textEdit.getLength();

    if (textEdit instanceof MultiTextEdit) {
      translatedTextEdit = new MultiTextEdit();
      TextEdit[] children = ((MultiTextEdit) textEdit).getChildren();
      for (int i = 0; i < children.length; i++) {
        TextEdit translatedChildTextEdit = translateTextEdit(children[i]);
        if (translatedChildTextEdit != null)
          ((MultiTextEdit) translatedTextEdit).addChild(translatedChildTextEdit);
      }
    }
    else if (textEdit instanceof ReplaceEdit) {
      if (jspOffset == -1)
        return null;

      if (!getTranslation().javaSpansMultipleJspPartitions(javaOffset, length))
        translatedTextEdit = new ReplaceEdit(jspOffset, length, ((ReplaceEdit) textEdit).getText());
    }
    else if (textEdit instanceof InsertEdit) {
      translatedTextEdit = new InsertEdit(jspOffset, ((InsertEdit) textEdit).getText());
    }
    else if (textEdit instanceof DeleteEdit) {
      translatedTextEdit = new DeleteEdit(jspOffset, length);
      TextEdit[] children = ((DeleteEdit) textEdit).getChildren();
      for (int i = 0; i < children.length; i++) {
        TextEdit translatedChildTextEdit = translateTextEdit(children[i]);
        if (translatedChildTextEdit != null)
          ((DeleteEdit) translatedTextEdit).addChild(translatedChildTextEdit);
      }
    }
    else if (textEdit instanceof CopySourceEdit) {
View Full Code Here

          importText = "<%@page import=\"" + importText + "\" %>\n"; //$NON-NLS-1$ //$NON-NLS-2$
          jspEdits.add(new InsertEdit(0, importText));
        }
      }
    }
    TextEdit allJspEdits = createMultiTextEdit((TextEdit[]) jspEdits.toArray(new TextEdit[jspEdits.size()]));

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105632
    // undo the java edit
    // (so the underlying Java document still represents what's in the
    // editor)
View Full Code Here

        JSPTranslationUtil translationUtil = new JSPTranslationUtil(document);
        ICompilationUnit cu = translationUtil.getCompilationUnit();
        if (cu != null) {
          String cuSource = cu.getSource();
          TextEdit textEdit = formatString(CodeFormatter.K_COMPILATION_UNIT, cuSource, 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences());

          TextEdit jspEdit = translationUtil.getTranslation().getJspEdit(textEdit);
          if (jspEdit != null && jspEdit.hasChildren())
            jspEdit.apply(document);
        }

      }
      catch (MalformedTreeException exception) {
        Logger.logException(exception);
View Full Code Here

  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

  }

  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

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.